From fd450bb5f6df25e10ad2c7a6318fc9eeca667877 Mon Sep 17 00:00:00 2001 From: mhoffm Date: Sun, 27 Jun 2021 15:54:15 +0200 Subject: [PATCH] fix empty heredoc templates --- CHANGELOG.md | 7 +++++++ src/scanner.cc | 6 +++--- test/corpus/templates.txt | 44 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f715311..27ff51c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.3.0 - not yet released + +fix: +* correct expression for identifiers +* allow empty template interpolations +* allow empty templates + ## 0.2.0 - 2021-06-26 feature: diff --git a/src/scanner.cc b/src/scanner.cc index efaf67b..365b982 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -129,7 +129,7 @@ public: advance(lexer); } context_stack.push_back({ .type = HEREDOC_TEMPLATE, .heredoc_identifier = identifier }); - return accept_and_advance(lexer, HEREDOC_IDENTIFIER); + return accept_inplace(lexer, HEREDOC_IDENTIFIER); } if (valid_symbols[HEREDOC_IDENTIFIER] && in_heredoc_context() && has_leading_whitespace_with_newline) { string expected_identifier = context_stack.back().heredoc_identifier; @@ -138,7 +138,7 @@ public: if (lexer->lookahead == *it) { advance(lexer); } else { - return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK); + return accept_inplace(lexer, TEMPLATE_LITERAL_CHUNK); } } // check if the identifier is on a line of its own @@ -148,7 +148,7 @@ public: } if (lexer->lookahead == '\n') { context_stack.pop_back(); - return accept_and_advance(lexer, HEREDOC_IDENTIFIER); + return accept_inplace(lexer, HEREDOC_IDENTIFIER); } else { advance(lexer); lexer->mark_end(lexer); diff --git a/test/corpus/templates.txt b/test/corpus/templates.txt index 0dd273a..fc0ff12 100644 --- a/test/corpus/templates.txt +++ b/test/corpus/templates.txt @@ -21,7 +21,7 @@ foo = "${ var.bar }" (identifier)))))))))) ================================================================================ -empty template +empty template interpolation ================================================================================ foo = "${}" @@ -37,6 +37,48 @@ foo = "${}" (quoted_template (template_interpolation))))))) +================================================================================ +empty heredoc template +================================================================================ + +foo = <