Skip to content

Commit bf59106

Browse files
committed
Improved string interpolation support - highlighting builtin terraform functions e.g. file/replace. Should fix #21
1 parent d071ff7 commit bf59106

File tree

2 files changed

+85
-70
lines changed

2 files changed

+85
-70
lines changed

Terraform.YAML-tmLanguage

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ repository:
102102
- match: ([\w-\/\._\\%]+)
103103
name: "string.quoted.double.terraform"
104104

105+
string_interpolation_functions:
106+
comment: Builtin functions
107+
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)(\()
108+
beginCaptures:
109+
'1': {name: keyword.other.function.inline.terraform}
110+
'2': {name: keyword.other.section.begin.terraform}
111+
end: (\))
112+
endCaptures:
113+
'1': {name: keyword.other.section.end.terraform}
114+
patterns:
115+
- include: '$self'
116+
- include: '#string_interpolation_keywords'
117+
118+
string_interpolation_keywords:
119+
match: (terraform|var|self|count|module|path|data)(\.[\w\*]+)+
120+
captures:
121+
'0': {name: entity.other.attribute-name.terraform}
122+
105123
string_interpolation:
106124
patterns:
107125
- name: source.terraform.embedded.source
@@ -113,29 +131,12 @@ repository:
113131
'0': {name: entity.tag.embedded.end.terraform}
114132
patterns:
115133
- include: '$self'
116-
134+
- include: '#string_interpolation_functions'
135+
- include: '#string_interpolation_keywords'
117136
- match: (\.)
118137
captures:
119138
'0': {name: keyword.control.period.terraform}
120-
121-
- 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)(\()
122-
comment: Builtin functions
123-
beginCaptures:
124-
'1': {name: keyword.other.function.inline.terraform}
125-
'2': {name: keyword.other.section.begin.terraform}
126-
end: (\))
127-
endCaptures:
128-
'1': {name: keyword.other.section.end.terraform}
129-
patterns:
130-
- include: '#string_interpolation'
131-
132-
# TODO handle functions with multiple arguments
133-
134-
- include: '#strings'
135-
136-
- match: (terraform|var|self|count|module|path|data)(\.[\w\*]+)+
137-
captures:
138-
'0': {name: entity.other.attribute-name.terraform}
139+
- include: '#strings'
139140

140141

141142
# TODO terraform configuration blocks

Terraform.tmLanguage

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -298,73 +298,87 @@
298298
<string>$self</string>
299299
</dict>
300300
<dict>
301-
<key>captures</key>
302-
<dict>
303-
<key>0</key>
304-
<dict>
305-
<key>name</key>
306-
<string>keyword.control.period.terraform</string>
307-
</dict>
308-
</dict>
309-
<key>match</key>
310-
<string>(\.)</string>
301+
<key>include</key>
302+
<string>#string_interpolation_functions</string>
311303
</dict>
312304
<dict>
313-
<key>begin</key>
314-
<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>
315-
<key>beginCaptures</key>
316-
<dict>
317-
<key>1</key>
318-
<dict>
319-
<key>name</key>
320-
<string>keyword.other.function.inline.terraform</string>
321-
</dict>
322-
<key>2</key>
323-
<dict>
324-
<key>name</key>
325-
<string>keyword.other.section.begin.terraform</string>
326-
</dict>
327-
</dict>
328-
<key>comment</key>
329-
<string>Builtin functions</string>
330-
<key>end</key>
331-
<string>(\))</string>
332-
<key>endCaptures</key>
333-
<dict>
334-
<key>1</key>
335-
<dict>
336-
<key>name</key>
337-
<string>keyword.other.section.end.terraform</string>
338-
</dict>
339-
</dict>
340-
<key>patterns</key>
341-
<array>
342-
<dict>
343-
<key>include</key>
344-
<string>#string_interpolation</string>
345-
</dict>
346-
<dict>
347-
<key>include</key>
348-
<string>#strings</string>
349-
</dict>
350-
</array>
305+
<key>include</key>
306+
<string>#string_interpolation_keywords</string>
351307
</dict>
352308
<dict>
353309
<key>captures</key>
354310
<dict>
355311
<key>0</key>
356312
<dict>
357313
<key>name</key>
358-
<string>entity.other.attribute-name.terraform</string>
314+
<string>keyword.control.period.terraform</string>
359315
</dict>
360316
</dict>
361317
<key>match</key>
362-
<string>(terraform|var|self|count|module|path|data)(\.[\w\*]+)+</string>
318+
<string>(\.)</string>
319+
</dict>
320+
<dict>
321+
<key>include</key>
322+
<string>#strings</string>
363323
</dict>
364324
</array>
365325
</dict>
366326
</array>
367327
</dict>
328+
<key>string_interpolation_functions</key>
329+
<dict>
330+
<key>begin</key>
331+
<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>
332+
<key>beginCaptures</key>
333+
<dict>
334+
<key>1</key>
335+
<dict>
336+
<key>name</key>
337+
<string>keyword.other.function.inline.terraform</string>
338+
</dict>
339+
<key>2</key>
340+
<dict>
341+
<key>name</key>
342+
<string>keyword.other.section.begin.terraform</string>
343+
</dict>
344+
</dict>
345+
<key>comment</key>
346+
<string>Builtin functions</string>
347+
<key>end</key>
348+
<string>(\))</string>
349+
<key>endCaptures</key>
350+
<dict>
351+
<key>1</key>
352+
<dict>
353+
<key>name</key>
354+
<string>keyword.other.section.end.terraform</string>
355+
</dict>
356+
</dict>
357+
<key>patterns</key>
358+
<array>
359+
<dict>
360+
<key>include</key>
361+
<string>$self</string>
362+
</dict>
363+
<dict>
364+
<key>include</key>
365+
<string>#string_interpolation_keywords</string>
366+
</dict>
367+
</array>
368+
</dict>
369+
<key>string_interpolation_keywords</key>
370+
<dict>
371+
<key>captures</key>
372+
<dict>
373+
<key>0</key>
374+
<dict>
375+
<key>name</key>
376+
<string>entity.other.attribute-name.terraform</string>
377+
</dict>
378+
</dict>
379+
<key>match</key>
380+
<string>(terraform|var|self|count|module|path|data)(\.[\w\*]+)+</string>
381+
</dict>
368382
<key>strings</key>
369383
<dict>
370384
<key>begin</key>

0 commit comments

Comments
 (0)