add real world test corpus; work on some parse errors and weirdnesses

This commit is contained in:
mhoffm
2021-06-19 16:56:35 +02:00
parent fa9b0307c6
commit 5f7a5b5e98
900 changed files with 16442 additions and 9184 deletions

View File

@@ -10,7 +10,8 @@ block_1 {
(config_file
(body
(block
(identifier))))
(identifier)
(body))))
================================================================================
basic block on one line
@@ -68,7 +69,8 @@ block_1 {
(identifier)
(body
(block
(identifier))))))
(identifier)
(body))))))
================================================================================
nested block on one line

View File

@@ -1,5 +1,5 @@
================================================================================
collection value tuple
tuple
================================================================================
foo = [1, 2, "foo"]
@@ -25,7 +25,70 @@ foo = [1, 2, "foo"]
(template_literal))))))))))
================================================================================
collection value object
multiline tuple
================================================================================
foo = [
1,
2,
"foo"
]
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(tuple
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(string_lit
(template_literal))))))))))
================================================================================
empty tuple
================================================================================
foo = []
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(tuple))))))
================================================================================
multiline empty tuple
================================================================================
foo = [
]
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(tuple))))))
================================================================================
object
================================================================================
foo = {1: 2, "foo"="bar"}
@@ -55,3 +118,250 @@ foo = {1: 2, "foo"="bar"}
(literal_value
(string_lit
(template_literal)))))))))))
================================================================================
multiline object
================================================================================
foo = {
1: 2,
"foo"="bar"
}
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(object
(object_elem
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))
(object_elem
(expression
(literal_value
(string_lit
(template_literal))))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
================================================================================
empty object
================================================================================
foo = { }
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(object))))))
================================================================================
multiline empty object
================================================================================
foo = {
}
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(object))))))
================================================================================
multiline object weird newlines
================================================================================
foo = { 1: 2,
"foo"="bar"
}
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(object
(object_elem
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))
(object_elem
(expression
(literal_value
(string_lit
(template_literal))))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
================================================================================
complex object
================================================================================
foo = {
a = "1",
b = "2"
}
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(object
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))))))))
================================================================================
complex from real world
================================================================================
worker_groups = [
{
name = "jasonb-test-group-1"
instance_type = "t2.small"
asg_desired_capacity = 2
additional_security_group_ids = [aws_security_group.external_connection.id]
},
{
name = "jasonb-test-group-2"
instance_type = "t2.medium"
additional_security_group_ids = [aws_security_group.external_connection.id]
asg_desired_capacity = 1
},
]
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(collection_value
(tuple
(expression
(collection_value
(object
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(numeric_lit))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(collection_value
(tuple
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))))))))))
(expression
(collection_value
(object
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(string_lit
(template_literal)))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(collection_value
(tuple
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier)))))))
(object_elem
(expression
(variable_expr
(identifier)))
(expression
(literal_value
(numeric_lit)))))))))))))

432
test/corpus/real_world.txt Normal file
View File

@@ -0,0 +1,432 @@
================================================================================
example 1
================================================================================
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
token = data.aws_eks_cluster_auth.cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
}
--------------------------------------------------------------------------------
(config_file
(body
(block
(identifier)
(string_lit
(template_literal))
(body
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(function_call
(identifier)
(function_arguments
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))
(index
(legacy_index))
(get_attr
(identifier)))))))))))
================================================================================
example 2
================================================================================
locals {
storage_account_container_name = var.storage_account_container_name == "" ? azurerm_storage_container.storage_account_container[0].name : var.storage_account_container_name
bootstrap_storage_account_container_name = var.bootstrap_storage_account_container_name == "" ? azurerm_storage_container.bootstrap_storage_account_container[0].name : var.bootstrap_storage_account_container_name
}
resource "azurerm_storage_container" "storage_account_container" {
count = var.storage_account_container_name == "" ? 1 : 0
name = var.storage_account_name
storage_account_name = var.storage_account_name
container_access_type = "private"
}
resource "azurerm_storage_container" "bootstrap_storage_account_container" {
count = var.bootstrap_storage_account_container_name == "" ? 1 : 0
name = var.bootstrap_storage_account_name
storage_account_name = var.bootstrap_storage_account_name
container_access_type = "private"
}
resource "azurerm_storage_blob" "bootstrap_license" {
count = var.bootstrap_storage_account_container_name == "" ? 1 : 0
source = var.tfe_license_filepath
name = var.tfe_license_name
storage_account_name = var.bootstrap_storage_account_name
storage_container_name = azurerm_storage_container.bootstrap_storage_account_container[0].name
type = "Page"
}
resource "azurerm_storage_blob" "proxy_cert" {
count = var.proxy_cert_name != "" && var.bootstrap_storage_account_container_name == "" ? 1 : 0
source = var.proxy_cert_path
name = var.proxy_cert_name
storage_account_name = var.bootstrap_storage_account_name
storage_container_name = azurerm_storage_container.bootstrap_storage_account_container[0].name
type = "Block"
}
--------------------------------------------------------------------------------
(config_file
(body
(block
(identifier)
(body
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(index
(new_index
(expression
(literal_value
(numeric_lit)))))
(get_attr
(identifier)))
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))))
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(index
(new_index
(expression
(literal_value
(numeric_lit)))))
(get_attr
(identifier)))
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))))))
(block
(identifier)
(string_lit
(template_literal))
(string_lit
(template_literal))
(body
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(literal_value
(string_lit
(template_literal)))))))
(block
(identifier)
(string_lit
(template_literal))
(string_lit
(template_literal))
(body
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(literal_value
(string_lit
(template_literal)))))))
(block
(identifier)
(string_lit
(template_literal))
(string_lit
(template_literal))
(body
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(template_expr
(quoted_template)))))
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(index
(new_index
(expression
(literal_value
(numeric_lit)))))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(literal_value
(string_lit
(template_literal)))))))
(block
(identifier)
(string_lit
(template_literal))
(string_lit
(template_literal))
(body
(attribute
(identifier)
(expression
(conditional
(expression
(operation
(binary_operation
(variable_expr
(identifier))
(get_attr
(identifier))
(ERROR
(template_expr
(quoted_template)))
(template_expr
(quoted_template)))))
(expression
(literal_value
(numeric_lit)))
(expression
(literal_value
(numeric_lit))))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(index
(new_index
(expression
(literal_value
(numeric_lit)))))
(get_attr
(identifier))))
(attribute
(identifier)
(expression
(literal_value
(string_lit
(template_literal)))))))))
================================================================================
example 3
================================================================================
private_key_pem = element(tls_private_key.server.*.private_key_pem, count.index)
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(function_call
(identifier)
(function_arguments
(expression
(variable_expr
(identifier))
(get_attr
(identifier))
(splat
(attr_splat
(get_attr
(identifier)))))
(expression
(variable_expr
(identifier))
(get_attr
(identifier)))))))))

