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,12 +56,11 @@ module.exports = grammar({
5056 $ . taglink ,
5157 $ . codespan ,
5258 $ . argument ,
59+ $ . keycode ,
5360 ) ,
5461
5562 // Explicit special cases: these are plaintext, not errors.
5663 _word_common : ( ) => choice (
57- // "|====|" and "|----|" are (plain text) table borders, not taglinks.
58- / \| ( ( [ + = ] [ + = ] [ + = ] [ + = ] + ) | ( [ + - ] [ + - ] [ + - ] [ + - ] + ) ) \| / ,
5964 // NOT optionlink: single "'".
6065 / [ \t ] ' [ \t ] / ,
6166 // NOT optionlink: contains any non-lowercase char.
@@ -68,10 +73,22 @@ module.exports = grammar({
6873 / \| \| * / ,
6974 // NOT argument: "{}".
7075 / \{ \} / ,
76+ / \{ \{ + [ 0 - 9 ] * / ,
7177 '(' ,
7278 / \w + \( / ,
7379 ) ,
7480
81+ keycode : ( ) => choice (
82+ / < [ - a - z A - Z 0 - 9 _ ] + > / ,
83+ / < [ S C M A D ] - .> / ,
84+ / C T R L - ./ ,
85+ / C T R L - S H I F T - ./ ,
86+ / C T R L - ( B r e a k | P a g e U p | P a g e D o w n | I n s e r t | D e l ) / ,
87+ / C T R L - \{ c h a r \} / ,
88+ / M E T A - ./ ,
89+ / A L T - ./ ,
90+ ) ,
91+
7592 // First part (minus tags) of h3 or column_heading.
7693 uppercase_name : ( ) => seq (
7794 token . immediate ( _uppercase_word ) , // No whitespace before heading.
@@ -114,7 +131,7 @@ module.exports = grammar({
114131 $ . codeblock ,
115132 $ . _line_noli ,
116133 ) ,
117- // Listitem line : consumes "*" line and all adjacent non-list lines.
134+ // Listitem: consumes prefixed line and all adjacent non-prefixed lines.
118135 line_li : ( $ ) => prec . right ( 1 , seq (
119136 optional ( token . immediate ( '<' ) ) , // Treat codeblock-terminating "<" as whitespace.
120137 _li_token ,
@@ -135,12 +152,10 @@ module.exports = grammar({
135152
136153 // "Column heading": plaintext followed by "~".
137154 // Intended for table column names per `:help help-writing`.
155+ // TODO: children should be $.word (plaintext), not $.atom.
138156 column_heading : ( $ ) => seq (
139- field ( 'name' , seq ( choice ( $ . _atom_noli , $ . _uppercase_words ) , repeat ( $ . _atom ) ) ) , // TODO: should be $.word (plaintext).
140- choice (
141- token . immediate ( / ~ [ \t ] * \n / ) ,
142- / ~ [ \t ] * \n / ,
143- ) ,
157+ field ( 'name' , seq ( choice ( $ . _atom_noli , $ . _uppercase_words ) , repeat ( $ . _atom ) ) ) ,
158+ / ~ \n / ,
144159 ) ,
145160
146161 h1 : ( $ ) =>
0 commit comments