From 3f265991388b2946860712dd8b007286f0ed683b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 5 Oct 2022 01:58:06 +0200 Subject: [PATCH] feat: keycodes, special close https://github.com/neovim/tree-sitter-vimdoc/issues/1 --- corpus/text.txt | 8 +++++++- grammar.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/corpus/text.txt b/corpus/text.txt index 3806032..a706471 100644 --- a/corpus/text.txt +++ b/corpus/text.txt @@ -2,6 +2,8 @@ simple file with text ================================================================================ Simple text + + -------------------------------------------------------------------------------- @@ -10,7 +12,11 @@ Simple text (block (line (word) - (word)))) + (word)) + (line + (keycode)) + (line + (keycode)))) ================================================================================ multiline text diff --git a/grammar.js b/grammar.js index d28a081..d1ac05e 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,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.