precedence of operators reversed to treesitter #8

Closed
opened 2024-04-19 10:18:20 +02:00 by Entkenntnis · 1 comment
Entkenntnis commented 2024-04-19 10:18:20 +02:00 (Migrated from github.com)

If you parse i < c + 1, you will get an AST that looks like this:

grafik

I'm expecting the CompareOp to have a lower precedence than the ArithOp. Looking at tree-sitter grammar, this is indeed the case, ADD has a higher precedence than REL.

In the grammar here, you will first notice that the order is reversed (which could have caused some confusion), and it looks like that compare now has a higher precedence than addition.

github.com/lezer-parser/java@d89968838c/src/java.grammar (L1-L20)

Can somebody recheck the precedence here? Thank you!

If you parse `i < c + 1`, you will get an AST that looks like this: ![grafik](https://github.com/lezer-parser/java/assets/13507950/c338b575-dc14-44e4-a9b3-c14edb7eac68) I'm expecting the CompareOp to have a lower precedence than the ArithOp. Looking at [tree-sitter grammar](https://github.com/tree-sitter/tree-sitter-java/blob/master/grammar.js), this is indeed the case, `ADD` has a higher precedence than `REL`. In the grammar here, you will first notice that the order is reversed (which could have caused some confusion), and it looks like that compare now has a higher precedence than addition. https://github.com/lezer-parser/java/blob/d89968838ccfc8d2a11557d669a8e1bca2f7a8bb/src/java.grammar#L1-L20 Can somebody recheck the precedence here? Thank you!
marijnh commented 2024-04-19 10:37:31 +02:00 (Migrated from github.com)

Yes, those were looking very confused. Attached patch fixes them.

Yes, those were looking very confused. Attached patch fixes them.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/java#8
No description provided.