Skip to content

Commit 84d9b3c

Browse files
committed
fix: parse sublist with empty line without error (resolve #23)
1 parent e40131e commit 84d9b3c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

corpus/basic.tst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,27 @@ List.8b - Whitespace after text
814814
(paragraph
815815
(expr))))))
816816

817+
================================================================================
818+
List.9 - newline before sub listitem
819+
================================================================================
820+
- a
821+
822+
- b
823+
--------------------------------------------------------------------------------
824+
825+
(document
826+
(body
827+
(list
828+
(listitem
829+
(bullet)
830+
(paragraph
831+
(expr))
832+
(list
833+
(listitem
834+
(bullet)
835+
(paragraph
836+
(expr))))))))
837+
817838
================================================================================
818839
Directive.1 - Document
819840
================================================================================

grammar.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,6 @@ org_grammar = {
241241
seq($.listitem, $._listend)
242242
),
243243

244-
listitem: $ => seq(
245-
$.bullet,
246-
choice(
247-
$._eof,
248-
alias($.body, "item_body"),
249-
)
250-
),
251-
252244
listitem: $ => seq(
253245
field('bullet', $.bullet),
254246
choice(

src/scanner.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include <tree_sitter/parser.h>
22
#include <vector>
33
#include <cwctype>
4-
#include <cstring>
5-
#include <cassert>
6-
#include <stdio.h>
74

85
namespace {
96

@@ -180,8 +177,8 @@ bool scan(TSLexer *lexer, const bool *valid_symbols) {
180177
// 1. dedent
181178
// 2. same indent, not a bullet
182179
// 3. two eols
180+
int16_t newlines = 0;
183181
if (valid_symbols[LISTEND] || valid_symbols[LISTITEMEND]) {
184-
int16_t newlines = 0;
185182
for (;;) {
186183
if (lexer->lookahead == ' ') {
187184
indent_length++;
@@ -232,8 +229,7 @@ bool scan(TSLexer *lexer, const bool *valid_symbols) {
232229
}
233230

234231
// - Liststart and bullets
235-
if (valid_symbols[LISTSTART] || valid_symbols[BULLET]) {
236-
232+
if ((valid_symbols[LISTSTART] || valid_symbols[BULLET]) && newlines == 0) {
237233
Bullet bullet = getbullet(lexer);
238234

239235
if (valid_symbols[BULLET] && bullet == bullet_stack.back() && indent_length == indent_length_stack.back()) {

0 commit comments

Comments
 (0)