Skip to content

Commit afbca92

Browse files
committed
feat!: support only "-", "•" as listitem prefix
"+" and "*" have many false-positives and aren't commonly used as a listitem prefix.
1 parent 6c9251c commit afbca92

File tree

4 files changed

+91
-46
lines changed

4 files changed

+91
-46
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Overview
2020
- contains headings (`h1`, `h2`, `h3`, `column_heading`) because `codeblock`
2121
terminated by "implicit stop" (no terminating `<`) consumes blank lines, so
2222
`block` has no way to end.
23-
- `line_li` ("list item")
23+
- `line_li` ("listitem")
24+
- lines starting with `-`/`` (_not_ `+`/`*`) are listitems.
2425
- consumes lines until blank line, codeblock, or next listitem.
2526
- nesting is ignored: indented listitems are parsed as siblings.
2627
- `codeblock`:
@@ -48,7 +49,7 @@ Known issues
4849
- `url` doesn't handle _nested_ parens. E.g. `(https://example.com/(foo)#yay)`
4950
- `column_heading` currently only recognizes tilde `~` preceded by space (i.e.
5051
`foo ~` not `foo~`). This covers 99% of :help files.
51-
- `column_heading` children should be plaintext. Currently its children are parsed as `$._atom`.
52+
- `column_heading` children should be plaintext, but currently are parsed as `$._atom`.
5253

5354
TODO
5455
----

corpus/line_block.txt

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ block2 text text
8080
================================================================================
8181
listitems
8282
================================================================================
83-
* list1.a item1
84-
* - •
83+
- list1.a item1
84+
- - •
8585
• word,
8686
!foo! ~bar. word word
8787
'item' line3 |foo|
88-
* x 'list1.a' ~/foo/bar.txt
88+
- x 'list1.a' ~/foo/bar.txt
8989
li continues
90-
* {nested} here
90+
- {nested} here
9191

92-
* 'list2' item w3
93-
* *nested_li* word *tag2*
94-
* list2 item w3
95-
* nested_li-2
92+
'list2' item w3
93+
- *nested_li* word *tag2*
94+
list2 item w3
95+
- nested_li-2
9696
foo
9797
foo
9898

@@ -178,16 +178,16 @@ li continues
178178
listitem with codeblock
179179
================================================================================
180180

181-
* list1.a item1 >
181+
list1.a item1 >
182182
foo
183-
< * list1.b item1
184-
* w1 w2
183+
< list1.b item1
184+
w1 w2
185185
w3 >
186186
code1 {
187187
code2
188188
}
189-
<* w1
190-
* w2 w3
189+
< w1
190+
w2 w3
191191
`item2` line2
192192
{item2} line3
193193

@@ -291,3 +291,48 @@ listitems + lines without blank lines
291291
(argument
292292
(word))
293293
(word)))))
294+
295+
================================================================================
296+
listitem tricky
297+
================================================================================
298+
299+
- x - x
300+
301+
-x -x
302+
303+
- - x -x
304+
- -x - x
305+
- -
306+
307+
308+
--------------------------------------------------------------------------------
309+
310+
(help_file
311+
(block
312+
(line_li
313+
(line
314+
(word)
315+
(word)
316+
(word))
317+
(line)))
318+
(block
319+
(line
320+
(word)
321+
(word)))
322+
(block
323+
(line_li
324+
(line
325+
(word)
326+
(word)
327+
(word))
328+
(line))
329+
(line_li
330+
(line
331+
(word)
332+
(word)
333+
(word))
334+
(line))
335+
(line_li
336+
(line
337+
(word))
338+
(line))))

corpus/tags.txt

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ NOT a tag
7878
================================================================================
7979
* bullet1
8080
* bullet2 bullet2
81-
* bullet3
82-
bullet3 bullet3
83-
* bullet4
8481

82+
0 \* escaped
83+
0 (paren *)
8584
1 "*" not
8685
2 * not
8786
3this *not no
@@ -93,34 +92,32 @@ NOT a tag
9392

9493
(help_file
9594
(block
96-
(line_li
97-
(line
98-
(word))
99-
(line))
100-
(line_li
101-
(line
102-
(word)
103-
(word))
104-
(line))
105-
(line_li
106-
(line
107-
(word))
108-
(line)
109-
(line
110-
(word)
111-
(word)))
112-
(line_li
113-
(line
114-
(word))
115-
(line)))
95+
(line
96+
(word)
97+
(word))
98+
(line
99+
(word)
100+
(word)
101+
(word)))
116102
(block
117103
(line
118104
(word)
119105
(word)
120106
(word))
121107
(line
122108
(word)
123-
(ERROR)
109+
(word)
110+
(word)
111+
(tag
112+
(word)
113+
(MISSING "*")))
114+
(line
115+
(word)
116+
(word)
117+
(word))
118+
(line
119+
(word)
120+
(word)
124121
(word))
125122
(line
126123
(word)

grammar.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// - Rules starting with underscore are hidden in the syntax tree.
99

1010
const _uppercase_word = /[A-Z0-9.()][-A-Z0-9.()_]+/;
11-
const _li_token = /[-*+][ ]+/;
11+
const _li_token = /[-][ ]+/;
1212

1313
module.exports = grammar({
1414
name: 'vimdoc',
@@ -27,7 +27,7 @@ module.exports = grammar({
2727

2828
_atom: ($) => choice(
2929
$.word,
30-
$._atom_common
30+
$._atom_common,
3131
),
3232
word: ($) => choice(
3333
// Try the more-restrictive pattern at higher relative precedence, so that things like
@@ -39,12 +39,12 @@ module.exports = grammar({
3939

4040
_atom_noli: ($) => prec(1, choice(
4141
alias($.word_noli, $.word),
42-
$._atom_common
42+
$._atom_common,
4343
)),
4444
word_noli: ($) => prec(1, choice(
4545
// Lines contained by line_li must not start with a listitem symbol.
46-
token(prec(-1, /[^-*+\n\t ][^\n\t ]*/)),
47-
token(prec(-1, /[-*+][^\n\t ]+/)),
46+
token(prec(-1, /[^-\n\t ][^\n\t ]*/)),
47+
token(prec(-1, /[-][^\n\t ]+/)),
4848
$._word_common,
4949
)),
5050

@@ -61,13 +61,15 @@ module.exports = grammar({
6161

6262
// Explicit special cases: these are plaintext, not errors.
6363
_word_common: () => choice(
64+
// NOT tag: isolated "*".
65+
/\*[\n\t ]/,
6466
// NOT optionlink: '
6567
"'",
6668
// NOT optionlink: 'x
6769
seq("'", token.immediate(/[^'\n\t ]/)),
68-
// NOT optionlink: followed by non-lowercase char.
70+
// NOT optionlink: 'X (non-lowercase char).
6971
seq("'", token.immediate(/[a-z]*[^'a-z\n\t ][a-z]*/), optional(token.immediate("'"))),
70-
// NOT optionlink: single char surrounded by "'".
72+
// NOT optionlink: 'x' (single char).
7173
seq("'", token.immediate(/[^'\n\t ]/), token.immediate("'")),
7274
// NOT taglink: "||", "|"
7375
/\|\|+/,

0 commit comments

Comments
 (0)