tree-sitter-elixir
tree-sitter-elixir copied to clipboard
grammar: optional parens for function calls & definition
currently the grammar doesn't allow for function calls & definitions without parens, like: String.split "1, 2", ","
I believe that currently implementing this is impossible, since the grammar allows for invalid conflicting configurations, such as "1" "1"
, which it parses into (source_file (string) (string))
. We might be able to require a new line after every statement (which would give us valid Elixir), and the above problem is probably solved by changing the const args
to optionalParens
.
Yes, I think this might be the hardest issue on the list of todos. Semicolons and newlines are valid expression terminators, however some expression span multiple lines, so I don't think it can be solved by "only" changing the const args to optionalParens
. But feel free to prove me wrong, I'm not an expert when it comes to building parsers :smile:
I've thought about this a lot more, and I cautiously think this might be impossible in the general case.
Consider the case of simply
func
.
We have no idea whether this is a 0-arity function call or a lookup to the variable func
. Even the interpreter wouldn't know if it was a variable or a function, as I'm sure we've all seen undefined function func/0
when we misspelled a variable name before!
Perhaps the way to "solve" this problem is to be opinionated -- perhaps we reject all 0-arity functions and only accept 1+ ones. I believe that solving this might give us a cleaner way represent certain things, such as , :do
notation, since those are all simply arguments to a macro.