Skip to content

Commit c1bcc4f

Browse files
authored
Merge pull request #60 from SublimeText/bugfix/hypenated-identifiers
Some fixes to identifiers (e.g. hyphens)
2 parents a923e44 + 06db312 commit c1bcc4f

File tree

3 files changed

+80
-44
lines changed

3 files changed

+80
-44
lines changed

Terraform.sublime-settings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"tab_size": 2,
3-
"translate_tabs_to_spaces": true
3+
"translate_tabs_to_spaces": true,
4+
// Move '-' to sub-word separators
5+
"word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}`~?",
6+
"sub_word_separators": "_-",
47
}

Terraform.sublime-syntax

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variables:
2929
# Identifiers: (UTF-8) (ID_Continue | '-')*;
3030
#
3131
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#identifiers
32-
identifer: (?:\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b)
32+
identifier: (?:\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b)
3333

3434
# Exponent: "e" or "E" followed by an optional sign
3535
#
@@ -123,13 +123,14 @@ contexts:
123123
#
124124
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#expression-terms
125125
expressions:
126-
- include: literal_values
126+
- include: literals
127127
- include: operators
128128
- include: brackets
129129
- include: objects
130130
- include: attribute_access
131131
- include: functions
132132
- include: parens
133+
- include: identifiers
133134

134135
comma:
135136
- match: \,
@@ -145,17 +146,14 @@ contexts:
145146
scope: punctuation.section.parens.end.terraform
146147
pop: true
147148
- include: expressions
148-
- match: "{{identifer}}"
149-
comment: Local Identifiers
150-
scope: variable.other.readwrite.terraform
151149

152150
# Literal Values: Numbers, Language Constants, and Strings
153151
#
154152
# Strings are _technically_ part of the "expression sub-language",
155153
# but make the most sense to be part of this stack.
156154
#
157155
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#literal-values
158-
literal_values:
156+
literals:
159157
- include: numeric_literals
160158
- include: language_constants
161159
- include: string_literals
@@ -181,11 +179,13 @@ contexts:
181179
- match: '#|//'
182180
comment: Inline Comments
183181
scope: punctuation.definition.comment.terraform
184-
push:
185-
- meta_scope: comment.line.terraform
186-
- match: $\n?
187-
scope: punctuation.definition.comment.terraform
188-
pop: true
182+
push: inline_comment_body
183+
184+
inline_comment_body:
185+
- meta_scope: comment.line.terraform
186+
- match: $\n?
187+
scope: punctuation.definition.comment.terraform
188+
pop: true
189189

190190
# Block comments: start and end delimiters for multi-line comments.
191191
#
@@ -195,11 +195,13 @@ contexts:
195195
- match: /\*
196196
comment: Block comments
197197
scope: punctuation.definition.comment.terraform
198-
push:
199-
- meta_scope: comment.block.terraform
200-
- match: \*/
201-
scope: punctuation.definition.comment.terraform
202-
pop: true
198+
push: block_comments_body
199+
200+
block_comments_body:
201+
- meta_scope: comment.block.terraform
202+
- match: \*/
203+
scope: punctuation.definition.comment.terraform
204+
pop: true
203205

204206
# Language Constants: booleans and `null`.
205207
#
@@ -278,7 +280,7 @@ contexts:
278280
#
279281
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#template-expressions
280282
heredoc:
281-
- match: (\<\<\-?)\s*({{identifer}})\s*$
283+
- match: (\<\<\-?)\s*({{identifier}})\s*$
282284
comment: String Heredoc's
283285
captures:
284286
1: keyword.operator.heredoc.terraform
@@ -349,8 +351,8 @@ contexts:
349351
- match: \"
350352
scope: punctuation.definition.string.end.terraform
351353
pop: true
352-
- match: "{{identifer}}"
353-
comment: Identifer label
354+
- match: "{{identifier}}"
355+
comment: Identifier label
354356
scope: entity.name.label.terraform
355357
- include: numeric_literals
356358
- include: attribute_access
@@ -376,8 +378,8 @@ contexts:
376378
pop: true
377379
- include: comma
378380
- include: comments
379-
- include: expressions
380381
- include: tuple_for_expression
382+
- include: expressions
381383

