From 98d401c359174dc583d6345fe6dd09eb52e255fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Tue, 25 Jun 2024 14:43:08 +0100 Subject: [PATCH] fix: Add support for attributes named "in". (#164) Special thanks to @jqcorreia for the grammar lesson and debugging. --- hcl2/hcl2.lark | 5 +++-- .../resource_in_attribute.json | 13 +++++++++++++ .../terraform-config/resource_in_attribute.tf | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/helpers/terraform-config-json/resource_in_attribute.json create mode 100644 test/helpers/terraform-config/resource_in_attribute.tf diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index cee792e..f477e3b 100644 --- a/hcl2/hcl2.lark +++ b/hcl2/hcl2.lark @@ -5,7 +5,8 @@ block : identifier (identifier | STRING_LIT)* new_line_or_comment? "{" body "}" new_line_and_or_comma: new_line_or_comment | "," | "," new_line_or_comment new_line_or_comment: ( /\n/ | /#.*\n/ | /\/\/.*\n/ )+ -identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ +identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ | IN +IN : "in" ?expression : expr_term | operation | conditional @@ -27,7 +28,7 @@ expr_term : "(" new_line_or_comment? expression new_line_or_comment? ")" | index_expr_term | get_attr_expr_term | identifier - | provider_function_call + | provider_function_call | heredoc_template | heredoc_template_trim | attr_splat_expr_term diff --git a/test/helpers/terraform-config-json/resource_in_attribute.json b/test/helpers/terraform-config-json/resource_in_attribute.json new file mode 100644 index 0000000..f94f842 --- /dev/null +++ b/test/helpers/terraform-config-json/resource_in_attribute.json @@ -0,0 +1,13 @@ +{ + "resource": [ + { + "custom_provider_resource": { + "resource_name": { + "name": "resource_name", + "attribute": "attribute_value", + "in": "attribute_value2" + } + } + } + ] +} diff --git a/test/helpers/terraform-config/resource_in_attribute.tf b/test/helpers/terraform-config/resource_in_attribute.tf new file mode 100644 index 0000000..85052f0 --- /dev/null +++ b/test/helpers/terraform-config/resource_in_attribute.tf @@ -0,0 +1,5 @@ +resource "custom_provider_resource" "resource_name" { + name = "resource_name" + attribute = "attribute_value" + in = "attribute_value2" +}