Skip to content

Commit 2bd6625

Browse files
rearrange precedence for class ranges and atoms (tree-sitter#7)
1 parent f9562de commit 2bd6625

File tree

5 files changed

+126
-107
lines changed

5 files changed

+126
-107
lines changed

corpus/main.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ character classes - '-' is an atom
211211
)
212212
))
213213

214+
===================
215+
character classes - 'a-' is atoms
216+
===================
217+
[a-]
218+
---
219+
(pattern (term
220+
(character_class
221+
(class_character)
222+
(class_character)
223+
)
224+
))
225+
214226
===================
215227
character classes - /[---]/ is odd but valid
216228
===================

grammar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module.exports = grammar({
2121
$._class_atom,
2222
],
2323

24+
conflicts: $ => [[$.character_class, $.class_range]],
25+
2426
rules: {
2527
pattern: $ => choice(
2628
$.disjunction,
@@ -83,7 +85,7 @@ module.exports = grammar({
8385
']'
8486
),
8587

86-
class_range: $ => prec.right(1,
88+
class_range: $ => prec.right(
8789
seq($._class_atom, '-', $._class_atom)
8890
),
8991

src/grammar.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
},
263263
"class_range": {
264264
"type": "PREC_RIGHT",
265-
"value": 1,
265+
"value": 0,
266266
"content": {
267267
"type": "SEQ",
268268
"members": [
@@ -669,7 +669,12 @@
669669
"value": "\n"
670670
}
671671
],
672-
"conflicts": [],
672+
"conflicts": [
673+
[
674+
"character_class",
675+
"class_range"
676+
]
677+
],
673678
"precedences": [],
674679
"externals": [],
675680
"inline": [

0 commit comments

Comments
 (0)