fix string literals; trim trailing whitespace

This commit is contained in:
mhoffm
2021-06-14 23:33:28 +02:00
parent 9606c5fa49
commit 01a4a981da
12 changed files with 3239 additions and 3142 deletions

View File

@@ -27,10 +27,6 @@ foo = "prefix-${func(\"bar\"}"
To make parsing a little easier, this parser only checks for valid escape sequences and template chars.
When using this parser one would have to take the content of a template interpolation, unescape it and parse it again to get the syntax tree. The same applies to template directives.
## String Literals
String literals are parsed as quoted templates. The calling application should check if the node contains any template interpolations or directives.
## Todo
* [ ] use [Unicode® Standard Annex #31](https://www.unicode.org/reports/tr31/) (augmented with '-') for identifiers

View File

@@ -24,6 +24,7 @@ module.exports = grammar({
[$.attr_splat],
[$.full_splat],
[$.conditional],
[$.string_lit, $.quoted_template],
],
externals: $ => [
@@ -233,8 +234,14 @@ module.exports = grammar({
// $.heredoc_template,
),
// application should check that no template interpolation is contained
string_lit: $ => $.quoted_template,
string_lit: $ => seq(
'"',
repeat(choice(
$._template_char,
$.escape_sequence,
)),
'"',
),
quoted_template: $ => seq(
'"',

View File

@@ -1015,8 +1015,33 @@
]
},
"string_lit": {
"type": "SYMBOL",
"name": "quoted_template"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_template_char"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"quoted_template": {
"type": "SEQ",
@@ -1176,6 +1201,10 @@
],
[
"conditional"
],
[
"string_lit",
"quoted_template"
]
],
"precedences": [],

View File

@@ -556,11 +556,11 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"multiple": true,
"required": false,
"types": [
{
"type": "quoted_template",
"type": "escape_sequence",
"named": true
}
]

File diff suppressed because it is too large Load Diff

View File

@@ -286,3 +286,18 @@ foo = "$${ var.bar }"
(attribute
(identifier)
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
==================
proper quoted template in string literal position errors
==================
resource "${var.bar}" {
}
---
(config_file
(body
(block
(identifier)
(string_lit (ERROR)))))