Skip to content

Commit 31fcaca

Browse files
committed
fix: first node in (line) captures whitespace
Problem: Whitespace is still captured in the first node of a line. #23 Solution: Avoid regexes that explicitly capture leading whitespace. The `extras` directive makes this unnecessary. fix #23
1 parent 21a633b commit 31fcaca

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

corpus/codespan.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ an error`.
4040
(word))
4141
(word)
4242
(word)
43-
(ERROR
43+
(codespan
4444
(word)
45-
(word))
45+
(MISSING "`")))
46+
(line
47+
(word)
4648
(word))))
4749

4850
================================================================================

corpus/heading3-column_heading.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ NOT column_heading
236236
tilde ~/foo/bar foo~ bar
237237
trailing-space-is-NOT-column_heading ~
238238

239+
buffer-diagram
240+
|-----|
241+
|foo |
242+
|~ |
243+
|~ |
244+
|-----|
245+
239246

240247
--------------------------------------------------------------------------------
241248

@@ -248,4 +255,26 @@ trailing-space-is-NOT-column_heading ~
248255
(word))
249256
(line
250257
(word)
251-
(word))))
258+
(word)))
259+
(block
260+
(line
261+
(word))
262+
(line
263+
(taglink
264+
(word)))
265+
(line
266+
(word)
267+
(ERROR
268+
(word))
269+
(word))
270+
(line
271+
(word)
272+
(word)
273+
(word))
274+
(line
275+
(word)
276+
(word)
277+
(word))
278+
(line
279+
(taglink
280+
(word)))))

corpus/line_block.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ text text text text
5353
(word)
5454
(word)
5555
(word))
56-
(MISSING "help_file_token1")))
56+
(MISSING "<")))
5757

5858
================================================================================
5959
blocks: with blank line at end of document

corpus/optionlink.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ x `after_codespan`'s
136136
(argument
137137
(word))
138138
(word))
139-
(ERROR
139+
(line
140140
(word)
141141
(codespan
142-
(word)))))
142+
(word))
143+
(word
144+
(MISSING "'")))))
143145

144146
================================================================================
145147
NOT optionlink 3 (FIXME)

grammar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = grammar({
2121
rules: {
2222
help_file: ($) =>
2323
seq(
24-
repeat(/[\t ]*\n/), // Eat whitespace at top of file.
24+
repeat($._blank), // Eat blank lines at top of file.
2525
repeat($.block),
2626
),
2727

@@ -67,8 +67,8 @@ module.exports = grammar({
6767
seq("'", token.immediate(/[^'\n\t ]*[^'a-z\n\t ][^'\n\t ]*/), token.immediate("'")),
6868
// NOT optionlink: single char surrounded by "'".
6969
seq("'", token.immediate(/[^'\n\t ]/), token.immediate("'")),
70-
// NOT taglink: "||".
71-
/\|\|*/,
70+
// NOT taglink: "||", "|"
71+
/\|\|+/,
7272
'|',
7373
// NOT listitem: "-" or "•" followed by tab.
7474
/[-]\t/,
@@ -125,7 +125,7 @@ module.exports = grammar({
125125
)),
126126

127127
// Lines.
128-
_blank: () => field('blank', /[\t ]*\n/),
128+
_blank: () => field('blank', '\n'),
129129
line: ($) => choice(
130130
$.column_heading,
131131
$.h1,

0 commit comments

Comments
 (0)