Skip to content

Commit

Permalink
Merge pull request #99 from hashicorp/support-tf-provider-defined-fns
Browse files Browse the repository at this point in the history
feat: support provider defined functions for Terraform HCL
  • Loading branch information
ansgarm authored Feb 22, 2024
2 parents 3b348a4 + b8a932a commit 1141ac7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
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::[[:alpha:]][\w_-]*::[[:alpha:]][\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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
>

0 comments on commit 1141ac7

Please sign in to comment.