Skip to content

Commit f134a79

Browse files
committed
feat: support headlines
1 parent b4f5c0c commit f134a79

File tree

5 files changed

+666
-271
lines changed

5 files changed

+666
-271
lines changed

corpus/headline.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
================================================================================
2+
Simple headline
3+
================================================================================
4+
5+
==============================================================================
6+
Headline *headline*
7+
8+
Text
9+
10+
--------------------------------------------------------------------------------
11+
12+
(help_file
13+
(headline
14+
(word)
15+
(tag
16+
(word)))
17+
(line
18+
(word)))

grammar.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ module.exports = grammar({
22
name: 'help', // The actual language name is help
33

44
extras: ($) => [/[\t ]/],
5-
conflicts: ($) => [
6-
[$._atom, $.column_name],
7-
],
5+
conflicts: ($) => [[$._atom, $.column_name]],
86

9-
externals: ($) => [
10-
$.code_block
11-
],
7+
externals: ($) => [$.code_block],
128

139
rules: {
14-
help_file: ($) => repeat1(choice($.line, '\n', $.column_heading)),
15-
16-
header: ($) => seq($.tag),
10+
help_file: ($) => repeat1(choice($.line, '\n', $.column_heading, $.headline)),
1711

12+
headline: ($) =>
13+
seq(
14+
field('delimiter', choice(/===.*===/, /---.*---/)),
15+
'\n',
16+
seq(repeat1($.word), $.tag),
17+
'\n',
18+
),
1819
line: ($) => prec.right(seq(repeat1($._atom), optional('\n'))),
1920

2021
_atom: ($) => choice($.word, $.tag, $.code_block),

src/grammar.json

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,57 @@
1717
{
1818
"type": "SYMBOL",
1919
"name": "column_heading"
20+
},
21+
{
22+
"type": "SYMBOL",
23+
"name": "headline"
2024
}
2125
]
2226
}
2327
},
24-
"header": {
28+
"headline": {
2529
"type": "SEQ",
2630
"members": [
2731
{
28-
"type": "SYMBOL",
29-
"name": "tag"
32+
"type": "FIELD",
33+
"name": "delimiter",
34+
"content": {
35+
"type": "CHOICE",
36+
"members": [
37+
{
38+
"type": "PATTERN",
39+
"value": "===.*==="
40+
},
41+
{
42+
"type": "PATTERN",
43+
"value": "---.*---"
44+
}
45+
]
46+
}
47+
},
48+
{
49+
"type": "STRING",
50+
"value": "\n"
51+
},
52+
{
53+
"type": "SEQ",
54+
"members": [
55+
{
56+
"type": "REPEAT1",
57+
"content": {
58+
"type": "SYMBOL",
59+
"name": "word"
60+
}
61+
},
62+
{
63+
"type": "SYMBOL",
64+
"name": "tag"
65+
}
66+
]
67+
},
68+
{
69+
"type": "STRING",
70+
"value": "\n"
3071
}
3172
]
3273
},

src/node-types.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@
4444
]
4545
}
4646
},
47+
{
48+
"type": "headline",
49+
"named": true,
50+
"fields": {},
51+
"children": {
52+
"multiple": true,
53+
"required": true,
54+
"types": [
55+
{
56+
"type": "tag",
57+
"named": true
58+
},
59+
{
60+
"type": "word",
61+
"named": true
62+
}
63+
]
64+
}
65+
},
4766
{
4867
"type": "help_file",
4968
"named": true,
@@ -56,6 +75,10 @@
5675
"type": "column_heading",
5776
"named": true
5877
},
78+
{
79+
"type": "headline",
80+
"named": true
81+
},
5982
{
6083
"type": "line",
6184
"named": true

0 commit comments

Comments
 (0)