Skip to content

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

@julianthome

Description

@julianthome

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions