Skip to content

Commit 2877318

Browse files
committed
fix: adjust operator precedence, add try precedence
1 parent 17a6b15 commit 2877318

File tree

4 files changed

+67114
-67227
lines changed

4 files changed

+67114
-67227
lines changed

grammar.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
/// <reference types="tree-sitter-cli/dsl" />
1313
// @ts-check
1414

15+
// https://doc.rust-lang.org/reference/expressions.html#expression-precedence
1516
const PREC = {
16-
range: 15,
17-
call: 14,
18-
field: 13,
17+
call: 15,
18+
field: 14,
19+
try: 13,
1920
unary: 12,
2021
cast: 11,
2122
multiplicative: 10,
@@ -27,6 +28,7 @@ const PREC = {
2728
comparative: 4,
2829
and: 3,
2930
or: 2,
31+
range: 1,
3032
assign: 0,
3133
closure: -1,
3234
};
@@ -979,10 +981,10 @@ module.exports = grammar({
979981
$._expression,
980982
)),
981983

982-
try_expression: $ => seq(
984+
try_expression: $ => prec(PREC.try, seq(
983985
$._expression,
984986
'?',
985-
),
987+
)),
986988

987989
reference_expression: $ => prec(PREC.unary, seq(
988990
'&',

src/grammar.json

Lines changed: 21 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)