leafo / moonscript

:crescent_moon: A language that compiles to Lua
https://moonscript.org
3.2k stars 192 forks source link

Using `do` or `then` keywords to disambiguate empty blocks, when necessary. #389

Open strait opened 5 years ago

strait commented 5 years ago

Currently, Moonscript isn't allowing any empty blocks where they might cause ambiguity, which is not ideal, since there are times when an entire block may need to be commented out, perhaps for testing.

Using do or then keywords as disambiguators would solve this problem by forcing an end to the preceding expression when necessary (test expression, etc. that contains an empty block), instead of letting that expression slurp up the following block that was meant for the enclosing statement.

In Moonscript, parentheses serve this purpose for function call arguments. Like do or then keywords, parentheses are optional in their respective context (function call), but they can also keep the last argument in a function call from slurping up more expression than intended.

strait commented 5 years ago

Could also promote the semicolon to be a statement, like Lua did. Then the semicolon could hold the 'empty' block and wouldn't need to be removed when the real block statements were later added.