handle quoted template expressions and template interpolations

This commit is contained in:
mhoffm
2021-06-14 00:55:24 +02:00
parent 3c984653bb
commit 7b91d51683
20 changed files with 5381 additions and 4751 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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