Skip to content

Commit 69328c4

Browse files
committed
feat: support tags
1 parent 97bb19d commit 69328c4

File tree

5 files changed

+235
-217
lines changed

5 files changed

+235
-217
lines changed

corpus/tags.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
================================================================================
2+
Simple tag
3+
================================================================================
4+
*foobar*
5+
--------------------------------------------------------------------------------
6+
7+
(help_file
8+
(line
9+
(tag
10+
(word))))
11+
12+
================================================================================
13+
Tag in text
14+
================================================================================
15+
*tag* in text
16+
--------------------------------------------------------------------------------
17+
18+
(help_file
19+
(line
20+
(tag
21+
(word))
22+
(word)
23+
(word)))
24+
25+
================================================================================
26+
Tag with lines after
27+
================================================================================
28+
*foo*
29+
Hello
30+
--------------------------------------------------------------------------------
31+
32+
(help_file
33+
(line
34+
(tag
35+
(word)))
36+
(line
37+
(word)))

grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ module.exports = grammar({
55

66
rules: {
77
// TODO: add the actual grammar rules
8-
help_file: ($) => seq($.line, repeat(seq('\n', $.line))),
8+
help_file: ($) => repeat1($.line),
99

1010
header: ($) => seq($.tag),
1111

12-
line: ($) => repeat1($._atom),
12+
line: ($) => prec.right(seq(repeat1($._atom), optional('\n'))),
1313

1414
_atom: ($) => choice($.word, $.tag),
1515

16-
word: ($) => /[^*'|\n]\S*[^*'|\n]/,
16+
word: ($) => /[^*|'\n \t]+/,
1717
tag: ($) => wrapped_word($, '*', 'name'),
18-
option: ($) => /'[a-z]+'/,
19-
hotlink: ($) => /|[a-z-]+|/,
18+
option: ($) => wrapped_word($, "'", 'name'),
19+
hotlink: ($) => wrapped_word($, '|', 'destination'),
2020
},
2121
});
2222

src/grammar.json

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,47 @@
22
"name": "help",
33
"rules": {
44
"help_file": {
5+
"type": "REPEAT1",
6+
"content": {
7+
"type": "SYMBOL",
8+
"name": "line"
9+
}
10+
},
11+
"header": {
512
"type": "SEQ",
613
"members": [
714
{
815
"type": "SYMBOL",
9-
"name": "line"
10-
},
11-
{
12-
"type": "REPEAT",
13-
"content": {
14-
"type": "SEQ",
16+
"name": "tag"
17+
}
18+
]
19+
},
20+
"line": {
21+
"type": "PREC_RIGHT",
22+
"value": 0,
23+
"content": {
24+
"type": "SEQ",
25+
"members": [
26+
{
27+
"type": "REPEAT1",
28+
"content": {
29+
"type": "SYMBOL",
30+
"name": "_atom"
31+
}
32+
},
33+
{
34+
"type": "CHOICE",
1535
"members": [
1636
{
1737
"type": "STRING",
1838
"value": "\n"
1939
},
2040
{
21-
"type": "SYMBOL",
22-
"name": "line"
41+
"type": "BLANK"
2342
}
2443
]
2544
}
26-
}
27-
]
28-
},
29-
"header": {
30-
"type": "SEQ",
31-
"members": [
32-
{
33-
"type": "SYMBOL",
34-
"name": "tag"
35-
}
36-
]
37-
},
38-
"line": {
39-
"type": "REPEAT1",
40-
"content": {
41-
"type": "SYMBOL",
42-
"name": "_atom"
45+
]
4346
}
4447
},
4548
"_atom": {
@@ -57,7 +60,7 @@
5760
},
5861
"word": {
5962
"type": "PATTERN",
60-
"value": "[^*'|\\n]\\S*[^*'|\\n]"
63+
"value": "[^*|'\\n \\t]+"
6164
},
6265
"tag": {
6366
"type": "SEQ",
@@ -81,12 +84,46 @@
8184
]
8285
},
8386
"option": {
84-
"type": "PATTERN",
85-
"value": "'[a-z]+'"
87+
"type": "SEQ",
88+
"members": [
89+
{
90+
"type": "STRING",
91+
"value": "'"
92+
},
93+
{
94+
"type": "FIELD",
95+
"name": "name",
96+
"content": {
97+
"type": "SYMBOL",
98+
"name": "word"
99+
}
100+
},
101+
{
102+
"type": "STRING",
103+
"value": "'"
104+
}
105+
]
86106
},
87107
"hotlink": {
88-
"type": "PATTERN",
89-
"value": "|[a-z-]+|"
108+
"type": "SEQ",
109+
"members": [
110+
{
111+
"type": "STRING",
112+
"value": "|"
113+
},
114+
{
115+
"type": "FIELD",
116+
"name": "destination",
117+
"content": {
118+
"type": "SYMBOL",
119+
"name": "word"
120+
}
121+
},
122+
{
123+
"type": "STRING",
124+
"value": "|"
125+
}
126+
]
90127
}
91128
},
92129
"extras": [

src/node-types.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@
5353
"type": "\n",
5454
"named": false
5555
},
56+
{
57+
"type": "'",
58+
"named": false
59+
},
5660
{
5761
"type": "*",
5862
"named": false
5963
},
6064
{
6165
"type": "word",
6266
"named": true
67+
},
68+
{
69+
"type": "|",
70+
"named": false
6371
}
6472
]

0 commit comments

Comments
 (0)