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 = <