@@ -29,7 +29,7 @@ variables:
29
29
# Identifiers: (UTF-8) (ID_Continue | '-')*;
30
30
#
31
31
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#identifiers
32
- identifer : \b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b
32
+ identifer : (?: \b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b)
33
33
34
34
# Exponent: "e" or "E" followed by an optional sign
35
35
#
@@ -208,15 +208,17 @@ contexts:
208
208
- match : ' "'
209
209
comment : Strings
210
210
scope : punctuation.definition.string.begin.terraform
211
- push :
212
- - meta_scope : meta.string.terraform string.quoted.double.terraform
213
- - match : ' "'
214
- scope : punctuation.definition.string.end.terraform
215
- pop : true
216
- - include : string_interpolation
217
- - match : ' {{char_escapes}}'
218
- comment : Character Escapes
219
- scope : constant.character.escape.terraform
211
+ push : string_body
212
+
213
+ string_body :
214
+ - meta_scope : meta.string.terraform string.quoted.double.terraform
215
+ - match : ' "'
216
+ scope : punctuation.definition.string.end.terraform
217
+ pop : true
218
+ - include : string_interpolation
219
+ - match : ' {{char_escapes}}'
220
+ comment : Character Escapes
221
+ scope : constant.character.escape.terraform
220
222
221
223
# String Interpolation: ("${" | "${~") Expression ("}" | "~}"
222
224
#
@@ -226,19 +228,21 @@ contexts:
226
228
captures :
227
229
1 : punctuation.section.interpolation.begin.terraform
228
230
2 : keyword.operator.template.trim.left.terraform
229
- push :
230
- - meta_scope : meta.interpolation.terraform
231
- - meta_content_scope : source.terraform
232
- - clear_scopes : 1 # Clear the string.* scope.
233
- - match : (~)?(\})
234
- captures :
235
- 1 : keyword.operator.template.trim.right.terraform
236
- 2 : punctuation.section.interpolation.end.terraform
237
- pop : true
238
- - match : \b(if|else|endif|for|in|endfor)\b
239
- comment : if/else/endif and for/in/endfor directives
240
- scope : keyword.control.terraform
241
- - include : expressions
231
+ push : string_interpolation_body
232
+
233
+ string_interpolation_body :
234
+ - meta_scope : meta.interpolation.terraform
235
+ - meta_content_scope : source.terraform
236
+ - clear_scopes : 1 # Clear the string.* scope.
237
+ - match : (~)?(\})
238
+ captures :
239
+ 1 : keyword.operator.template.trim.right.terraform
240
+ 2 : punctuation.section.interpolation.end.terraform
241
+ pop : true
242
+ - match : \b(if|else|endif|for|in|endfor)\b
243
+ comment : if/else/endif and for/in/endfor directives
244
+ scope : keyword.control.terraform
245
+ - include : expressions
242
246
243
247
# String Heredocs
244
248
#
@@ -353,43 +357,54 @@ contexts:
353
357
objects :
354
358
- match : \{
355
359
scope : punctuation.section.braces.begin.terraform
360
+ push : object_body
361
+
362
+ object_body :
363
+ - meta_scope : meta.braces.terraform
364
+ - match : \}
365
+ scope : punctuation.section.braces.end.terraform
366
+ pop : true
367
+ - include : object_for_expression
368
+ - include : comments
369
+ - match : (?=({{identifer}}|\".*?\")\s*=)
356
370
push :
357
- - meta_scope : meta.braces.terraform
358
- - match : \}
359
- scope : punctuation.section.braces.end.terraform
360
- pop : true
361
- - include : object_for_expression
362
- - include : comments
363
- - match : ' \s*({{identifer}})\s*(\=)\s*'
364
- comment : Literal, named object key
371
+ - object_value
372
+ - assignment_operator
373
+ - object_key
374
+ - match : \(
375
+ comment : Computed object key (any expression between parens)
376
+ scope : punctuation.section.parens.begin.terraform
377
+ push :
378
+ - meta_scope : meta.mapping.key.terraform
379
+ - match : ' (\))\s*(\=)\s*'
365
380
captures :
366
- 1 : meta.mapping.key.terraform string.unquoted .terraform
381
+ 1 : punctuation.section.parens.end .terraform
367
382
2 : keyword.operator.terraform
368
- push : object_key_values
369
- - match : ' ((\").*(\"))\s*(\=)\s* '
370
- comment : String object key
371
- captures :
372
- 1 : meta.mapping.key.terraform string.quoted.double.terraform
373
- 2 : punctuation.definition. string.begin .terraform
374
- 3 : punctuation.definition.string.end.terraform
375
- 4 : keyword.operator.terraform
376
- push : object_key_values
377
- - match : \(
378
- comment : Computed object key (any expression between parens)
379
- scope : punctuation.section.parens.begin .terraform
380
- push :
381
- - meta_scope : meta.mapping.key.terraform
382
- - match : ' (\))\s*(\=)\s* '
383
- captures :
384
- 1 : punctuation.section.parens.end.terraform
385
- 2 : keyword.operator.terraform
386
- set : object_key_values
387
- - include : expressions
383
+ set : object_value
384
+ - include : expressions
385
+
386
+ object_key :
387
+ - match : ' {{identifer}} '
388
+ scope : meta.mapping.key.terraform string.unquoted .terraform
389
+ pop : true
390
+ - match : (\").*?(\")
391
+ scope : meta.mapping.key.terraform string.quoted.double.terraform
392
+ captures :
393
+ 1 : punctuation.definition.string.begin.terraform
394
+ 2 : punctuation.definition.string.end .terraform
395
+ pop : true
396
+ - include : else_pop
397
+
398
+ assignment_operator :
399
+ - match : =
400
+ scope : keyword.operator.assignment .terraform
401
+ pop : true
402
+ - include : else_pop
388
403
389
404
# Object key values: pop at comma, newline, and closing-bracket
390
405
#
391
406
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#collection-values
392
- object_key_values :
407
+ object_value :
393
408
- include : comments
394
409
- include : expressions
395
410
- match : \,
@@ -431,14 +446,33 @@ contexts:
431
446
#
432
447
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#attribute-definitions
433
448
attribute_definition :
434
- - match : (\()?({{identifer}})(\))?\s*(\=[^\=|\>])\s*
435
- comment : Identifier "=" with optional parens
436
- scope : variable.declaration.terraform
437
- captures :
438
- 1 : punctuation.section.parens.begin.terraform
439
- 2 : variable.other.readwrite.terraform
440
- 3 : punctuation.section.parens.end.terraform
441
- 4 : keyword.operator.assignment.terraform
449
+ - match : (?=(\()?({{identifer}})(\))?\s*(\=(?![\=\>])))
450
+ push :
451
+ - assignment_operator
452
+ - attribute_key
453
+
454
+ attribute_key :
455
+ - match : \((?={{identifer}}\))
456
+ scope : punctuation.section.parens.begin.terraform
457
+ set :
458
+ - attribute_key_end
459
+ - attribute_key
460
+ # https://developer.hashicorp.com/terraform/language/meta-arguments/for_each
461
+ - match : for_each\b
462
+ scope : variable.declaration.terraform keyword.control.loop.for.terraform
463
+ pop : true
464
+ # https://developer.hashicorp.com/terraform/language/meta-arguments/count
465
+ - match : count\b
466
+ scope : variable.declaration.terraform keyword.control.conditional.terraform
467
+ pop : true
468
+ - match : ' {{identifer}}'
469
+ scope : variable.declaration.terraform variable.other.readwrite.terraform
470
+ pop : true
471
+
472
+ attribute_key_end :
473
+ - match : \)
474
+ scope : punctuation.section.parens.end.terraform
475
+ pop : true
442
476
443
477
# Functions: Terraform builtins and unknown
444
478
#
@@ -521,24 +555,32 @@ contexts:
521
555
captures :
522
556
1 : keyword.declaration.terraform
523
557
2 : entity.name.type.terraform
524
- push :
525
- - meta_scope : meta.type.terraform
526
- - match : \"
527
- comment : String literal label
528
- scope : punctuation.definition.string.begin.terraform
529
- push :
530
- - meta_scope : string.quoted.double.terraform
531
- - match : \"
532
- scope : punctuation.definition.string.end.terraform
533
- pop : true
534
- - match : " {{identifer}}"
535
- comment : Identifer label
536
- scope : entity.name.label.terraform
537
- - match : \{
538
- scope : punctuation.section.block.begin.terraform
539
- set :
540
- - meta_scope : meta.block.terraform
541
- - include : main
542
- - match : \}
543
- scope : punctuation.section.block.end.terraform
544
- pop : true
558
+ push : block_name
559
+
560
+ block_name :
561
+ - meta_scope : meta.type.terraform
562
+ - match : \"
563
+ scope : punctuation.definition.string.begin.terraform
564
+ push : block_name_body
565
+ - match : " {{identifer}}"
566
+ scope : entity.name.label.terraform
567
+ - match : \{
568
+ scope : punctuation.section.block.begin.terraform
569
+ set : block_body
570
+
571
+ block_name_body :
572
+ - meta_scope : string.quoted.double.terraform
573
+ - match : \"
574
+ scope : punctuation.definition.string.end.terraform
575
+ pop : true
576
+
577
+ block_body :
578
+ - meta_scope : meta.block.terraform
579
+ - include : main
580
+ - match : \}
581
+ scope : punctuation.section.block.end.terraform
582
+ pop : true
583
+
584
+ else_pop :
585
+ - match : (?=\S)
586
+ pop : true
0 commit comments