tree-sitter-elixir icon indicating copy to clipboard operation
tree-sitter-elixir copied to clipboard

grammar: optional parens for function calls & definition

Open Tuxified opened this issue 3 years ago • 3 comments

currently the grammar doesn't allow for function calls & definitions without parens, like: String.split "1, 2", ","

Tuxified avatar Mar 04 '21 21:03 Tuxified

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.

addcninblue avatar Mar 25 '21 08:03 addcninblue

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:

Tuxified avatar Mar 25 '21 15:03 Tuxified

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.

addcninblue avatar Mar 27 '21 06:03 addcninblue