diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index eefcd24b..cd057f12 100644 --- a/hcl2/hcl2.lark +++ b/hcl2/hcl2.lark @@ -11,7 +11,7 @@ identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ conditional : expression "?" _NEW_LINE_OR_COMMENT* expression _NEW_LINE_OR_COMMENT* ":" _NEW_LINE_OR_COMMENT* expression _NEW_LINE_OR_COMMENT? -?operation : unary_op | binary_op +?operation : unary_op _NEW_LINE_OR_COMMENT* | binary_op !unary_op : ("-" | "!") expr_term binary_op : expression binary_term !binary_operator : "==" | "!=" | "<" | ">" | "<=" | ">=" | "-" | "*" | "/" | "%" | "&&" | "||" | "+" diff --git a/test/helpers/terraform-config-json/unary_operator_newline.json b/test/helpers/terraform-config-json/unary_operator_newline.json new file mode 100644 index 00000000..6b42f6e7 --- /dev/null +++ b/test/helpers/terraform-config-json/unary_operator_newline.json @@ -0,0 +1,43 @@ +{ + "variable": [ + { + "names": { + "type": [ + "${list(string)}" + ], + "default": [ + [ + "a" + ] + ], + "validation": [ + { + "condition": [ + "${alltrue([for n in var.names : length(n) > 0 && !contains(['host'],n) && n != \"x\"])}" + ], + "error_message": [ + "bad name" + ] + } + ], + "__start_line__": 1, + "__end_line__": 13 + } + } + ], + "locals": [ + { + "not_then_or": [ + "${!var.a || var.b}" + ], + "negative_then_plus": [ + "${-var.c + 2}" + ], + "not_with_comment": [ + "${!var.a && var.b}" + ], + "__start_line__": 15, + "__end_line__": 29 + } + ] +} diff --git a/test/helpers/terraform-config/unary_operator_newline.tf b/test/helpers/terraform-config/unary_operator_newline.tf new file mode 100644 index 00000000..598092fc --- /dev/null +++ b/test/helpers/terraform-config/unary_operator_newline.tf @@ -0,0 +1,29 @@ +variable "names" { + type = list(string) + default = ["a"] + validation { + condition = alltrue([ + for n in var.names : + length(n) > 0 + && !contains(["host"], n) + && n != "x" + ]) + error_message = "bad name" + } +} + +locals { + not_then_or = ( + !var.a + || var.b + ) + negative_then_plus = ( + -var.c + + 2 + ) + not_with_comment = ( + !var.a + # comment + && var.b + ) +}