gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.31k stars 156 forks source link

Unexpected comma in function arguments list #1112

Open LeXofLeviafan opened 3 years ago

LeXofLeviafan commented 3 years ago

Suppose we have the following code:

foo = (bar, match, baz) ->

According to language docs, it doesn't include any reserved words, so it should compile… but instead it generates an outright confusing syntax error: Parse error on line 1: Unexpected ','

After some fiddling, we narrow down the reason to the match word… But it wasn't used anywhere in the language, was it now? We do a text search on the language webpage, just in case we forgot about it… And it does find a mention – but only in the changelog, as an experimental feature. So what, was it added but then removed later and they forgot to exclude it from the parser? Nope – after searching through the github issues we find out that the feature is present in the language, just never mentioned anywhere in the docs.

The problem here, of course, is that the match keyword is neither documented in the language docs – not even as a reserved word – nor does its usage produce a sensible error message (when used as an argument name). Thus, I suggest doing one or more of the following:

rhendric commented 3 years ago

The fourth option would be quite nice but I think we're limited by the parser generator we're using; Jison's error recovery facilities are... not great.

The third option is something I'm reluctant to do in a keep-the-lights-on context, so unless LiveScript starts gathering forward momentum again, I think experimental match is here to stay.

So that leaves the other two. I've suggested before that a glossary of keywords/symbols would be a good idea, and I still think so; maybe just a list of keywords is worth adding as an interim solution.