Skip to content

Commit 41ac505

Browse files
committed
feat: add argument nodes
1 parent dfc8a80 commit 41ac505

File tree

6 files changed

+559
-313
lines changed

6 files changed

+559
-313
lines changed

corpus/arguments.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
================================================================================
2+
Simple argument
3+
================================================================================
4+
This in an argument: {arg}
5+
--------------------------------------------------------------------------------
6+
7+
(help_file
8+
(line
9+
(word)
10+
(word)
11+
(word)
12+
(word)
13+
(argument
14+
(word))))
15+
16+
================================================================================
17+
Multiple arguments on the same line
18+
================================================================================
19+
20+
{foo} {bar} {baz}
21+
22+
--------------------------------------------------------------------------------
23+
24+
(help_file
25+
(line
26+
(argument
27+
(word))
28+
(argument
29+
(word))
30+
(argument
31+
(word))))

grammar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = grammar({
3333
$.option,
3434
$.hotlink,
3535
$.backtick,
36+
$.argument,
3637
),
3738

3839
column_heading: ($) =>
@@ -48,9 +49,10 @@ module.exports = grammar({
4849
option: ($) => wrapped_word($, "'", 'name'),
4950
hotlink: ($) => wrapped_word($, '|', 'destination'),
5051
backtick: ($) => wrapped_word($, '`', 'content'),
52+
argument: ($) => seq("{", field('name', $.word), token.immediate('}'))
5153
},
5254
});
5355

5456
function wrapped_word($, char, fname) {
55-
return seq(char, field(fname, $.word), char);
57+
return seq(char, field(fname, $.word), token.immediate(char));
5658
}

src/grammar.json

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
{
130130
"type": "SYMBOL",
131131
"name": "backtick"
132+
},
133+
{
134+
"type": "SYMBOL",
135+
"name": "argument"
132136
}
133137
]
134138
},
@@ -195,8 +199,11 @@
195199
}
196200
},
197201
{
198-
"type": "STRING",
199-
"value": "*"
202+
"type": "IMMEDIATE_TOKEN",
203+
"content": {
204+
"type": "STRING",
205+
"value": "*"
206+
}
200207
}
201208
]
202209
},
@@ -216,8 +223,11 @@
216223
}
217224
},
218225
{
219-
"type": "STRING",
220-
"value": "'"
226+
"type": "IMMEDIATE_TOKEN",
227+
"content": {
228+
"type": "STRING",
229+
"value": "'"
230+
}
221231
}
222232
]
223233
},
@@ -237,8 +247,11 @@
237247
}
238248
},
239249
{
240-
"type": "STRING",
241-
"value": "|"
250+
"type": "IMMEDIATE_TOKEN",
251+
"content": {
252+
"type": "STRING",
253+
"value": "|"
254+
}
242255
}
243256
]
244257
},
@@ -257,9 +270,36 @@
257270
"name": "word"
258271
}
259272
},
273+
{
274+
"type": "IMMEDIATE_TOKEN",
275+
"content": {
276+
"type": "STRING",
277+
"value": "`"
278+
}
279+
}
280+
]
281+
},
282+
"argument": {
283+
"type": "SEQ",
284+
"members": [
260285
{
261286
"type": "STRING",
262-
"value": "`"
287+
"value": "{"
288+
},
289+
{
290+
"type": "FIELD",
291+
"name": "name",
292+
"content": {
293+
"type": "SYMBOL",
294+
"name": "word"
295+
}
296+
},
297+
{
298+
"type": "IMMEDIATE_TOKEN",
299+
"content": {
300+
"type": "STRING",
301+
"value": "}"
302+
}
263303
}
264304
]
265305
}

src/node-types.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
[
2+
{
3+
"type": "argument",
4+
"named": true,
5+
"fields": {
6+
"name": {
7+
"multiple": false,
8+
"required": true,
9+
"types": [
10+
{
11+
"type": "word",
12+
"named": true
13+
}
14+
]
15+
}
16+
}
17+
},
218
{
319
"type": "backtick",
420
"named": true,
@@ -111,6 +127,10 @@
111127
"multiple": true,
112128
"required": true,
113129
"types": [
130+
{
131+
"type": "argument",
132+
"named": true
133+
},
114134
{
115135
"type": "backtick",
116136
"named": true
@@ -202,8 +222,16 @@
202222
"type": "word",
203223
"named": true
204224
},
225+
{
226+
"type": "{",
227+
"named": false
228+
},
205229
{
206230
"type": "|",
207231
"named": false
232+
},
233+
{
234+
"type": "}",
235+
"named": false
208236
}
209237
]

0 commit comments

Comments
 (0)