Skip to content

Commit d595021

Browse files
authored
Merge #27 from justinmk/fixes
feat: keycodes, fixes: taglink, column_heading, argument
2 parents c27e3e2 + 7cfa706 commit d595021

10 files changed

+6543
-3308
lines changed

corpus/arguments.txt

+21-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ NOT an argument
5555
================================================================================
5656
{foo "{bar}" `{baz}` |{baz| } {}
5757

58+
===============
59+
3. Netrw *netrw-ref* {{{1
60+
61+
EXTERNAL *netrw-externapp* {{{2
62+
5863

5964
--------------------------------------------------------------------------------
6065

@@ -70,4 +75,19 @@ NOT an argument
7075
(taglink
7176
(word))
7277
(word)
73-
(word))))
78+
(word)))
79+
(block
80+
(line
81+
(h1
82+
(word)
83+
(word)
84+
(tag
85+
(word))
86+
(word))))
87+
(block
88+
(line
89+
(h3
90+
(uppercase_name)
91+
(tag
92+
(word))
93+
(ERROR)))))

corpus/codespan.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ an error`.
4040
(word))
4141
(word)
4242
(word)
43-
(codespan
43+
(ERROR
4444
(word)
45-
(MISSING "`")))
46-
(line
47-
(word)
45+
(word))
4846
(word))))
4947

5048
================================================================================

corpus/heading3-column_heading.txt

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ ABC not-h3
234234
NOT column_heading
235235
================================================================================
236236
tilde ~/foo/bar foo~ bar
237+
trailing-space-is-NOT-column_heading ~
237238

238239

239240
--------------------------------------------------------------------------------
@@ -243,5 +244,8 @@ tilde ~/foo/bar foo~ bar
243244
(line
244245
(word)
245246
(word)
247+
(word)
248+
(word))
249+
(line
246250
(word)
247251
(word))))

corpus/optionlink.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ x `after_codespan`'s
9999
(ERROR)
100100
(block
101101
(line
102-
(codespan
102+
(argument
103103
(word))
104-
(ERROR))))
104+
(word))
105+
(ERROR
106+
(word)
107+
(codespan
108+
(word)))))
105109

106110
================================================================================
107111
NOT optionlink 3 (FIXME)
@@ -116,6 +120,8 @@ foo '"\ '. Notice
116120
(block
117121
(line
118122
(word)
119-
(word
120-
(ERROR)
121-
(MISSING "'")))))
123+
(ERROR)
124+
(word))
125+
(line
126+
(taglink
127+
(word)))))

corpus/taglink.txt

+25-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ taglink in text
1717
================================================================================
1818
Hello |world| hello
1919

20+
|-+| +[num] line
21+
|-e| -e Ex
22+
|-| - minus
23+
24+
2025

2126
--------------------------------------------------------------------------------
2227

@@ -26,6 +31,22 @@ Hello |world| hello
2631
(word)
2732
(taglink
2833
(word))
34+
(word)))
35+
(block
36+
(line
37+
(taglink
38+
(word))
39+
(word)
40+
(word))
41+
(line
42+
(taglink
43+
(word))
44+
(word)
45+
(word))
46+
(line
47+
(taglink
48+
(word))
49+
(word)
2950
(word))))
3051

3152
================================================================================
@@ -78,8 +99,10 @@ Note: ":autocmd" can...
7899
(word))
79100
(line
80101
(word)
81-
(word)
82-
(word)))
102+
(taglink
103+
(word))
104+
(taglink
105+
(word))))
83106
(block
84107
(line_li
85108
(line

corpus/text.txt

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
simple file with text
33
================================================================================
44
Simple text
5+
<Del> <CSI> <C-S-x> <C-x> <M-^> <x-y>
6+
CTRL-{char} ctr-z CTRL-SHIFT-\ CTRL-+ CTRL-Break ALT-?
57

68

79
--------------------------------------------------------------------------------
@@ -10,7 +12,21 @@ Simple text
1012
(block
1113
(line
1214
(word)
13-
(word))))
15+
(word))
16+
(line
17+
(keycode)
18+
(keycode)
19+
(keycode)
20+
(keycode)
21+
(keycode)
22+
(keycode))
23+
(line
24+
(keycode)
25+
(word)
26+
(keycode)
27+
(keycode)
28+
(keycode)
29+
(keycode))))
1430