View File

@@ -32,9 +32,10 @@ foo = bar[1]
(variable_expr
(identifier))
(index
(expression
(literal_value
(numeric_lit))))))))
(new_index
(expression
(literal_value
(numeric_lit)))))))))
================================================================================
attr splat
@@ -102,6 +103,7 @@ foo = bar[*][*].a.b.c[d]
(get_attr
(identifier))
(index
(expression
(variable_expr
(identifier))))))))))
(new_index
(expression
(variable_expr
(identifier)))))))))))

View File

@@ -1,5 +1,5 @@
================================================================================
string bad escape sequence 2
bad escape sequence 2
================================================================================
foo = "bar\uZZ"
@@ -11,14 +11,14 @@ foo = "bar\uZZ"
(attribute
(identifier)
(expression
(template_expr
(quoted_template
(literal_value
(string_lit
(template_literal
(ERROR
(UNEXPECTED '\')))))))))
================================================================================
string literal multi line error
literal multi line error
================================================================================
foo = "
@@ -31,14 +31,14 @@ bar"
(attribute
(identifier)
(expression
(template_expr
(quoted_template
(literal_value
(string_lit
(ERROR
(UNEXPECTED 'b'))
(UNEXPECTED '\n'))
(template_literal)))))))
================================================================================
string literal unescaped tab
unescaped tab
================================================================================
foo = "foo bar"
@@ -50,14 +50,12 @@ foo = "foo bar"
(attribute
(identifier)
(expression
(template_expr
(quoted_template
(template_literal
(ERROR
(UNEXPECTED 'b')))))))))
(literal_value
(string_lit
(template_literal)))))))
================================================================================
string literal unescaped backslash
unescaped backslash
================================================================================
foo = "foo\bar"
@@ -69,14 +67,14 @@ foo = "foo\bar"
(attribute
(identifier)
(expression
(template_expr
(quoted_template
(literal_value
(string_lit
(template_literal
(ERROR
(UNEXPECTED '\')))))))))
================================================================================
string literal escaped backslash at end
escaped backslash at end
================================================================================
foo = "foo\\"
@@ -110,7 +108,7 @@ foo = "$${foo.bar}"
(template_literal)))))))
================================================================================
string literal template chars but no template 1
template chars but no template 1
================================================================================
foo = "$$$"
@@ -127,7 +125,7 @@ foo = "$$$"
(template_literal)))))))
================================================================================
string literal template chars but no template 2
template chars but no template 2
================================================================================
foo = "100%"
@@ -144,7 +142,7 @@ foo = "100%"
(template_literal)))))))
================================================================================
string literal template chars but no template 3
template chars but no template 3
================================================================================
foo = "%\n\t"
@@ -161,7 +159,7 @@ foo = "%\n\t"
(template_literal)))))))
================================================================================
string literal template chars but no template 4
template chars but no template 4
================================================================================
foo = "%%\n\t"
@@ -178,7 +176,7 @@ foo = "%%\n\t"
(template_literal)))))))
================================================================================
string literal template chars but no template 5
template chars but no template 5
================================================================================
foo = "$$"
@@ -195,7 +193,7 @@ foo = "$$"
(template_literal)))))))
================================================================================
string literal template chars but no template 6
template chars but no template 6
================================================================================
foo = "%%{\n\t"
@@ -212,7 +210,7 @@ foo = "%%{\n\t"
(template_literal)))))))
================================================================================
string literal escaped template
escaped template
================================================================================
foo = "$${ var.bar }"

View File

@@ -125,9 +125,10 @@ foo = "${ {a=b}[a] }"
(variable_expr
(identifier))))))
(index
(expression
(variable_expr
(identifier))))))))))))
(new_index
(expression
(variable_expr
(identifier)))))))))))))
================================================================================
escaped template interpolation start