From 0ae2fffe6d1e5e41bbea5b7da9cf8962dbc30ed5 Mon Sep 17 00:00:00 2001 From: mhoffm Date: Sat, 26 Jun 2021 11:11:34 +0200 Subject: [PATCH] fix ending heredoc identifiers must be on single line --- README.md | 1 - ...nstaller%modules%ignition%etcd.tf-155.hcl} | 5 ++-- grammar.js | 1 - src/scanner.cc | 6 ++++- test/corpus/templates.txt | 23 +++++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) rename example/real_world_stuff/coreos/{coreos%tectonic-installer%modules%ignition%etcd.tf-155 => coreos%tectonic-installer%modules%ignition%etcd.tf-155.hcl} (98%) diff --git a/README.md b/README.md index 64c5e64..a800f0e 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,3 @@ The aim is to build unit testcases from selected failure classes and slowly get * [x] add quoted template interpolations * [ ] add quoted template directives * [x] add heredoc templates - diff --git a/example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155 b/example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155.hcl similarity index 98% rename from example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155 rename to example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155.hcl index c1b238d..41d8914 100644 --- a/example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155 +++ b/example/real_world_stuff/coreos/coreos%tectonic-installer%modules%ignition%etcd.tf-155.hcl @@ -12,14 +12,15 @@ After=coreos-metadata.service EOF cert_options = < seq( $.heredoc_start, $.heredoc_identifier, diff --git a/src/scanner.cc b/src/scanner.cc index 337e49a..efaf67b 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -73,7 +73,11 @@ public: } bool scan(TSLexer* lexer, const bool* valid_symbols) { + bool has_leading_whitespace_with_newline = false; while (iswspace(lexer->lookahead)) { + if (lexer->lookahead == '\n') { + has_leading_whitespace_with_newline = true; + } skip(lexer); } if (lexer->lookahead == '\0') { @@ -127,7 +131,7 @@ public: context_stack.push_back({ .type = HEREDOC_TEMPLATE, .heredoc_identifier = identifier }); return accept_and_advance(lexer, HEREDOC_IDENTIFIER); } - if (valid_symbols[HEREDOC_IDENTIFIER] && in_heredoc_context()) { + if (valid_symbols[HEREDOC_IDENTIFIER] && in_heredoc_context() && has_leading_whitespace_with_newline) { string expected_identifier = context_stack.back().heredoc_identifier; for (string::iterator it = expected_identifier.begin(); it != expected_identifier.end(); ++it) { diff --git a/test/corpus/templates.txt b/test/corpus/templates.txt index 8abce0c..2c41085 100644 --- a/test/corpus/templates.txt +++ b/test/corpus/templates.txt @@ -146,3 +146,26 @@ foo = "hello $${ world" (literal_value (string_lit (template_literal))))))) + +================================================================================ +tricky heredoc +================================================================================ + +foo = <