Skip to content
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

"when" is treated as an operator even without a space after #53

Closed
yaglo opened this issue May 30, 2023 · 1 comment
Closed

"when" is treated as an operator even without a space after #53

yaglo opened this issue May 30, 2023 · 1 comment

Comments

@yaglo
Copy link

yaglo commented May 30, 2023

when doesn't require a space after it but it should.

Example:

def func(arg) whenis_number(arg)

tree-sitter-elixir parses it without issues (as you can see above):

source [0, 0] - [1, 0]
  call [0, 0] - [0, 32]
    target: identifier [0, 0] - [0, 3]
    arguments [0, 4] - [0, 32]
      binary_operator [0, 4] - [0, 32]
        left: call [0, 4] - [0, 13]
          target: identifier [0, 4] - [0, 8]
          arguments [0, 8] - [0, 13]
            identifier [0, 9] - [0, 12]
        right: call [0, 18] - [0, 32]
          target: identifier [0, 18] - [0, 27]
          arguments [0, 27] - [0, 32]
            identifier [0, 28] - [0, 31]

Elixir's parser doesn't consider this valid:

** (SyntaxError) iex:18:15: syntax error before: whenis_number
    |
 18 | def func(arg) whenis_number(arg)
    |               ^
    (iex 1.14.5) lib/iex/evaluator.ex:292: IEx.Evaluator.parse_eval_inspect/3
    (iex 1.14.5) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.14.5) lib/iex/evaluator.ex:32: IEx.Evaluator.init/4
    (stdlib 4.3.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

@jonatanklosko
Copy link
Member

Hey @yaglo, this is essentially the same case as this:

1 or1
1or1
1or 1
1 or 1

All of the above are parsed without error (but only the last one is valid). I discussed this upstream in the past (tree-sitter/tree-sitter#1404) and the conclusion was that this behaviour was kinda expected given all the context.

Generally false positives in edge cases like these are not critical. It is important to correctly parse all valid syntax, but it's not really the goal to strictly reject all invalid syntax :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants