Skip to content

Commit

Permalink
Reorganize built-in function list
Browse files Browse the repository at this point in the history
  • Loading branch information
FichteFoll committed Jul 30, 2024
1 parent 6a20313 commit 27a2468
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
42 changes: 36 additions & 6 deletions Terraform.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,38 @@ variables:

# Built-In Functions
#
# https://www.terraform.io/docs/language/functions/index.html
predeclared_funcs: abs|ceil|floor|log|max|min|pow|signum|chomp|format|formatlist|indent|join|lower|regex|regexall|replace|split|strrev|substr|title|trimspace|upper|chunklist|coalesce|coalescelist|compact|concat|contains|distinct|element|flatten|index|keys|length|list|lookup|map|matchkeys|merge|range|reverse|setintersection|setproduct|setunion|slice|sort|transpose|values|zipmap|base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|urlencode|yamldecode|yamlencode|abspath|dirname|pathexpand|basename|file|fileexists|fileset|filebase64|templatefile|formatdate|timeadd|timestamp|base64sha256|base64sha512|bcrypt|filebase64sha256|filebase64sha512|filemd5|filemd1|filesha256|filesha512|md5|rsadecrypt|sha1|sha256|sha512|uuid|uuidv5|cidrhost|cidrnetmask|cidrsubnet|tobool|tolist|tomap|tonumber|toset|tostring
# https://developer.hashicorp.com/terraform/language/functions
predeclared_funcs: |-
\b(?x:
# numbers
abs|ceil|floor|log|max|min|parseint|pow|signum
# string
|chomp|endswith|format|formatlist|indent|join|lower|regex|regexall|replace
|split|startswith|strcontains|strrev|substr
|templatestring|title|trim|trimprefix|trimsuffix|trimspace|upper
# collection
|alltrue|anytrue|chunklist|coalesce|coalescelist|compact|concat|contains
|distinct|element|flatten|index|keys|length|list|lookup
|map|matchkeys|merge|one|range|reverse
|setintersection|setproduct|setsubtract|setunion|slice|sort|sum
|transpose|values|zipmap
# encoding
|base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|textdecodebase64|textencodebase64|urlencode|yamldecode|yamlencode
# filesystem
|abspath|dirname|pathexpand|basename|file|fileexists|fileset|filebase64|templatefile
# date and time
|formatdate|plantimestamp|timeadd|timecmp|timestamp
# hash and crypto
|base64sha256|base64sha512|bcrypt|filebase64sha256|filebase64sha512|filemd5|filesha1|filesha256|filesha512|md5|rsadecrypt|sha1|sha256|sha512|uuid|uuidv5
# ip network
|cidrhost|cidrnetmask|cidrsubnet|cidrsubnets
# type conversion
|can|issensitive|nonsensitive|sensitive|tobool|tolist|tomap|tonumber|toset|tostring|try|type
# terraform-specific
|provider::terraform::(?:encode_tfvars|decode_tfvars|encode_expr)
# deprecated/old
|filemd1
)\b
contexts:
main:
Expand Down Expand Up @@ -479,12 +509,12 @@ contexts:
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#functions-and-function-calls
# https://www.terraform.io/docs/language/expressions/function-calls.html
functions:
- match: (({{predeclared_funcs}})|\b({{identifer}})\b)(\()
- match: (?:({{predeclared_funcs}})|\b({{identifer}})\b)(\()
comment: Built-in function calls
captures:
2: support.function.builtin.terraform
3: variable.function.terraform
4: punctuation.section.parens.begin.terraform
1: support.function.builtin.terraform
2: variable.function.terraform
3: punctuation.section.parens.begin.terraform
push:
- meta_scope: meta.function-call.terraform
- match: \)
Expand Down
9 changes: 9 additions & 0 deletions syntax_test_terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,15 @@
# ^^^^^^ meta.function-call.terraform string.quoted.double.terraform
# ^ meta.function-call.terraform punctuation.section.parens.end.terraform


provider::terraform::encode_tfvars({
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.terraform
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ support.function.builtin.terraform
# ^ punctuation.section.parens.begin.terraform
# ^ meta.braces.terraform punctuation.section.braces.begin.terraform
example = "Hello!"
})

/////////////////////////////////////////////////////////////////////
// TUPLE FOR-EXPRESSIONS
/////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 27a2468

Please sign in to comment.