Skip to content

Commit

Permalink
feat: keycodes, special
Browse files Browse the repository at this point in the history
close #1
  • Loading branch information
justinmk committed Oct 5, 2022
1 parent fc1b022 commit 2ad84ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 17 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> <C-S-x> <C-x> <M-^> <x-y>
CTRL-{char} ctr-z CTRL-SHIFT-\ CTRL-+ CTRL-Break ALT-?


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

================================================================================
multiline text
Expand Down
18 changes: 18 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,17 @@ module.exports = grammar({
/\w+\(/,
),

keycode: () => choice(
/<[-a-zA-Z0-9_]+>/,
/<[SCMAD]-.>/,
/CTRL-./,
/CTRL-SHIFT-./,
/CTRL-(Break|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 2ad84ef

Please sign in to comment.