1531
================================================================================
1632
multiline text

grammar.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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-zA-Z0-9_]+>/,
83+
/<[SCMAD]-.>/,
84+
/CTRL-./,
85+
/CTRL-SHIFT-./,
86+
/CTRL-(Break|PageUp|PageDown|Insert|Del)/,
87+
/CTRL-\{char\}/,
88+
/META-./,
89+
/ALT-./,
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: ($) =>

src/grammar.json

+47-18
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@
157157
{
158158
"type": "SYMBOL",
159159
"name": "argument"
160+
},
161+
{
162+
"type": "SYMBOL",
163+
"name": "keycode"
160164
}
161165
]
162166
},
163167
"_word_common": {
164168
"type": "CHOICE",
165169
"members": [
166-
{
167-
"type": "PATTERN",
168-
"value": "\\|(([+=][+=][+=][+=]+)|([+-][+-][+-][+-]+))\\|"
169-
},
170170
{
171171
"type": "PATTERN",
172172
"value": "[\\t ]'[\\t ]"
@@ -229,6 +229,10 @@
229229
"type": "PATTERN",
230230
"value": "\\{\\}"
231231
},
232+
{
233+
"type": "PATTERN",
234+
"value": "\\{\\{+[0-9]*"
235+
},
232236
{
233237
"type": "STRING",
234238
"value": "("
@@ -239,6 +243,43 @@
239243
}
240244
]
241245
},
246+
"keycode": {
247+
"type": "CHOICE",
248+
"members": [
249+
{
250+
"type": "PATTERN",
251+
"value": "<[-a-zA-Z0-9_]+>"
252+
},
253+
{
254+
"type": "PATTERN",
255+
"value": "<[SCMAD]-.>"
256+
},
257+
{
258+
"type": "PATTERN",
259+
"value": "CTRL-."
260+
},
261+
{
262+
"type": "PATTERN",
263+
"value": "CTRL-SHIFT-."
264+
},
265+
{
266+
"type": "PATTERN",
267+
"value": "CTRL-(Break|PageUp|PageDown|Insert|Del)"
268+
},
269+
{
270+
"type": "PATTERN",
271+
"value": "CTRL-\\{char\\}"
272+
},
273+
{
274+
"type": "PATTERN",
275+
"value": "META-."
276+
},
277+
{
278+
"type": "PATTERN",
279+
"value": "ALT-."
280+
}
281+
]
282+
},
242283
"uppercase_name": {
243284
"type": "SEQ",
244285
"members": [
@@ -590,20 +631,8 @@
590631
}
591632
},
592633
{
593-
"type": "CHOICE",
594-
"members": [
595-
{
596-
"type": "IMMEDIATE_TOKEN",
597-
"content": {
598-
"type": "PATTERN",
599-
"value": "~[\\t ]*\\n"
600-
}
601-
},
602-
{
603-
"type": "PATTERN",
604-
"value": "~[\\t ]*\\n"
605-
}
606-
]
634+
"type": "PATTERN",
635+
"value": "~\\n"
607636
}
608637
]
609638
},

src/node-types.json

+21
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
"type": "codespan",
8282
"named": true
8383
},
84+
{
85+
"type": "keycode",
86+
"named": true
87+
},
8488
{
8589
"type": "optionlink",
8690
"named": true
@@ -121,6 +125,10 @@
121125
"type": "codespan",
122126
"named": true
123127
},
128+
{
129+
"type": "keycode",
130+
"named": true
131+
},
124132
{
125133
"type": "optionlink",
126134
"named": true
@@ -160,6 +168,10 @@
160168
"type": "codespan",
161169
"named": true
162170
},
171+
{
172+
"type": "keycode",
173+
"named": true
174+
},
163175
{
164176
"type": "optionlink",
165177
"named": true
@@ -224,6 +236,11 @@
224236
]
225237
}
226238
},
239+
{
240+
"type": "keycode",
241+
"named": true,
242+
"fields": {}
243+
},
227244
{
228245
"type": "line",
229246
"named": true,
@@ -260,6 +277,10 @@
260277
"type": "h3",
261278
"named": true
262279
},
280+
{
281+
"type": "keycode",
282+
"named": true
283+
},
263284
{
264285
"type": "optionlink",
265286
"named": true

0 commit comments

Comments
 (0)