tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
337 stars 96 forks source link

bug: Half-open ranges are not parsed correctly in match statements #205

Closed AlexCid closed 7 months ago

AlexCid commented 8 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

The Rust parser emits an error token for the following code:

match foo {
    1.. => {}
};

Right half-open inclusive ranges (such as ..=1) are also concerned.

Steps To Reproduce/Bad Parse Tree

The code above is parsed to the following s-expression:

(source_file (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (remaining_field_pattern)) (ERROR (integer_literal)) value: (block))))) (empty_statement))

Expected Behavior/Parse Tree

The expected s-expression would be rather

(source_file (expression_statement (match_expression value: (identifier) body: (match_block (match_arm pattern: (match_pattern (range_expression (integer_literal))) ) value: (block))))) (empty_statement))

or something similar

Repro

match foo {
    1.. => {}
};
amaanq commented 7 months ago

Thanks, fixed on master