tree-sitter/tree-sitter-ruby

incorrect representation of range expression in the presence of negative integer arguments

julianthome opened this issue · 1 comments

The current grammar fails to parse ranges correctly if they contain negative numbers:

(1..5).to_a        #=> [1, 2, 3, 4, 5] -> OK
('a'..'e').to_a    #=> ["a", "b", "c", "d", "e"] -> OK
('a'...'e').to_a   #=> ["a", "b", "c", "d"] = -5..-1 -> OK
(-1..-5).to_a      #=> [], -> FAILS
(-5..-1).to_a      #=> [-5, -4, -3, -2, -1] -> FAILS

The figure below depicts the corresponding tree-sitter tree:

image

For the cases, where a range was recognized correctly, it is rooted with a range node. The incorrect cases are rooted with a binary node and the range node only has a single unary child.

For all cases, I would suggest to use a different labeling for the parenthesized_statements because range is an expression.

This should be fixed by #207.