-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse error when std.import'ed script contains executable statements #24
Comments
Thanks for reporting! The issue is actually caused by another matter, which can surely be a source of confusion. Let me format your code differently, and you'll see what is going on: Original source with some whitespace removed:
Which is equivalent to:
As the language has no semicolons, this gets parsed as the indexing operator, and not an array declaration. This is very similar to what happens in Lua, and it surely seems very weird at a first glance. This was known from the start when I was designing the language, and in my experience using Lua there is very seldomly a case where you'll want to write a statement that will cause the ambiguity, such as
And it should work. By the way, there is no alternative parser mode for modules, and the issue is reproducible with a single Hush script. Also note that the issue won't happen if you're returning a dictionary, as the We should most likely add a semicolon symbol to allow explicit separation of statements, so that the user can use it in cases like this. Please, let me know what you think. |
Adding a semicolon seems like it would work. But you've tried to keep semicolons out of the language, or at least out of the non-command-block parts. With the current model, there's no way to DWIW without adding a throwaway symbol. But if the newline had a higher precedence than [, you could get the indexing behavior by moving the [ up to the previous line or just using an open paren at the start of the atom:
Which is weird, because [] generally has super-high precedence vs other operators. So I think this is a "what do you want your language to look like" question. If you feel strongly about no newlines, then make the rule that if it looks like the start of an expression, you have to have a continuation character or open brackets or something to advance to the next line. Or go one step further, and dictate that some kind of expression-stack entry is required to continue: open brackets, binary operators, whatever. This would bias the language to use more parens and break expressions the (IMO) wrong way:
|
Yeah, I'm not very fond of newlines having syntactical meaning. I believe optional semicolons would be the most aligned with what we already have, and the least disturbing approach. |
Consider two files:
importer.hsh
mcve.hsh
Configured thus, when I invoke
hush importer.hsh
I get these errors:But if I comment out the print statement, there is no problem.
My expectation is that the inner script (mcve.hsh) is to be executed immediately, and the last expression evaluated will provide the return value for the
std.import()
function. But what appears to be happening is some kind of different parse mode(?) where the syntax is slightly different? I'm not sure if this is a bug, (IMO: yes!) or a documentation failure, or what.The text was updated successfully, but these errors were encountered: