Skip to content

Commit c88a172

Browse files
committed
feat: listitem (line_li)
- BREAKING CHANGE: give up on block_end, line_noeol. Too much trouble and doesn't matter for consumers anyway. - line_li now consumes all adjacent lines until blank line, "<", or next listitem. This makes it much easier for applications to present lists--even nested lists--because now the application only needs to compare the indent of the previous sibling listitem.
1 parent c418f88 commit c88a172

13 files changed

+400
-137
lines changed

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
tree-sitter-vimdoc
22
==================
33

4-
This grammar intentionally support a subset of the vimdoc "spec"; predictable
5-
results are the primary goal, so that _output_ formats (e.g. HTML) are
6-
well-formed; the _input_ (vimdoc) is secondary. The first step should always be
7-
to try to fix the input (within reason) rather than insist on a grammar that
8-
handles vimdoc's endless quirks.
4+
This grammar intentionally support a subset of the vimdoc "spec"
5+
([ref1](https://neovim.io/doc/user/helphelp.html#help-writing),
6+
[ref2](https://github.com/nanotee/vimdoc-notes));
7+
predictable results are the primary goal, so that _output_ formats (e.g. HTML)
8+
are well-formed; the _input_ (vimdoc) is secondary. The first step should
9+
always be to try to fix the input rather than insist on a grammar that handles
10+
vimdoc's endless quirks.
911

1012
Overview
1113
--------
1214

13-
- vimdoc format "spec":
14-
- [:help help-writing](https://neovim.io/doc/user/helphelp.html#help-writing)
15-
- https://github.com/nanotee/vimdoc-notes
16-
- whitespace is intentionally captured in all atoms, because it is often used
17-
for "layout" and ascii art in legacy help files.
18-
- `block` is the main top-level node which contains `line` nodes.
19-
- ends at blank line(s) or a line starting with `<`.
15+
- `block` is the main top-level node which contains `line` and `line_li` nodes.
16+
- delimited by blank line(s) or any line starting with `<` (codeblock terminator).
2017
- `line`:
2118
- contains atoms (words, tags, taglinks, …)
22-
- contains `codeblock` because `>` can start a codeblock at the end of a line.
2319
- contains headings (`h1`, `h2`, `h3`) because `codeblock` terminated by
2420
"implicit stop" (no terminating `<`) consumes blank lines, so `block` has
2521
no way to end.
2622
- contains `column_heading` because `<` (the `codeblock` terminating char)
2723
can appear at the start of `column_heading`.
24+
- `line_li` ("list item")
25+
- consumes lines until blank line, codeblock, or next listitem.
26+
- nesting is ignored: indented listitems are parsed as siblings.
2827
- `codeblock`:
29-
- contains `line` nodes which do not contain `word` nodes, it's just the full
28+
- contained by `line` or `line_li`. Because ">" can start
29+
a codeblock at the end of any line.
30+
- contains `line` nodes without `word` nodes, it's just the full
3031
raw text line including whitespace. This is somewhat dictated by its
3132
"preformatted" nature; parsing the contents would require loading a "child"
3233
language (injection). See [#2](https://github.com/neovim/tree-sitter-vimdoc/issues/2).
@@ -38,16 +39,20 @@ Overview
3839
Known issues
3940
------------
4041

41-
- `line_li` ("list item") is experimental. It doesn't support nesting yet.
42+
- Input must end with newline/EOL (`\n`). Grammar does not support files without EOL.
43+
- Input must end with a blank line. Though this doesn't seem to matter in practice.
4244
- Spec requires that `codeblock` delimiter ">" must be preceded by a space
4345
(" >"), not a tab. But currently the grammar doesn't enforce this. Example:
4446
`:help lcs-tab`.
4547
- `url` doesn't handle _surrounding_ parens. E.g. `(https://example.com/#yay)` yields `word`
4648
- `url` doesn't handle _nested_ parens. E.g. `(https://example.com/(foo)#yay)`
49+
- `column_heading` currently only recognizes tilde "~" preceded by space (i.e.
50+
"foo ~" not "foo~"). This covers 99% of :help files, but the grammar should
51+
probably support "foo~" also.
4752

4853
TODO
4954
----
5055

51-
- `line_noeol` is a special-case to support documents that don't end in EOL.
52-
Grammar could be simpler if we require EOL at end of document.
5356
- `line_modeline` ?
57+
- `tag_heading` : line(s) containing only tags, typically implies a "heading"
58+
before a block.

corpus/arguments.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
simple argument
33
================================================================================
44
This in an argument: {arg}
5+
6+
57
--------------------------------------------------------------------------------
68

79
(help_file
@@ -19,6 +21,7 @@ multiple arguments on the same line
1921
================================================================================
2022
{foo} {bar} {baz}
2123

24+
2225
--------------------------------------------------------------------------------
2326

2427
(help_file
@@ -36,6 +39,7 @@ NOT an argument
3639
================================================================================
3740
{foo "{bar}" `{baz}` |{baz| } {}
3841

42+
3943
--------------------------------------------------------------------------------
4044

4145
(help_file

corpus/codeblock.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ block3:
1616
<
1717

1818
text
19+
20+
1921
--------------------------------------------------------------------------------
2022

2123
(help_file
@@ -62,6 +64,7 @@ From luaref.txt:
6264

6365
text
6466

67+
6568
--------------------------------------------------------------------------------
6669

6770
(help_file
@@ -116,6 +119,7 @@ h2-headline *foo*
116119

117120
H3 HEADLINE *foo*
118121

122+
119123
--------------------------------------------------------------------------------
120124

121125
(help_file
@@ -162,8 +166,8 @@ codeblock with empty lines
162166

163167
Example: >
164168

165-
let buf = nvim_create_buf(v:false, v:true)
166-
call nvim_buf_set_lines(buf, 0, -1, v:true, ["test", "text"])
169+
- let buf = nvim_create_buf(v:false, v:true)
170+
- call nvim_buf_set_lines(buf, 0, -1, v:true, ["test", "text"])
167171

168172
let opts = {'relative': 'cursor', 'width': 10, 'height': 2, 'col': 0,
169173
\ 'row': 1, 'anchor': 'NW', 'style': 'minimal'}
@@ -172,6 +176,7 @@ Example: >
172176
call nvim_win_set_option(win, 'winhl', 'Normal:MyHighlight')
173177
x
174178

179+
175180
--------------------------------------------------------------------------------
176181

177182
(help_file
@@ -211,6 +216,7 @@ tricky codeblock
211216

212217
tricky
213218

219+
214220
--------------------------------------------------------------------------------
215221

216222
(help_file

corpus/codespan.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ simple codespan
44

55
a `foobar` b `:echo`
66

7+
78
--------------------------------------------------------------------------------
89

910
(help_file
@@ -23,6 +24,7 @@ codespan in text
2324
Hello `world`, I am `markup language`. But `this is
2425
an error`.
2526

27+
2628
--------------------------------------------------------------------------------
2729

2830
(help_file
@@ -52,6 +54,7 @@ NOT codespan
5254
*g'* *g'a* *g`* *g`a*
5355
g'{mark} g`{mark}
5456

57+
5558
--------------------------------------------------------------------------------
5659

5760
(help_file

corpus/heading1_2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Heading two *tag2.1* *tag2.2*
1212

1313
Text2
1414

15+
1516
--------------------------------------------------------------------------------
1617

1718
(help_file
@@ -51,6 +52,7 @@ Text
5152

5253
Text
5354

55+
5456
--------------------------------------------------------------------------------
5557

5658
(help_file
@@ -104,6 +106,7 @@ Text
104106
Not-a-heading-4 *heading4*
105107
Text
106108

109+
107110
--------------------------------------------------------------------------------
108111

109112
(help_file

corpus/heading3-column_heading.txt

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ HELLO
55

66
Test
77

8-
GUI ~
8+
GUI COOL ~
99
Text
10+
11+
1012
--------------------------------------------------------------------------------
1113

1214
(help_file
@@ -20,7 +22,8 @@ Text
2022
(block
2123
(line
2224
(column_heading
23-
(uppercase_name)))
25+
(word)
26+
(word)))
2427
(line
2528
(word))))
2629

@@ -30,6 +33,8 @@ h3 (uppercase) heading, multiple words
3033
HELLO WORLD
3134

3235
LEADING-SPACE-NOT-A-HEADING
36+
37+
3338
--------------------------------------------------------------------------------
3439

3540
(help_file
@@ -47,6 +52,8 @@ h3 heading with tag
4752
HELLO WORLD *abc*
4853

4954
Test
55+
56+
5057
--------------------------------------------------------------------------------
5158

5259
(help_file
@@ -63,9 +70,11 @@ Test
6370
================================================================================
6471
column_heading lowercase
6572
================================================================================
66-
Test~
73+
test-Test ~
6774

6875
Below
76+
77+
6978
--------------------------------------------------------------------------------
7079

7180
(help_file
@@ -78,17 +87,35 @@ Below
7887
(word))))
7988

8089
================================================================================
81-
column_heading with multiple words
90+
column_heading no space before tilde (FIXME)
8291
================================================================================
83-
Multiple words~
92+
test~
93+
94+
Below
95+
96+
97+
--------------------------------------------------------------------------------
98+
99+
(help_file
100+
(block
101+
(line
102+
(word)))
103+
(block
104+
(line
105+
(word))))
84106

85-
text
107+
================================================================================
108+
column_heading with multiple words
109+
================================================================================
110+
Multiple words ~
86111

87112
nvim_ui_try_resize({width}, {height}) *nvim_ui_try_resize()*
88113
TODO: Documentation
89114

90115
Attributes: ~
91116
|RPC| only
117+
118+
92119
--------------------------------------------------------------------------------
93120

94121
(help_file
@@ -97,9 +124,6 @@ nvim_ui_try_resize({width}, {height}) *nvim_ui_try_resize()*
97124
(column_heading
98125
(word)
99126
(word))))
100-
(block
101-
(line
102-
(word)))
103127
(block
104128
(line
105129
(word)
@@ -132,6 +156,7 @@ column_heading should NOT parse atoms (links, tags, etc.) (FIXME)
132156

133157
Text.
134158

159+
135160
--------------------------------------------------------------------------------
136161

137162
(help_file
@@ -165,6 +190,7 @@ ABC not-h3
165190
5. PRODUCT of 3.
166191
...`/lua`-path,-leaving:
167192

193+
168194
--------------------------------------------------------------------------------
169195

170196
(help_file
@@ -208,6 +234,7 @@ NOT column_heading
208234
================================================================================
209235
tilde ~/foo/bar foo~ bar
210236

237+
211238
--------------------------------------------------------------------------------
212239

213240
(help_file
@@ -216,5 +243,4 @@ tilde ~/foo/bar foo~ bar
216243
(word)
217244
(word)
218245
(word)
219-
(word)
220246
(word))))

0 commit comments

Comments
 (0)