Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f26599

Browse files
committedOct 5, 2022
feat: keycodes, special
close neovim#1
1 parent fc1b022 commit 3f26599

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎corpus/text.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
simple file with text
33
================================================================================
44
Simple text
5+
<Del>
6+
<CSI>
57

68

79
--------------------------------------------------------------------------------
@@ -10,7 +12,11 @@ Simple text
1012
(block
1113
(line
1214
(word)
13-
(word))))
15+
(word))
16+
(line
17+
(keycode))
18+
(line
19+
(keycode))))
1420

1521
================================================================================
1622
multiline text

‎grammar.js

+19
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,18 @@ 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/,
87+
/CTRL-(PageUp|PageDown|Insert|Del)/,
88+
/CTRL-\{char\}/,
89+
/META-./,
90+
/ALT-./,
91+
),
92+
7493
// First part (minus tags) of h3 or column_heading.
7594
uppercase_name: () => seq(
7695
token.immediate(_uppercase_word), // No whitespace before heading.

0 commit comments

Comments
 (0)
Please sign in to comment.