fix string literals; trim trailing whitespace
This commit is contained in:
@@ -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
|
||||
|
||||
11
grammar.js
11
grammar.js
@@ -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(
|
||||
'"',
|
||||
|
||||
@@ -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": [],
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
|
||||
5808
src/parser.c
5808
src/parser.c
File diff suppressed because it is too large
Load Diff
@@ -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)))))
|
||||
|
||||
Reference in New Issue
Block a user