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.
|
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.
|
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
|
## Todo
|
||||||
|
|
||||||
* [ ] use [Unicode® Standard Annex #31](https://www.unicode.org/reports/tr31/) (augmented with '-') for identifiers
|
* [ ] 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],
|
[$.attr_splat],
|
||||||
[$.full_splat],
|
[$.full_splat],
|
||||||
[$.conditional],
|
[$.conditional],
|
||||||
|
[$.string_lit, $.quoted_template],
|
||||||
],
|
],
|
||||||
|
|
||||||
externals: $ => [
|
externals: $ => [
|
||||||
@@ -233,8 +234,14 @@ module.exports = grammar({
|
|||||||
// $.heredoc_template,
|
// $.heredoc_template,
|
||||||
),
|
),
|
||||||
|
|
||||||
// application should check that no template interpolation is contained
|
string_lit: $ => seq(
|
||||||
string_lit: $ => $.quoted_template,
|
'"',
|
||||||
|
repeat(choice(
|
||||||
|
$._template_char,
|
||||||
|
$.escape_sequence,
|
||||||
|
)),
|
||||||
|
'"',
|
||||||
|
),
|
||||||
|
|
||||||
quoted_template: $ => seq(
|
quoted_template: $ => seq(
|
||||||
'"',
|
'"',
|
||||||
|
|||||||
@@ -1015,8 +1015,33 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"string_lit": {
|
"string_lit": {
|
||||||
"type": "SYMBOL",
|
"type": "SEQ",
|
||||||
"name": "quoted_template"
|
"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": {
|
"quoted_template": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
@@ -1176,6 +1201,10 @@
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
"conditional"
|
"conditional"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"string_lit",
|
||||||
|
"quoted_template"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"precedences": [],
|
"precedences": [],
|
||||||
|
|||||||
@@ -556,11 +556,11 @@
|
|||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": false,
|
"multiple": true,
|
||||||
"required": true,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "quoted_template",
|
"type": "escape_sequence",
|
||||||
"named": true
|
"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
|
(attribute
|
||||||
(identifier)
|
(identifier)
|
||||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
(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