- 
                Notifications
    You must be signed in to change notification settings 
- Fork 66
RFC: Indexing syntax when using long strings #127
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
base: master
Are you sure you want to change the base?
RFC: Indexing syntax when using long strings #127
Conversation
| As a side note, this is totally ambiguous in Lua[u], even if deciding between long brackets vs indexing was performed during the parse stage using an advanced parser. The expression  
 There's a third alternative I forgot, that I'm adding into the RFC now. | 
| I don't think this passes the -200 points test. | 
| I support this RFC because, as of right now local meowkey = {
    [[[meow]]] = 2, -- syntax error
}
local meowkey2 = {
    [ [[meow]] = 2, -- completely fine
}Luau shouldn't be relying on load-bearing whitespace here, so fixing this would make Luau a more consistent language and thereby (in my view) meets the -whatever point requirement. Nit, but I thought  | 
| 
 Don't get me wrong, it's hardly an especially interesting or exciting RFC, but it's currently this awkward unspecified ambiguity that really should at least be specified. I'd be fully in support of literally just specifying that the current behaviour is the intended way to parse a file—it's just about cleaning up the fact that currently this is an awkward thing that's not really considered formally anywhere. Edit: thanks mobile | 
| I think this RFC is very similar to the trailing commas in function calls RFC. That RFC was rejected because while it made users think they were happier, it didn't actually make the language better or actually make users happier. This RFC is the same. | 
| There's a little bit of an ambiguity here, isn't there? It makes sense to want  | 
|  | ||
| The first party Luau parser follows the semantic-whitespace behaviour. | ||
|  | ||
| The predominant Rust parser for Luau, [full-moon](https://github.com/Kampfkarren/full-moon), follows the semantic-whitespace behaviour. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't really semantic, since it only affects the parser step and it's a parse error or not which makes this entirely syntactic. I'd use "significant whitespace" instead (although that term is traditionally used to decide which block to place a statement in, I think it still applies)
| That's a really good point. I think the "logical" parse of  Is there a good way to solve this? Quite likely not. The lexer could do some pretty nasty checks to decide when to perform which behaviour (ie if the previous lexeme was a name,  The simplest solution here might be to consider this just a general poor design decision of lua, unfixable, and then codify the current behaviour in writing rather than seeking to amend it at all? | 
Rendered
Defines the logic for how to parse
foo[[[a]]], opting to parse this asfoo["a"]rather than the currentfoo"[a"].This logic can be implemented in the official Luau lexer via the following modification to https://github.com/luau-lang/luau/blob/master/Ast/src/Lexer.cpp:
While not mentioned in the document, as it is focused on Luau, it is interesting to note that most Lua minifiers stumble when trying to minify statements of the form discussed, removing this semantic whitespace and producing code that then parses differently. Lua currently still uses the semantic-whitespace behaviour that Luau is also currently using. (I tested
mathiasbynens/luamin,stravant/lua-minifyandstravant/LuaMinify)