From 4e33af071052af30381553ff0ab743e45d23d274 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Sat, 8 Apr 2023 15:26:24 +0300 Subject: [PATCH] Fix a case with an empty body with comment(s) --- make_grammar.js | 15 +++++++++------ src/scanner.cc | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/make_grammar.js b/make_grammar.js index b06c907..442ced1 100644 --- a/make_grammar.js +++ b/make_grammar.js @@ -37,12 +37,15 @@ module.exports = function make_grammar(dialect) { // also allow objects to handle .tfvars in json format config_file: $ => optional(choice($.body, $.object)), - body: $ => seq( - optional($._shim), - repeat1( - choice( - $.attribute, - $.block, + body: $ => choice( + $._shim, + seq( + optional($._shim), + repeat1( + choice( + $.attribute, + $.block, + ), ), ), ), diff --git a/src/scanner.cc b/src/scanner.cc index 99e71f8..60c36f3 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -98,6 +98,8 @@ public: return false; } if (valid_symbols[SHIM]) { + lexer->mark_end(lexer); + while(skip_comment(lexer)); if (lexer->lookahead != '}') { return accept_inplace(lexer, SHIM); } @@ -271,6 +273,20 @@ private: return iswxdigit(lexer->lookahead); } + bool skip_comment(TSLexer* lexer) { + while (iswspace(lexer->lookahead)) { + skip(lexer); + } + if (lexer->lookahead != '#') { + return false; + } + skip(lexer); + while (lexer->lookahead != '\n') { + skip(lexer); + } + return true; + } + bool in_context_type(ContextType type) { if (context_stack.empty()) { return false;