From 9903dc0b575e6b63c31d2b0a28b36a7e1b31382e Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Sat, 8 Apr 2023 06:55:22 +0300 Subject: [PATCH] Add a shim to move a comment extra into a body node --- make_grammar.js | 12 ++++++++---- src/scanner.cc | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/make_grammar.js b/make_grammar.js index 3e9960b..b06c907 100644 --- a/make_grammar.js +++ b/make_grammar.js @@ -25,6 +25,7 @@ module.exports = function make_grammar(dialect) { $.template_directive_start, $.template_directive_end, $.heredoc_identifier, + $._shim, ], extras: $ => [ @@ -36,10 +37,13 @@ module.exports = function make_grammar(dialect) { // also allow objects to handle .tfvars in json format config_file: $ => optional(choice($.body, $.object)), - body: $ => repeat1( - choice( - $.attribute, - $.block, + body: $ => seq( + optional($._shim), + repeat1( + choice( + $.attribute, + $.block, + ), ), ), diff --git a/src/scanner.cc b/src/scanner.cc index d2eb4b8..99e71f8 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -20,6 +20,7 @@ enum TokenType { TEMPLATE_DIRECTIVE_START, TEMPLATE_DIRECTIVE_END, HEREDOC_IDENTIFIER, + SHIM, }; enum ContextType { @@ -96,6 +97,11 @@ public: if (lexer->lookahead == '\0') { return false; } + if (valid_symbols[SHIM]) { + if (lexer->lookahead != '}') { + return accept_inplace(lexer, SHIM); + } + } // manage quoted context if (valid_symbols[QUOTED_TEMPLATE_START] && !in_quoted_context() && lexer->lookahead == '"') {