fix empty heredoc templates

This commit is contained in:
mhoffm
2021-06-27 15:54:15 +02:00
parent 6c5f3eba28
commit fd450bb5f6
3 changed files with 53 additions and 4 deletions

View File

@@ -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:

View File

@@ -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);

View File

@@ -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 = <<END
END
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(template_expr
(heredoc_template
(heredoc_start)
(heredoc_identifier)
(heredoc_identifier)))))))
================================================================================
heredoc with fake ending
================================================================================
foo = <<END
END not!
END
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(template_expr
(heredoc_template
(heredoc_start)
(heredoc_identifier)
(template_literal)
(heredoc_identifier)))))))
================================================================================
quoted template expression with escaped strings and fake strip marker
================================================================================