Skip to content

Commit 2ad84ef

Browse files
committed
feat: keycodes, special
close #1
1 parent fc1b022 commit 2ad84ef

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

corpus/text.txt

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
simple file with text
33
================================================================================
44
Simple text
5+
<Del> <CSI> <C-S-x> <C-x> <M-^> <x-y>
6+
CTRL-{char} ctr-z CTRL-SHIFT-\ CTRL-+ CTRL-Break ALT-?
57

68

79
--------------------------------------------------------------------------------
@@ -10,7 +12,21 @@ Simple text
1012
(block
1113
(line
1214
(word)
13-
(word))))
15+
(word))
16+
(line
17+
(keycode)
18+
(keycode)
19+
(keycode)
20+
(keycode)
21+
(keycode)
22+
(keycode))
23+
(line
24+
(keycode)
25+
(word)
26+
(keycode)
27+
(keycode)
28+
(keycode)
29+
(keycode))))
1430

1531
================================================================================
1632
multiline text

grammar.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// https://tree-sitter.github.io/tree-sitter/creating-parsers#conflicting-tokens
2+
// - Match Specificity: Tree-sitter will prefer a token that is specified in
3+
// the grammar as a String instead of a RegExp.
4+
// - Rule Order: Tree-sitter will prefer the token that appears earlier in the
5+
// grammar.
6+
//
17
// https://tree-sitter.github.io/tree-sitter/creating-parsers
28
// - Rules starting with underscore are hidden in the syntax tree.
39

@@ -50,6 +56,7 @@ module.exports = grammar({
5056
$.taglink,
5157
$.codespan,
5258
$.argument,
59+
$.keycode,
5360
),
5461

5562
// Explicit special cases: these are plaintext, not errors.
@@ -71,6 +78,17 @@ module.exports = grammar({
7178
/\w+\(/,
7279
),
7380

81+
keycode: () => choice(
82+
/<[-a-zA-Z0-9_]+>/,
83+
/<[SCMAD]-.>/,
84+
/CTRL-./,
85+
/CTRL-SHIFT-./,
86+
/CTRL-(Break|PageUp|PageDown|Insert|Del)/,
87+
/CTRL-\{char\}/,
88+
/META-./,
89+
/ALT-./,
90+
),
91+
7492
// First part (minus tags) of h3 or column_heading.
7593
uppercase_name: () => seq(
7694
token.immediate(_uppercase_word), // No whitespace before heading.

0 commit comments

Comments
 (0)