From 8ad760f47105c3abb420c0888d4b37ad1f568f3e Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Mon, 25 Mar 2024 12:33:49 +0100 Subject: [PATCH 1/2] Add testcase for `=>` --- tests/snapshot/hcl/issue114.hcl | 7 ++ tests/snapshot/hcl/issue114.hcl.snap | 96 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/snapshot/hcl/issue114.hcl create mode 100644 tests/snapshot/hcl/issue114.hcl.snap diff --git a/tests/snapshot/hcl/issue114.hcl b/tests/snapshot/hcl/issue114.hcl new file mode 100644 index 0000000..186b78f --- /dev/null +++ b/tests/snapshot/hcl/issue114.hcl @@ -0,0 +1,7 @@ +byte_match_statement_rules = local.enabled && var.byte_match_statement_rules != null ? { + for rule in flatten(var.byte_match_statement_rules) : + format("%s-%s", + lookup(rule, "name", null) != null ? rule.name : format("%s-byte-match-%d", module.this.id, rule.priority), + rule.action, + ) => rule + } : {} \ No newline at end of file diff --git a/tests/snapshot/hcl/issue114.hcl.snap b/tests/snapshot/hcl/issue114.hcl.snap new file mode 100644 index 0000000..5146b2b --- /dev/null +++ b/tests/snapshot/hcl/issue114.hcl.snap @@ -0,0 +1,96 @@ +>byte_match_statement_rules = local.enabled && var.byte_match_statement_rules != null ? { +#^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl variable.declaration.hcl variable.other.readwrite.hcl +# ^ source.hcl variable.declaration.hcl +# ^ source.hcl variable.declaration.hcl keyword.operator.assignment.hcl +# ^ source.hcl variable.declaration.hcl +# ^^^^^ source.hcl meta.block.hcl entity.name.type.hcl +# ^ source.hcl meta.block.hcl +# ^^^^^^^ source.hcl meta.block.hcl variable.other.enummember.hcl +# ^^^^ source.hcl meta.block.hcl +# ^^^ source.hcl meta.block.hcl variable.other.enummember.hcl +# ^ source.hcl meta.block.hcl +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl variable.other.enummember.hcl +# ^^^^ source.hcl meta.block.hcl +# ^^^^ source.hcl meta.block.hcl variable.other.enummember.hcl +# ^^^ source.hcl meta.block.hcl +# ^ source.hcl meta.block.hcl punctuation.section.block.begin.hcl +> for rule in flatten(var.byte_match_statement_rules) : +#^^^^^^^^^^^^^^ source.hcl meta.block.hcl +# ^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl support.function.builtin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^^^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +# ^ source.hcl meta.block.hcl +# ^ source.hcl meta.block.hcl keyword.operator.hcl +> format("%s-%s", +#^^^^ source.hcl meta.block.hcl +# ^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl support.function.builtin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl +# ^^^^^ source.hcl meta.block.hcl meta.function-call.hcl string.quoted.double.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.separator.hcl +> lookup(rule, "name", null) != null ? rule.name : format("%s-byte-match-%d", module.this.id, rule.priority), +#^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl +# ^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl support.function.builtin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.separator.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.separator.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl constant.language.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl +# ^^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl constant.language.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.hcl +# ^^^^^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl +# ^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl support.function.builtin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl +# ^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.separator.hcl +# ^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.separator.hcl +# ^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.separator.hcl +> rule.action, +#^^^^^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl keyword.operator.accessor.hcl +# ^^^^^^ source.hcl meta.block.hcl meta.function-call.hcl variable.other.member.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.separator.hcl +> ) => rule +#^^^^ source.hcl meta.block.hcl meta.function-call.hcl +# ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +# ^^ source.hcl meta.block.hcl +# ^ source.hcl meta.block.hcl keyword.operator.hcl +# ^^^^^^ source.hcl meta.block.hcl +> } : {} +#^^ source.hcl meta.block.hcl +# ^ source.hcl meta.block.hcl punctuation.section.block.end.hcl +# ^ source.hcl +# ^ source.hcl keyword.operator.hcl +# ^ source.hcl +# ^ source.hcl meta.braces.hcl punctuation.section.braces.begin.hcl +# ^ source.hcl meta.braces.hcl punctuation.section.braces.end.hcl \ No newline at end of file From 443aee88d28bddcf68b19f129ec47d266f2adb3d Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Mon, 25 Mar 2024 12:34:34 +0100 Subject: [PATCH 2/2] Introduce `=>` as new operator --- src/_main.yml | 2 ++ syntaxes/hcl.tmGrammar.json | 4 ++++ syntaxes/terraform.tmGrammar.json | 4 ++++ tests/snapshot/hcl/issue114.hcl.snap | 4 ++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/_main.yml b/src/_main.yml index 28ce74e..e379c82 100644 --- a/src/_main.yml +++ b/src/_main.yml @@ -230,6 +230,8 @@ repository: name: keyword.operator.hcl - match: "\\:" name: keyword.operator.hcl + - match: \=\> + name: keyword.operator.hcl brackets: begin: \[ beginCaptures: diff --git a/syntaxes/hcl.tmGrammar.json b/syntaxes/hcl.tmGrammar.json index 7e5b662..651e014 100644 --- a/syntaxes/hcl.tmGrammar.json +++ b/syntaxes/hcl.tmGrammar.json @@ -671,6 +671,10 @@ { "name": "keyword.operator.hcl", "match": "\\:" + }, + { + "name": "keyword.operator.hcl", + "match": "\\=\\>" } ] }, diff --git a/syntaxes/terraform.tmGrammar.json b/syntaxes/terraform.tmGrammar.json index efeda56..9252e20 100644 --- a/syntaxes/terraform.tmGrammar.json +++ b/syntaxes/terraform.tmGrammar.json @@ -693,6 +693,10 @@ { "name": "keyword.operator.hcl", "match": "\\:" + }, + { + "name": "keyword.operator.hcl", + "match": "\\=\\>" } ] }, diff --git a/tests/snapshot/hcl/issue114.hcl.snap b/tests/snapshot/hcl/issue114.hcl.snap index 5146b2b..987ca50 100644 --- a/tests/snapshot/hcl/issue114.hcl.snap +++ b/tests/snapshot/hcl/issue114.hcl.snap @@ -83,8 +83,8 @@ > ) => rule #^^^^ source.hcl meta.block.hcl meta.function-call.hcl # ^ source.hcl meta.block.hcl meta.function-call.hcl punctuation.section.parens.end.hcl -# ^^ source.hcl meta.block.hcl -# ^ source.hcl meta.block.hcl keyword.operator.hcl +# ^ source.hcl meta.block.hcl +# ^^ source.hcl meta.block.hcl keyword.operator.hcl # ^^^^^^ source.hcl meta.block.hcl > } : {} #^^ source.hcl meta.block.hcl