fix ending heredoc identifiers must be on single line

This commit is contained in:
mhoffm
2021-06-26 11:11:34 +02:00
parent bc0b3f1eb0
commit 0ae2fffe6d
5 changed files with 31 additions and 5 deletions

View File

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

View File

@@ -12,14 +12,15 @@ After=coreos-metadata.service
EOF
cert_options = <<EOF
--cert-file=/etc/ssl/etcd/server.crt \
--cert-file=/etc/ssl/etcd/server.crt \
--client-cert-auth=true \
--key-file=/etc/ssl/etcd/server.key \
--peer-cert-file=/etc/ssl/etcd/peer.crt \
--peer-key-file=/etc/ssl/etcd/peer.key \
--peer-trusted-ca-file=/etc/ssl/etcd/ca.crt \
--peer-client-cert-auth=true \
--trusted-ca-file=/etc/ssl/etcd/ca.crtEOF
--trusted-ca-file=/etc/ssl/etcd/ca.crt
EOF
}
data "template_file" "etcd_names" {

View File

@@ -279,7 +279,6 @@ module.exports = grammar({
$._quoted_template_end,
)),
// TODO user chosen identifiers
heredoc_template: $ => seq(
$.heredoc_start,
$.heredoc_identifier,

View File

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

View File

@@ -146,3 +146,26 @@ foo = "hello $${ world"
(literal_value
(string_lit
(template_literal)))))))
================================================================================
tricky heredoc
================================================================================
foo = <<END
contains fake endings
END (ineligible) END
END
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(template_expr
(heredoc_template
(heredoc_start)
(heredoc_identifier)
(template_literal)
(heredoc_identifier)))))))