From 698bb1a34331e68f83fc24bdd1b6f97016bb30de Mon Sep 17 00:00:00 2001 From: Emilia Simmons Date: Tue, 16 Aug 2022 11:51:11 -0400 Subject: [PATCH] fix: freeze on error recovery (#34) --- Cargo.toml | 2 +- package.json | 2 +- src/scanner.cc | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f3fced..b9042d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-org" description = "org grammar for the tree-sitter parsing library" -version = "1.3.0" +version = "1.3.1" keywords = ["incremental", "parsing", "org"] categories = ["parsing", "text-editors"] repository = "https://github.com/milisims/tree-sitter-org" diff --git a/package.json b/package.json index 602afb9..d8e1d35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-org", - "version": "1.3.0", + "version": "1.3.1", "description": "Org grammar for tree-sitter", "main": "bindings/node", "keywords": [ diff --git a/src/scanner.cc b/src/scanner.cc index 2ba0919..f198183 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -105,6 +105,16 @@ struct Scanner { return true; } + bool in_error_recovery(const bool *valid_symbols) { + return (valid_symbols[LISTSTART] && + valid_symbols[LISTEND] && + valid_symbols[LISTITEMEND] && + valid_symbols[BULLET] && + valid_symbols[HLSTARS] && + valid_symbols[SECTIONEND] && + valid_symbols[ENDOFFILE]); + } + Bullet getbullet(TSLexer *lexer) { if (lexer->lookahead == '-') { advance(lexer); @@ -150,6 +160,10 @@ struct Scanner { bool scan(TSLexer *lexer, const bool *valid_symbols) { + if (in_error_recovery(valid_symbols)) + return false; + + // - Section ends int16_t indent_length = 0; lexer->mark_end(lexer);