Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support provider defined functions for Terraform HCL #99

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ repository:
- include: "#expressions"

functions:
begin: (\w+)(\()
begin: ([:\-\w]+)(\()
name: meta.function-call.hcl
comment: Built-in function calls
beginCaptures:
"1":
patterns:
- match: \b(abs|abspath|alltrue|anytrue|base64decode|base64encode|base64gzip|base64sha256|base64sha512|basename|bcrypt|can|ceil|chomp|chunklist|cidrhost|cidrnetmask|cidrsubnet|cidrsubnets|coalesce|coalescelist|compact|concat|contains|csvdecode|dirname|distinct|element|endswith|file|filebase64|filebase64sha256|filebase64sha512|fileexists|filemd5|fileset|filesha1|filesha256|filesha512|flatten|floor|format|formatdate|formatlist|indent|index|join|jsondecode|jsonencode|keys|length|log|lookup|lower|matchkeys|max|md5|merge|min|nonsensitive|one|parseint|pathexpand|plantimestamp|pow|range|regex|regexall|replace|reverse|rsadecrypt|sensitive|setintersection|setproduct|setsubtract|setunion|sha1|sha256|sha512|signum|slice|sort|split|startswith|strcontains|strrev|substr|sum|templatefile|textdecodebase64|textencodebase64|timeadd|timecmp|timestamp|title|tobool|tolist|tomap|tonumber|toset|tostring|transpose|trim|trimprefix|trimspace|trimsuffix|try|upper|urlencode|uuid|uuidv5|values|yamldecode|yamlencode|zipmap)\b
name: support.function.builtin.terraform
- match: \bprovider::[^\d\W][\w_-]*::[^\d\W][\w_-]*\b
name: support.function.provider
"2":
name: punctuation.section.parens.begin.hcl
end: \)
Expand Down
6 changes: 5 additions & 1 deletion syntaxes/terraform.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
},
"functions": {
"name": "meta.function-call.hcl",
"begin": "(\\w+)(\\()",
"begin": "([:\\-\\w]+)(\\()",
"end": "\\)",
"comment": "Built-in function calls",
"beginCaptures": {
Expand All @@ -293,6 +293,10 @@
{
"match": "\\b(abs|abspath|alltrue|anytrue|base64decode|base64encode|base64gzip|base64sha256|base64sha512|basename|bcrypt|can|ceil|chomp|chunklist|cidrhost|cidrnetmask|cidrsubnet|cidrsubnets|coalesce|coalescelist|compact|concat|contains|csvdecode|dirname|distinct|element|endswith|file|filebase64|filebase64sha256|filebase64sha512|fileexists|filemd5|fileset|filesha1|filesha256|filesha512|flatten|floor|format|formatdate|formatlist|indent|index|join|jsondecode|jsonencode|keys|length|log|lookup|lower|matchkeys|max|md5|merge|min|nonsensitive|one|parseint|pathexpand|plantimestamp|pow|range|regex|regexall|replace|reverse|rsadecrypt|sensitive|setintersection|setproduct|setsubtract|setunion|sha1|sha256|sha512|signum|slice|sort|split|startswith|strcontains|strrev|substr|sum|templatefile|textdecodebase64|textencodebase64|timeadd|timecmp|timestamp|title|tobool|tolist|tomap|tonumber|toset|tostring|transpose|trim|trimprefix|trimspace|trimsuffix|try|upper|urlencode|uuid|uuidv5|values|yamldecode|yamlencode|zipmap)\\b",
"name": "support.function.builtin.terraform"
},
{
"match": "\\bprovider::[^\\d\\W][\\w_-]*::[^\\d\\W][\\w_-]*\\b",
"name": "support.function.provider"
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions tests/snapshot/terraform/expressions_functions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ upper("hello")
# known

foo("bar")

# provider defined functions

provider::framework::example("hi")
invalid::namespaced::function("bye")
19 changes: 19 additions & 0 deletions tests/snapshot/terraform/expressions_functions.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,23 @@
# ^^^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl
# ^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.end.hcl
>
># provider defined functions
#^ source.hcl.terraform comment.line.number-sign.hcl punctuation.definition.comment.hcl
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl.terraform comment.line.number-sign.hcl
>
>provider::framework::example("hi")
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl.terraform meta.function-call.hcl support.function.provider
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.begin.hcl
# ^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl
# ^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.end.hcl
>invalid::namespaced::function("bye")
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl.terraform meta.function-call.hcl
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.begin.hcl
# ^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl
# ^ source.hcl.terraform meta.function-call.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.end.hcl
>
Loading