|
13 | 13 | // @ts-check |
14 | 14 |
|
15 | 15 | const _uppercase_word = /[A-Z0-9.()][-A-Z0-9.()_]+/; |
| 16 | +// List-item. |
16 | 17 | const _li_token = /[-•][ ]+/; |
| 18 | +// Numbered list-item. |
| 19 | +const _num_li_token = /[0-9]{1,3}\.[ ]+/; |
17 | 20 |
|
18 | 21 | module.exports = grammar({ |
19 | 22 | name: 'vimdoc', |
@@ -49,9 +52,10 @@ module.exports = grammar({ |
49 | 52 | alias($.word_noli, $.word), |
50 | 53 | $._atom_common, |
51 | 54 | ), |
| 55 | + // Word NOT matching (numbered) listitem. |
52 | 56 | word_noli: ($) => choice( |
53 | | - // Lines contained by line_li must not start with a listitem symbol. |
54 | | - token(prec(-1, /[^-•\n\t ][^(\[\n\t ]*/)), |
| 57 | + // Lines contained by line_li must not start with (numbered) listitem symbol. |
| 58 | + token(prec(-1, /(([^-•\n\t ])|([^0-9\n\t ][^.\n\t ]))[^.(\[\n\t ]*/)), |
55 | 59 | token(prec(-1, /[-•][^\n\t ]+/)), |
56 | 60 | $._word_common, |
57 | 61 | ), |
@@ -132,7 +136,8 @@ module.exports = grammar({ |
132 | 136 | choice( |
133 | 137 | repeat1($.line), |
134 | 138 | repeat1($.line_li), |
135 | | - seq(repeat1($.line), repeat1($.line_li)), |
| 139 | + repeat1($.line_li_num), |
| 140 | + seq(repeat1($.line), repeat1(choice($.line_li, $.line_li_num))), |
136 | 141 | ), |
137 | 142 | choice( |
138 | 143 | token.immediate('<'), // Treat codeblock-terminating "<" as whitespace. |
@@ -171,6 +176,16 @@ module.exports = grammar({ |
171 | 176 | ), |
172 | 177 | repeat(alias($._line_noli, $.line)), |
173 | 178 | )), |
| 179 | + // Numbered listitem: consumes prefixed line and all adjacent non-prefixed lines. |
| 180 | + line_li_num: ($) => prec.right(1, seq( |
| 181 | + optional(token.immediate('<')), // Treat codeblock-terminating "<" as whitespace. |
| 182 | + _num_li_token, |
| 183 | + choice( |
| 184 | + alias(seq(repeat1($._atom), /\n/), $.line), |
| 185 | + seq(alias(repeat1($._atom), $.line), $.codeblock), |
| 186 | + ), |
| 187 | + repeat(alias($._line_noli, $.line)), |
| 188 | + )), |
174 | 189 | // Codeblock lines: must be indented by at least 1 space/tab. |
175 | 190 | // Line content (incl. whitespace) is captured as a single atom. |
176 | 191 | line_code: () => choice(/\n/, /[\t ]+[^\n]+\n/), |
|
0 commit comments