-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Labels
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-c
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
No response
Describe the bug
I'm working on an ast-grep version of the Rubocop ambiguous operator lint. One of the cases it needs to alert on is something +x and something -y.
When I do something -y I get an AST like this:
But when I do something +x I get a binary in the AST instead of a unary as expected:
Ruby alerts on both of these, showing that it parses both of these as a unary:
def do_something(x); end
do_something +42
do_something -42# Running that gives us this:
/Users/samwightt/Code/ruby/ast-grep-rubocop/demo_ambiguous_operators.rb:3: warning: ambiguous first argument; put parentheses or a space even after `+` operator
/Users/samwightt/Code/ruby/ast-grep-rubocop/demo_ambiguous_operators.rb:4: warning: ambiguous first argument; put parentheses or a space even after `-` operatorSteps To Reproduce/Bad Parse Tree
See examples above.
Expected Behavior/Parse Tree
The parse tree for something +x and something -y should be the same structure, minus the operator and name difference:
something + xshould give abinarysomething +xshould give aunarysomething+xshould give abinary
Repro
something +x
something -y