Skip to content

fix: * operator after .. incorrectly parsed as binary#305

Open
Strawbang wants to merge 1 commit intotree-sitter:masterfrom
Strawbang:fix/range-unary-operator-precedence
Open

fix: * operator after .. incorrectly parsed as binary#305
Strawbang wants to merge 1 commit intotree-sitter:masterfrom
Strawbang:fix/range-unary-operator-precedence

Conversation

@Strawbang
Copy link
Copy Markdown

Fixes #291

..*a was incorrectly parsed as (..) * a (binary multiply) instead of a prefix range ending at a dereference.

This affects real code like Tokio's buf_writer.rs:

me.buf.drain(..*me.written);

The fix gives the prefix range alternative seq('..', $._expression) a slightly higher precedence (PREC.range + 1) with right-associativity, so the parser prefers building the range's right side over reducing `..\ to a
standalone RangeFull when followed by a unary operator.

* Fix shift/reduce conflict in range_expression so that `..*a`
  parses as a prefix range ending at a dereference, not as a
  binary multiplication of RangeFull by a
* Add corpus test for range expressions with leading unary operators
* Regenerate parser
@wetneb
Copy link
Copy Markdown

wetneb commented Mar 16, 2026

Thanks for working on this! I have integrated it in the tree-sitter-rust-orchard fork, since external contributions are infrequently merged in this repository.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: * operator in ..*a incorrectly parsed as binary operator when it should be a dereference

2 participants