Skip to content

Commit c97082b

Browse files
authored
Impove function-call syntax (#83)
This commit... 1. scopes namespaces in function calls `variable.namespace` 2. adds more detailed `meta.function-call.[identifier|arguments]` scopes. 3. adjusts tests accordingly 4. reformats list of built-in functions
1 parent f6d5997 commit c97082b

File tree

2 files changed

+1207
-1137
lines changed

2 files changed

+1207
-1137
lines changed

Terraform.sublime-syntax

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,43 @@ variables:
8383
# Built-In Functions
8484
#
8585
# https://developer.hashicorp.com/terraform/language/functions
86-
predeclared_funcs: |-
87-
\b(?x:
88-
# numbers
89-
abs|ceil|floor|log|max|min|parseint|pow|signum
90-
# string
91-
|chomp|endswith|format|formatlist|indent|join|lower|regex|regexall|replace
92-
|split|startswith|strcontains|strrev|substr
93-
|templatestring|title|trim|trimprefix|trimsuffix|trimspace|upper
94-
# collection
95-
|alltrue|anytrue|chunklist|coalesce|coalescelist|compact|concat|contains
96-
|distinct|element|flatten|index|keys|length|list|lookup
97-
|map|matchkeys|merge|one|range|reverse
98-
|setintersection|setproduct|setsubtract|setunion|slice|sort|sum
99-
|transpose|values|zipmap
100-
# encoding
101-
|base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|textdecodebase64|textencodebase64|urlencode|yamldecode|yamlencode
102-
# filesystem
103-
|abspath|dirname|pathexpand|basename|file|fileexists|fileset|filebase64|templatefile
104-
# date and time
105-
|formatdate|plantimestamp|timeadd|timecmp|timestamp
106-
# hash and crypto
107-
|base64sha256|base64sha512|bcrypt|filebase64sha256|filebase64sha512|filemd5|filesha1|filesha256|filesha512|md5|rsadecrypt|sha1|sha256|sha512|uuid|uuidv5
108-
# ip network
109-
|cidrhost|cidrnetmask|cidrsubnet|cidrsubnets
110-
# type conversion
111-
|can|issensitive|nonsensitive|sensitive|tobool|tolist|tomap|tonumber|toset|tostring|try|type
112-
# terraform-specific
113-
|provider::terraform::(?:encode_tfvars|decode_tfvars|encode_expr)
114-
# deprecated/old
115-
|filemd1
116-
)\b
86+
builtin_functions: |-
87+
(?x:
88+
# numbers
89+
abs | ceil | floor | log | max | min | parseint | pow | signum
90+
# string
91+
| chomp | endswith | format | formatlist | indent | join | lower | regex
92+
| regexall | replace | split | startswith | strcontains | strrev | substr
93+
| templatestring | title | trim | trimprefix | trimsuffix | trimspace | upper
94+
# collection
95+
| alltrue | anytrue | chunklist | coalesce | coalescelist | compact | concat
96+
| contains | distinct | element | flatten | index | keys | length | list
97+
| lookup | map | matchkeys | merge | one | range | reverse | setintersection
98+
| setproduct | setsubtract | setunion | slice | sort | sum | transpose
99+
| values | zipmap
100+
# encoding
101+
| base64decode | base64encode | base64gzip | csvdecode | jsondecode
102+
| jsonencode | textdecodebase64 | textencodebase64 | urlencode | yamldecode
103+
| yamlencode
104+
# filesystem
105+
| abspath | dirname | pathexpand | basename | file | fileexists | fileset
106+
| filebase64 | templatefile
107+
# date and time
108+
| formatdate | plantimestamp | timeadd | timecmp | timestamp
109+
# hash and crypto
110+
| base64sha256 | base64sha512 | bcrypt | filebase64sha256
111+
| filebase64sha512 | filemd5 | filesha1 | filesha256 | filesha512 | md5
112+
| rsadecrypt | sha1 | sha256 | sha512 | uuid | uuidv5
113+
# ip network
114+
| cidrhost | cidrnetmask | cidrsubnet | cidrsubnets
115+
# type conversion
116+
| can | issensitive | nonsensitive | sensitive | tobool | tolist | tomap
117+
| tonumber | toset | tostring | try | type
118+
# terraform-specific
119+
| provider::terraform::(?:encode_tfvars | decode_tfvars | encode_expr)
120+
# deprecated/old
121+
| filemd1
122+
)
117123
118124
contexts:
119125
main:
@@ -593,16 +599,32 @@ contexts:
593599
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#functions-and-function-calls
594600
# https://www.terraform.io/docs/language/expressions/function-calls.html
595601
functions:
596-
- match: (?:({{predeclared_funcs}})|\b({{identifier}})\b)(\()
597-
comment: Built-in function calls
598-
captures:
599-
1: support.function.builtin.terraform
600-
2: variable.function.terraform
601-
3: punctuation.section.parens.begin.terraform
602-
push: function-argument-list-body
602+
- match: (?={{builtin_functions}}\()
603+
push: builtin-function-name
604+
- match: (?=(?:{{identifier}}::)*{{identifier}}\()
605+
push: other-function-name
606+
607+
builtin-function-name:
608+
- meta_content_scope: meta.function-call.identifier.terraform
609+
- include: function-argument-list
610+
- include: namespaces
611+
- match: '{{identifier}}'
612+
scope: support.function.builtin.terraform
613+
614+
other-function-name:
615+
- meta_content_scope: meta.function-call.identifier.terraform
616+
- include: function-argument-list
617+
- include: namespaces
618+
- match: '{{identifier}}'
619+
scope: variable.function.terraform
620+
621+
function-argument-list:
622+
- match: \(
623+
scope: punctuation.section.parens.begin.terraform
624+
set: function-argument-list-body
603625

604626
function-argument-list-body:
605-
- meta_scope: meta.function-call.terraform
627+
- meta_scope: meta.function-call.arguments.terraform meta.parens.terraform
606628
- match: \)
607629
scope: punctuation.section.parens.end.terraform
608630
pop: 1
@@ -664,6 +686,12 @@ contexts:
664686
- include: comments
665687
- include: comma
666688

689+
namespaces:
690+
- match: ({{identifier}})(::)
691+
captures:
692+
1: variable.namespace.terraform
693+
2: punctuation.accessor.double-colon.terraform
694+
667695
identifiers:
668696
- match: '{{identifier}}'
669697
scope: variable.other.readwrite.terraform

0 commit comments

Comments
 (0)