Skip to content

Commit

Permalink
feat: keycodes, special
Browse files Browse the repository at this point in the history
close neovim#1
  • Loading branch information
justinmk committed Oct 5, 2022
1 parent fc1b022 commit 3f26599
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion corpus/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
simple file with text
================================================================================
Simple text
<Del>
<CSI>


--------------------------------------------------------------------------------
Expand All @@ -10,7 +12,11 @@ Simple text
(block
(line
(word)
(word))))
(word))
(line
(keycode))
(line
(keycode))))

================================================================================
multiline text
Expand Down
19 changes: 19 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// https://tree-sitter.github.io/tree-sitter/creating-parsers#conflicting-tokens
// - Match Specificity: Tree-sitter will prefer a token that is specified in
// the grammar as a String instead of a RegExp.
// - Rule Order: Tree-sitter will prefer the token that appears earlier in the
// grammar.
//
// https://tree-sitter.github.io/tree-sitter/creating-parsers
// - Rules starting with underscore are hidden in the syntax tree.

Expand Down Expand Up @@ -50,6 +56,7 @@ module.exports = grammar({
$.taglink,
$.codespan,
$.argument,
$.keycode,
),

// Explicit special cases: these are plaintext, not errors.
Expand All @@ -71,6 +78,18 @@ module.exports = grammar({
/\w+\(/,
),

keycode: () => choice(
/<[-a-zA-Z0-9_]+>/,
/<[SCMAD]-.>/,
/CTRL-./,
/CTRL-SHIFT-./,
/CTRL-Break/,
/CTRL-(PageUp|PageDown|Insert|Del)/,
/CTRL-\{char\}/,
/META-./,
/ALT-./,
),

// First part (minus tags) of h3 or column_heading.
uppercase_name: () => seq(
token.immediate(_uppercase_word), // No whitespace before heading.
Expand Down

0 comments on commit 3f26599

Please sign in to comment.