diff --git a/corpus/text.txt b/corpus/text.txt index 3806032..de6eaaf 100644 --- a/corpus/text.txt +++ b/corpus/text.txt @@ -2,6 +2,8 @@ simple file with text ================================================================================ Simple text + +CTRL-{char} ctr-z CTRL-SHIFT-\ CTRL-+ CTRL-Break ALT-? -------------------------------------------------------------------------------- @@ -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 diff --git a/grammar.js b/grammar.js index d28a081..6933877 100644 --- a/grammar.js +++ b/grammar.js @@ -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. @@ -50,6 +56,7 @@ module.exports = grammar({ $.taglink, $.codespan, $.argument, + $.keycode, ), // Explicit special cases: these are plaintext, not errors. @@ -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.