Skip to content

Commit e7454c2

Browse files
committed
feat: add support for posix character classes
1 parent 123552e commit e7454c2

File tree

7 files changed

+1285
-975
lines changed

7 files changed

+1285
-975
lines changed

Package.resolved

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SwiftTreeSitter",
6+
"repositoryURL": "https://github.com/ChimeHQ/SwiftTreeSitter",
7+
"state": {
8+
"branch": null,
9+
"revision": "2599e95310b3159641469d8a21baf2d3d200e61f",
10+
"version": "0.8.0"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

grammar.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = grammar({
5959
$.lookaround_assertion,
6060
$.pattern_character,
6161
$.character_class,
62+
$.posix_character_class,
6263
$.any_character,
6364
$.decimal_escape,
6465
$.character_class_escape,
@@ -104,13 +105,23 @@ module.exports = grammar({
104105
character_class: $ => seq(
105106
'[',
106107
optional('^'),
107-
repeat(choice(
108-
$.class_range,
109-
$._class_atom,
110-
)),
108+
choice(
109+
repeat(choice(
110+
$.class_range,
111+
$._class_atom,
112+
)),
113+
),
111114
']',
112115
),
113116

117+
posix_character_class: $ => seq(
118+
'[:',
119+
$.posix_class_name,
120+
':]',
121+
),
122+
123+
posix_class_name: _ => /[a-zA-Z]+/,
124+
114125
class_range: $ => prec.right(
115126
seq($._class_atom, '-', $._class_atom),
116127
),
@@ -121,6 +132,7 @@ module.exports = grammar({
121132
alias('\\-', $.identity_escape),
122133
$.character_class_escape,
123134
$._character_escape,
135+
$.posix_character_class,
124136
),
125137

126138
class_character: _ => // NOT: \ ] or -

queries/highlights.scm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"]"
1010
"{"
1111
"}"
12+
"[:"
13+
":]"
1214
] @punctuation.bracket
1315

1416
(group_name) @property
@@ -45,6 +47,9 @@
4547
(class_range "-" @operator)
4648
])
4749

48-
(class_character) @constant.character
50+
[
51+
(class_character)
52+
(posix_class_name)
53+
] @constant.character
4954

5055
(pattern_character) @string

src/grammar.json

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

src/node-types.json

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

0 commit comments

Comments
 (0)