Skip to content

Commit b4f5c0c

Browse files
committed
feat: add support for code blocks
1 parent c7d577a commit b4f5c0c

File tree

6 files changed

+357
-155
lines changed

6 files changed

+357
-155
lines changed

corpus/code_block.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
================================================================================
2+
Simple code block
3+
================================================================================
4+
>
5+
abcabcabc
6+
<
7+
--------------------------------------------------------------------------------
8+
9+
(help_file
10+
(line
11+
(code_block)))
12+
13+
================================================================================
14+
Code block with text before
15+
================================================================================
16+
This code: >
17+
abc
18+
<
19+
--------------------------------------------------------------------------------
20+
21+
(help_file
22+
(line
23+
(word)
24+
(word)
25+
(code_block)))
26+
27+
================================================================================
28+
Code block with implicit stop
29+
================================================================================
30+
>
31+
abc
32+
33+
Blehke
34+
--------------------------------------------------------------------------------
35+
36+
(help_file
37+
(line
38+
(code_block)
39+
(word)))

grammar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ module.exports = grammar({
66
[$._atom, $.column_name],
77
],
88

9+
externals: ($) => [
10+
$.code_block
11+
],
12+
913
rules: {
1014
help_file: ($) => repeat1(choice($.line, '\n', $.column_heading)),
1115

1216
header: ($) => seq($.tag),
1317

1418
line: ($) => prec.right(seq(repeat1($._atom), optional('\n'))),
1519

16-
_atom: ($) => choice($.word, $.tag),
20+
_atom: ($) => choice($.word, $.tag, $.code_block),
1721

1822
uppercase_name: ($) => repeat1(/[A-Z]+/),
1923
column_name: ($) => repeat1($.word),

src/grammar.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
{
6969
"type": "SYMBOL",
7070
"name": "tag"
71+
},
72+
{
73+
"type": "SYMBOL",
74+
"name": "code_block"
7175
}
7276
]
7377
},
@@ -222,7 +226,12 @@
222226
]
223227
],
224228
"precedences": [],
225-
"externals": [],
229+
"externals": [
230+
{
231+
"type": "SYMBOL",
232+
"name": "code_block"
233+
}
234+
],
226235
"inline": [],
227236
"supertypes": []
228237
}

src/node-types.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
"multiple": true,
7272
"required": true,
7373
"types": [
74+
{
75+
"type": "code_block",
76+
"named": true
77+
},
7478
{
7579
"type": "tag",
7680
"named": true
@@ -115,6 +119,10 @@
115119
"type": "*",
116120
"named": false
117121
},
122+
{
123+
"type": "code_block",
124+
"named": true
125+
},
118126
{
119127
"type": "word",
120128
"named": true

0 commit comments

Comments
 (0)