handle quoted template expressions and template interpolations
This commit is contained in:
@@ -10,10 +10,7 @@ foo = "bar"
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
(expr_term
|
||||
(literal_value
|
||||
(string_lit)))))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))
|
||||
|
||||
==================
|
||||
attribute with variable
|
||||
@@ -27,8 +24,5 @@ foo = bar
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
(expr_term
|
||||
(variable_expr
|
||||
(identifier)))))))
|
||||
(expression (expr_term (variable_expr (identifier)))))))
|
||||
|
||||
|
||||
@@ -39,15 +39,12 @@ block_1 "strlit1" "strlit2" {
|
||||
(body
|
||||
(block
|
||||
(identifier)
|
||||
(string_lit)
|
||||
(string_lit)
|
||||
(string_lit (quoted_template))
|
||||
(string_lit (quoted_template))
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
(expr_term
|
||||
(literal_value
|
||||
(string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
|
||||
==================
|
||||
nested block
|
||||
|
||||
@@ -16,7 +16,7 @@ foo = [1, 2, "foo"]
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (numeric_lit))))
|
||||
(expression (expr_term (literal_value (numeric_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))))
|
||||
|
||||
==================
|
||||
collection value object
|
||||
@@ -38,6 +38,6 @@ foo = {1: 2, "foo"="bar"}
|
||||
(expression (expr_term (literal_value (numeric_lit))))
|
||||
(expression (expr_term (literal_value (numeric_lit)))))
|
||||
(object_elem
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit))))))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template))))))))))))
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ foo = [for v in ["a", "b"]: v]
|
||||
(expr_term
|
||||
(collection_value
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
(expression (expr_term (variable_expr (identifier)))))))))))
|
||||
|
||||
==================
|
||||
@@ -47,8 +47,8 @@ foo = [for i, v in ["a", "b"]: i]
|
||||
(expr_term
|
||||
(collection_value
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
(expression (expr_term (variable_expr (identifier)))))))))))
|
||||
|
||||
==================
|
||||
@@ -74,9 +74,9 @@ foo = [for i, v in ["a", "b", "c"]: v if pred(i)]
|
||||
(expr_term
|
||||
(collection_value
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
(expression (expr_term (variable_expr (identifier))))
|
||||
(for_cond
|
||||
(expression
|
||||
@@ -109,8 +109,8 @@ foo = {for i, v in ["a", "b"]: v => i}
|
||||
(expr_term
|
||||
(collection_value
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
(expression (expr_term (variable_expr (identifier))))
|
||||
(expression (expr_term (variable_expr (identifier)))))))))))
|
||||
|
||||
@@ -137,7 +137,7 @@ foo = {for i, v in ["a", "b"]: v => i...}
|
||||
(expr_term
|
||||
(collection_value
|
||||
(tuple
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))
|
||||
(expression (expr_term (variable_expr (identifier))))
|
||||
(expression (expr_term (variable_expr (identifier)))) (ellipsis))))))))
|
||||
|
||||
@@ -10,10 +10,7 @@ foo = bar()
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
(expr_term
|
||||
(function_call
|
||||
(identifier)))))))
|
||||
(expression (expr_term (function_call (identifier)))))))
|
||||
|
||||
==================
|
||||
unary function call
|
||||
@@ -32,10 +29,7 @@ foo = bar("foo")
|
||||
(function_call
|
||||
(identifier)
|
||||
(function_arguments
|
||||
(expression
|
||||
(expr_term
|
||||
(literal_value
|
||||
(string_lit)))))))))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))))
|
||||
|
||||
==================
|
||||
variadic function call
|
||||
@@ -77,7 +71,7 @@ foo = bar(
|
||||
(function_call
|
||||
(identifier)
|
||||
(function_arguments
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit))))
|
||||
(expression (expr_term (literal_value (string_lit)))))))))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template))))
|
||||
(expression (expr_term (template_expr (quoted_template)))))))))))
|
||||
|
||||
|
||||
@@ -125,158 +125,4 @@ foo = null
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (null_lit)))))))
|
||||
|
||||
==================
|
||||
string literal one line
|
||||
==================
|
||||
|
||||
foo = "bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit)))))))
|
||||
|
||||
==================
|
||||
string literal escaped newline
|
||||
==================
|
||||
|
||||
foo = "bar\nbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped tab
|
||||
==================
|
||||
|
||||
foo = "bar\tbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped "
|
||||
==================
|
||||
|
||||
foo = "bar\"baz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped \
|
||||
==================
|
||||
|
||||
foo = "bar\\baz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped \uFFFF
|
||||
==================
|
||||
|
||||
foo = "bar\uFFFFbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string bad escape sequence
|
||||
==================
|
||||
|
||||
foo = "bar\pbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (ERROR (UNEXPECTED 'p')))))))))
|
||||
|
||||
==================
|
||||
string bad escape sequence 2
|
||||
==================
|
||||
|
||||
foo = "bar\uZZ"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (ERROR (UNEXPECTED 'Z')))))))))
|
||||
|
||||
==================
|
||||
string literal multi line error
|
||||
==================
|
||||
|
||||
foo = "
|
||||
bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (ERROR (UNEXPECTED 'b')))))))))
|
||||
|
||||
==================
|
||||
string literal unescaped tab
|
||||
==================
|
||||
|
||||
foo = "foo bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (ERROR (UNEXPECTED 'b')))))))))
|
||||
|
||||
==================
|
||||
string literal unescaped backslash
|
||||
==================
|
||||
|
||||
foo = "foo\bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (literal_value (string_lit (ERROR (UNEXPECTED 'b')))))))))
|
||||
|
||||
|
||||
288
test/corpus/strings.txt
Normal file
288
test/corpus/strings.txt
Normal file
@@ -0,0 +1,288 @@
|
||||
==================
|
||||
string literal one line
|
||||
==================
|
||||
|
||||
foo = "bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template)))))))
|
||||
|
||||
==================
|
||||
string literal escaped newline
|
||||
==================
|
||||
|
||||
foo = "bar\nbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped tab
|
||||
==================
|
||||
|
||||
foo = "bar\tbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped "
|
||||
==================
|
||||
|
||||
foo = "bar\"baz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped \
|
||||
==================
|
||||
|
||||
foo = "bar\\baz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped \uFFFF
|
||||
==================
|
||||
|
||||
foo = "bar\uFFFFbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string bad escape sequence
|
||||
==================
|
||||
|
||||
foo = "bar\pbaz"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (ERROR (UNEXPECTED '\')))))))))
|
||||
|
||||
==================
|
||||
string bad escape sequence 2
|
||||
==================
|
||||
|
||||
foo = "bar\uZZ"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (ERROR (UNEXPECTED '\')))))))))
|
||||
|
||||
==================
|
||||
string literal multi line error
|
||||
==================
|
||||
|
||||
foo = "
|
||||
bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (ERROR (UNEXPECTED 'b')))))))))
|
||||
|
||||
==================
|
||||
string literal unescaped tab
|
||||
==================
|
||||
|
||||
foo = "foo bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (ERROR (UNEXPECTED 'b')))))))))
|
||||
|
||||
==================
|
||||
string literal unescaped backslash
|
||||
==================
|
||||
|
||||
foo = "foo\bar"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (ERROR (UNEXPECTED '\')))))))))
|
||||
|
||||
==================
|
||||
string literal escaped backslash at end
|
||||
==================
|
||||
|
||||
foo = "foo\\"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
|
||||
==================
|
||||
string literal escaped template interpolation
|
||||
==================
|
||||
|
||||
foo = "$${foo.bar}"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 1
|
||||
==================
|
||||
|
||||
foo = "$$$"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template)))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 2
|
||||
==================
|
||||
|
||||
foo = "100%"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template)))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 3
|
||||
==================
|
||||
|
||||
foo = "%\n\t"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template
|
||||
(escape_sequence)
|
||||
(escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 4
|
||||
==================
|
||||
|
||||
foo = "%%\n\t"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template
|
||||
(escape_sequence)
|
||||
(escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 5
|
||||
==================
|
||||
|
||||
foo = "$$"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template)))))))
|
||||
|
||||
==================
|
||||
string literal template chars but no template 6
|
||||
==================
|
||||
|
||||
foo = "%%{\n\t"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template
|
||||
(escape_sequence)
|
||||
(escape_sequence)
|
||||
(escape_sequence))))))))
|
||||
|
||||
==================
|
||||
string literal escaped template
|
||||
==================
|
||||
|
||||
foo = "$${ var.bar }"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (escape_sequence))))))))
|
||||
13
test/corpus/templates.txt
Normal file
13
test/corpus/templates.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
==================
|
||||
quoted template expression
|
||||
==================
|
||||
|
||||
foo = "${ var.bar }"
|
||||
|
||||
---
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression (expr_term (template_expr (quoted_template (template_interpolation))))))))
|
||||
Reference in New Issue
Block a user