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
+ //
1
7
// https://tree-sitter.github.io/tree-sitter/creating-parsers
2
8
// - Rules starting with underscore are hidden in the syntax tree.
3
9
@@ -50,12 +56,11 @@ module.exports = grammar({
50
56
$ . taglink ,
51
57
$ . codespan ,
52
58
$ . argument ,
59
+ $ . keycode ,
53
60
) ,
54
61
55
62
// Explicit special cases: these are plaintext, not errors.
56
63
_word_common : ( ) => choice (
57
- // "|====|" and "|----|" are (plain text) table borders, not taglinks.
58
- / \| ( ( [ + = ] [ + = ] [ + = ] [ + = ] + ) | ( [ + - ] [ + - ] [ + - ] [ + - ] + ) ) \| / ,
59
64
// NOT optionlink: single "'".
60
65
/ [ \t ] ' [ \t ] / ,
61
66
// NOT optionlink: contains any non-lowercase char.
@@ -68,10 +73,22 @@ module.exports = grammar({
68
73
/ \| \| * / ,
69
74
// NOT argument: "{}".
70
75
/ \{ \} / ,
76
+ / \{ \{ + [ 0 - 9 ] * / ,
71
77
'(' ,
72
78
/ \w + \( / ,
73
79
) ,
74
80
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
+
75
92
// First part (minus tags) of h3 or column_heading.
76
93
uppercase_name : ( ) => seq (
77
94
token . immediate ( _uppercase_word ) , // No whitespace before heading.
@@ -114,7 +131,7 @@ module.exports = grammar({
114
131
$ . codeblock ,
115
132
$ . _line_noli ,
116
133
) ,
117
- // Listitem line : consumes "*" line and all adjacent non-list lines.
134
+ // Listitem: consumes prefixed line and all adjacent non-prefixed lines.
118
135
line_li : ( $ ) => prec . right ( 1 , seq (
119
136
optional ( token . immediate ( '<' ) ) , // Treat codeblock-terminating "<" as whitespace.
120
137
_li_token ,
@@ -135,12 +152,10 @@ module.exports = grammar({
135
152
136
153
// "Column heading": plaintext followed by "~".
137
154
// Intended for table column names per `:help help-writing`.
155
+ // TODO: children should be $.word (plaintext), not $.atom.
138
156
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 / ,
144
159
) ,
145
160
146
161
h1 : ( $ ) =>
0 commit comments