Skip to content

Commit

Permalink
Improved string interpolation support - highlighting builtin terrafor…
Browse files Browse the repository at this point in the history
…m functions e.g. file/replace. Should fix #21
  • Loading branch information
alexlouden committed Mar 30, 2017
1 parent d071ff7 commit bf59106
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 70 deletions.
41 changes: 21 additions & 20 deletions Terraform.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ repository:
- match: ([\w-\/\._\\%]+)
name: "string.quoted.double.terraform"

string_interpolation_functions:
comment: Builtin functions
begin: (replace|base64decode|base64encode|base64sha256|ceil|cidrnetmask|compact|distinct|file|floor|keys|length|lower|md5|pathexpand|replace|sha1|sha256|signum|sort|timestamp|title|trimspace|upper|uuid|values|cidrhost|cidrsubnet|coalesce|concat|element|format|formatlist|from|index|join|jsonencode|length|list|lookup|map|max|merge|min|slice|split|substr|zipmap)(\()
beginCaptures:
'1': {name: keyword.other.function.inline.terraform}
'2': {name: keyword.other.section.begin.terraform}
end: (\))
endCaptures:
'1': {name: keyword.other.section.end.terraform}
patterns:
- include: '$self'
- include: '#string_interpolation_keywords'

string_interpolation_keywords:
match: (terraform|var|self|count|module|path|data)(\.[\w\*]+)+
captures:
'0': {name: entity.other.attribute-name.terraform}

string_interpolation:
patterns:
- name: source.terraform.embedded.source
Expand All @@ -113,29 +131,12 @@ repository:
'0': {name: entity.tag.embedded.end.terraform}
patterns:
- include: '$self'

- include: '#string_interpolation_functions'
- include: '#string_interpolation_keywords'
- match: (\.)
captures:
'0': {name: keyword.control.period.terraform}

- begin: (replace|base64decode|base64encode|base64sha256|ceil|cidrnetmask|compact|distinct|file|floor|keys|length|lower|md5|pathexpand|replace|sha1|sha256|signum|sort|timestamp|title|trimspace|upper|uuid|values)(\()
comment: Builtin functions
beginCaptures:
'1': {name: keyword.other.function.inline.terraform}
'2': {name: keyword.other.section.begin.terraform}
end: (\))
endCaptures:
'1': {name: keyword.other.section.end.terraform}
patterns:
- include: '#string_interpolation'

# TODO handle functions with multiple arguments

- include: '#strings'

- match: (terraform|var|self|count|module|path|data)(\.[\w\*]+)+
captures:
'0': {name: entity.other.attribute-name.terraform}
- include: '#strings'


# TODO terraform configuration blocks
Expand Down
114 changes: 64 additions & 50 deletions Terraform.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -298,73 +298,87 @@
<string>$self</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.period.terraform</string>
</dict>
</dict>
<key>match</key>
<string>(\.)</string>
<key>include</key>
<string>#string_interpolation_functions</string>
</dict>
<dict>
<key>begin</key>
<string>(replace|base64decode|base64encode|base64sha256|ceil|cidrnetmask|compact|distinct|file|floor|keys|length|lower|md5|pathexpand|replace|sha1|sha256|signum|sort|timestamp|title|trimspace|upper|uuid|values)(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.function.inline.terraform</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.other.section.begin.terraform</string>
</dict>
</dict>
<key>comment</key>
<string>Builtin functions</string>
<key>end</key>
<string>(\))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.section.end.terraform</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#string_interpolation</string>
</dict>
<dict>
<key>include</key>
<string>#strings</string>
</dict>
</array>
<key>include</key>
<string>#string_interpolation_keywords</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>entity.other.attribute-name.terraform</string>
<string>keyword.control.period.terraform</string>
</dict>
</dict>
<key>match</key>
<string>(terraform|var|self|count|module|path|data)(\.[\w\*]+)+</string>
<string>(\.)</string>
</dict>
<dict>
<key>include</key>
<string>#strings</string>
</dict>
</array>
</dict>
</array>
</dict>
<key>string_interpolation_functions</key>
<dict>
<key>begin</key>
<string>(replace|base64decode|base64encode|base64sha256|ceil|cidrnetmask|compact|distinct|file|floor|keys|length|lower|md5|pathexpand|replace|sha1|sha256|signum|sort|timestamp|title|trimspace|upper|uuid|values|cidrhost|cidrsubnet|coalesce|concat|element|format|formatlist|from|index|join|jsonencode|length|list|lookup|map|max|merge|min|slice|split|substr|zipmap)(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.function.inline.terraform</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.other.section.begin.terraform</string>
</dict>
</dict>
<key>comment</key>
<string>Builtin functions</string>
<key>end</key>
<string>(\))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.section.end.terraform</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
<dict>
<key>include</key>
<string>#string_interpolation_keywords</string>
</dict>
</array>
</dict>
<key>string_interpolation_keywords</key>
<dict>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>entity.other.attribute-name.terraform</string>
</dict>
</dict>
<key>match</key>
<string>(terraform|var|self|count|module|path|data)(\.[\w\*]+)+</string>
</dict>
<key>strings</key>
<dict>
<key>begin</key>
Expand Down

0 comments on commit bf59106

Please sign in to comment.