fix: parse sublist with empty line without error (resolve #23)

This commit is contained in:
Emilia Simmons 2022-05-02 16:46:13 -04:00
parent e40131e544
commit 84d9b3c26c
3 changed files with 23 additions and 14 deletions

View file

@ -814,6 +814,27 @@ List.8b - Whitespace after text
(paragraph
(expr))))))
================================================================================
List.9 - newline before sub listitem
================================================================================
- a
- b
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr))
(list
(listitem
(bullet)
(paragraph
(expr))))))))
================================================================================
Directive.1 - Document
================================================================================

View file

@ -241,14 +241,6 @@ org_grammar = {
seq($.listitem, $._listend)
),
listitem: $ => seq(
$.bullet,
choice(
$._eof,
alias($.body, "item_body"),
)
),
listitem: $ => seq(
field('bullet', $.bullet),
choice(

View file

@ -1,9 +1,6 @@
#include <tree_sitter/parser.h>
#include <vector>
#include <cwctype>
#include <cstring>
#include <cassert>
#include <stdio.h>
namespace {
@ -180,8 +177,8 @@ bool scan(TSLexer *lexer, const bool *valid_symbols) {
// 1. dedent
// 2. same indent, not a bullet
// 3. two eols
int16_t newlines = 0;
if (valid_symbols[LISTEND] || valid_symbols[LISTITEMEND]) {
int16_t newlines = 0;
for (;;) {
if (lexer->lookahead == ' ') {
indent_length++;
@ -232,8 +229,7 @@ bool scan(TSLexer *lexer, const bool *valid_symbols) {
}
// - Liststart and bullets
if (valid_symbols[LISTSTART] || valid_symbols[BULLET]) {
if ((valid_symbols[LISTSTART] || valid_symbols[BULLET]) && newlines == 0) {
Bullet bullet = getbullet(lexer);
if (valid_symbols[BULLET] && bullet == bullet_stack.back() && indent_length == indent_length_stack.back()) {