From 8bdf090b7ad88b3d3265bd84a69b37bf1b8a5d11 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 12 Mar 2024 09:31:49 +0100 Subject: [PATCH 1/2] Add namespaced functions to HCL grammar --- src/_main.yml | 6 ++++-- syntaxes/hcl.tmGrammar.json | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/_main.yml b/src/_main.yml index 9a9a2e1..978cb84 100644 --- a/src/_main.yml +++ b/src/_main.yml @@ -402,13 +402,15 @@ repository: "0": name: keyword.operator.splat.hcl functions: - begin: (\w+)(\() + begin: ([:\-\w]+)(\() name: meta.function-call.hcl comment: Built-in function calls beginCaptures: "1": patterns: - - match: \b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b + - match: \b[[:alpha:]][\w_-]*::([[:alpha:]][\w_-]*::)?[[:alpha:]][\w_-]*\b + name: support.function.namespaced.hcl + - match: \b[[:alpha:]][\w_-]*\b name: support.function.builtin.hcl "2": name: punctuation.section.parens.begin.hcl diff --git a/syntaxes/hcl.tmGrammar.json b/syntaxes/hcl.tmGrammar.json index e7cd95d..458d266 100644 --- a/syntaxes/hcl.tmGrammar.json +++ b/syntaxes/hcl.tmGrammar.json @@ -283,14 +283,18 @@ }, "functions": { "name": "meta.function-call.hcl", - "begin": "(\\w+)(\\()", + "begin": "([:\\-\\w]+)(\\()", "end": "\\)", "comment": "Built-in function calls", "beginCaptures": { "1": { "patterns": [ { - "match": "\\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\\b", + "match": "\\b[[:alpha:]][\\w_-]*::([[:alpha:]][\\w_-]*::)?[[:alpha:]][\\w_-]*\\b", + "name": "support.function.namespaced.hcl" + }, + { + "match": "\\b[[:alpha:]][\\w_-]*\\b", "name": "support.function.builtin.hcl" } ] From 499e1a5f25d90103788dec4b13f69e8f3fb08f8d Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 12 Mar 2024 09:32:41 +0100 Subject: [PATCH 2/2] Add HCL namespaced functions test cases --- tests/snapshot/hcl/expressions_functions.hcl | 6 +++++ .../hcl/expressions_functions.hcl.snap | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/snapshot/hcl/expressions_functions.hcl b/tests/snapshot/hcl/expressions_functions.hcl index 227e0d4..8eec4c6 100644 --- a/tests/snapshot/hcl/expressions_functions.hcl +++ b/tests/snapshot/hcl/expressions_functions.hcl @@ -35,3 +35,9 @@ upper("hello") # known foo("bar") + +prefix::namespace::func("bar") +prefix::namespace::func() + +namespace::short("bar") +namespace::short_name() \ No newline at end of file diff --git a/tests/snapshot/hcl/expressions_functions.hcl.snap b/tests/snapshot/hcl/expressions_functions.hcl.snap index 73f5a80..e04a847 100644 --- a/tests/snapshot/hcl/expressions_functions.hcl.snap +++ b/tests/snapshot/hcl/expressions_functions.hcl.snap @@ -356,4 +356,27 @@ # ^^^ source.hcl meta.function-call.hcl string.quoted.double.hcl # ^ source.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl # ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl -> \ No newline at end of file +> +>prefix::namespace::func("bar") +#^^^^^^^^^^^^^^^^^^^^^^^ source.hcl meta.function-call.hcl support.function.namespaced.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl +# ^^^ source.hcl meta.function-call.hcl string.quoted.double.hcl +# ^ source.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +>prefix::namespace::func() +#^^^^^^^^^^^^^^^^^^^^^^^ source.hcl meta.function-call.hcl support.function.namespaced.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +> +>namespace::short("bar") +#^^^^^^^^^^^^^^^^ source.hcl meta.function-call.hcl support.function.namespaced.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl +# ^^^ source.hcl meta.function-call.hcl string.quoted.double.hcl +# ^ source.hcl meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl +>namespace::short_name() +#^^^^^^^^^^^^^^^^^^^^^ source.hcl meta.function-call.hcl support.function.namespaced.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl +# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl \ No newline at end of file