382384
# Objects: collection values
383385
#
@@ -396,7 +398,7 @@ contexts:
396398
pop: true
397399
- include: object_for_expression
398400
- include: comments
399-
- match: (?=({{identifer}}|\".*?\")\s*=)
401+
- match: (?=({{identifier}}|\".*?\")\s*=)
400402
push:
401403
- object_value
402404
- assignment_operator
@@ -414,7 +416,7 @@ contexts:
414416
- include: expressions
415417

416418
object_key:
417-
- match: '{{identifer}}'
419+
- match: '{{identifier}}'
418420
scope: meta.mapping.key.terraform string.unquoted.terraform
419421
pop: true
420422
- match: (\").*?(\")
@@ -455,19 +457,23 @@ contexts:
455457
attribute_access:
456458
- match: \.
457459
scope: punctuation.accessor.dot.terraform
458-
push:
459-
- match: "{{identifer}}"
460-
comment: Attribute access
461-
scope: variable.other.member.terraform
462-
pop: true
463-
- match: \d+
464-
comment: Subscript
465-
scope: constant.numeric.integer.terraform
466-
pop: true
467-
- match: \*
468-
comment: Attribute-only splat
469-
scope: keyword.operator.splat.terraform
470-
pop: true
460+
push: member
461+
462+
member:
463+
- include: comments
464+
- match: "{{identifier}}"
465+
comment: Attribute access
466+
scope: variable.other.member.terraform
467+
pop: true
468+
- match: \d+
469+
comment: Subscript
470+
scope: constant.numeric.integer.terraform
471+
pop: true
472+
- match: \*
473+
comment: Attribute-only splat
474+
scope: keyword.operator.splat.terraform
475+
pop: true
476+
- include: else_pop
471477

472478
# Attribute Definition: Identifier "=" Expression Newline
473479
#
@@ -476,13 +482,13 @@ contexts:
476482
#
477483
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#attribute-definitions
478484
attribute_definition:
479-
- match: (?=(\()?({{identifer}})(\))?\s*(\=(?![\=\>])))
485+
- match: (?=(\()?({{identifier}})(\))?\s*(\=(?![\=\>])))
480486
push:
481487
- assignment_operator
482488
- attribute_key
483489

484490
attribute_key:
485-
- match: \((?={{identifer}}\))
491+
- match: \((?={{identifier}}\))
486492
scope: punctuation.section.parens.begin.terraform
487493
set:
488494
- attribute_key_end
@@ -495,7 +501,7 @@ contexts:
495501
- match: count\b
496502
scope: variable.declaration.terraform keyword.control.conditional.terraform
497503
pop: true
498-
- match: '{{identifer}}'
504+
- match: '{{identifier}}'
499505
scope: variable.declaration.terraform variable.other.readwrite.terraform
500506
pop: true
501507

@@ -509,7 +515,7 @@ contexts:
509515
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#functions-and-function-calls
510516
# https://www.terraform.io/docs/language/expressions/function-calls.html
511517
functions:
512-
- match: (?:({{predeclared_funcs}})|\b({{identifer}})\b)(\()
518+
- match: (?:({{predeclared_funcs}})|\b({{identifier}})\b)(\()
513519
comment: Built-in function calls
514520
captures:
515521
1: support.function.builtin.terraform
@@ -573,15 +579,16 @@ contexts:
573579
- include: expressions
574580
- include: comments
575581
- include: comma
576-
- match: "{{identifer}}"
577-
comment: Local Identifiers
582+
583+
identifiers:
584+
- match: "{{identifier}}"
578585
scope: variable.other.readwrite.terraform
579586

580587
# Blocks: Identifier (StringLit|Identifier)* "{" Newline Body "}" Newline;
581588
#
582589
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#structural-elements
583590
block:
584-
- match: (?:\b({{terraform_known_blocks}})\b|({{identifer}}))(?=[\s\"\-[:word:]]*(\{))
591+
- match: (?:\b({{terraform_known_blocks}})\b|({{identifier}}))(?=[\s\"\-[:word:]]*(\{))
585592
captures:
586593
1: keyword.declaration.terraform
587594
2: entity.name.type.terraform
@@ -592,7 +599,7 @@ contexts:
592599
- match: \"
593600
scope: punctuation.definition.string.begin.terraform
594601
push: block_name_body
595-
- match: "{{identifer}}"
602+
- match: "{{identifier}}"
596603
scope: entity.name.label.terraform
597604
- match: \{
598605
scope: punctuation.section.block.begin.terraform

syntax_test_terraform.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@
259259
# ^^^^^^^^^^ constant.character.escape.terraform
260260
# ^ punctuation.definition.string.end.terraform
261261

262+
/////////////////////////////////////////////////////////////////////
263+
// Identifiers
264+
/////////////////////////////////////////////////////////////////////
265+
266+
this_is_an_identifier
267+
# ^^^^^^^^^^^^^^^^^^^^^ variable.other.readwrite.terraform
268+
269+
identifier.member_access
270+
# ^^^^^^^^^^ variable.other.readwrite.terraform
271+
# ^ punctuation.accessor.dot.terraform
272+
# ^^^^^^^^^^^^^ variable.other.member.terraform
273+
274+
identifier-with-hyphens
275+
# ^^^^^^^^^^^^^^^^^^^^^^^ variable.other.readwrite.terraform
276+
277+
identifier.
278+
// comment
279+
# <- comment
280+
262281
/////////////////////////////////////////////////////////////////////
263282
// STRING INTERPOLATION
264283
/////////////////////////////////////////////////////////////////////
@@ -1119,6 +1138,13 @@
11191138
# ^ punctuation.definition.string.begin.terraform
11201139
# ^ punctuation.definition.string.end.terraform
11211140

1141+
provider = google-beta.impersonated
1142+
# ^^^^^^^^ variable.declaration.terraform variable.other.readwrite.terraform
1143+
# ^ keyword.operator.assignment.terraform
1144+
# ^^^^^^^^^^^ variable.other.readwrite.terraform
1145+
# ^ punctuation.accessor.dot.terraform
1146+
# ^^^^^^^^^^^^ variable.other.member.terraform
1147+
11221148

11231149
/////
11241150
// Meta-arguments

0 commit comments

Comments
 (0)