Skip to content

Commit

Permalink
Merge pull request #58 from FichteForks/pr/scopes
Browse files Browse the repository at this point in the history
Various scope adjustments to ST Terraform syntax
  • Loading branch information
FichteFoll authored Aug 7, 2024
2 parents 1576c26 + ad9dbf7 commit cff50c9
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 3,240 deletions.
51 changes: 24 additions & 27 deletions Terraform.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ name: Terraform
# https://www.terraform.io/docs/language/index.html
file_extensions:
- tf
- hcl
- nomad

scope: source.terraform
Expand Down Expand Up @@ -136,8 +135,8 @@ contexts:

named_value_references:
- match: '\b({{named_values}})\b'
comment: Constant values available only to Terraform.
scope: support.constant.terraform
comment: Special variables available only to Terraform.
scope: variable.language.terraform

type_keywords:
- match: '\b({{terraform_type_keywords}})\b'
Expand Down Expand Up @@ -210,7 +209,7 @@ contexts:
comment: Strings
scope: punctuation.definition.string.begin.terraform
push:
- meta_scope: string.quoted.double.terraform
- meta_scope: meta.string.terraform string.quoted.double.terraform
- match: '"'
scope: punctuation.definition.string.end.terraform
pop: true
Expand All @@ -223,21 +222,19 @@ contexts:
#
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#templates
string_interpolation:
- match: (\$|\%)\{
comment: String interpolation
scope: keyword.other.interpolation.begin.terraform
- match: ([$%]\{)(~)?
captures:
1: punctuation.section.interpolation.begin.terraform
2: keyword.operator.template.trim.left.terraform
push:
- meta_scope: meta.interpolation.terraform
- clear_scopes: 1 # Clear the string.* scope.
- match: \}
scope: keyword.other.interpolation.end.terraform
- meta_content_scope: source.terraform
- clear_scopes: 1 # Clear the string.* scope.
- match: (~)?(\})
captures:
1: keyword.operator.template.trim.right.terraform
2: punctuation.section.interpolation.end.terraform
pop: true
- match: \~\s
comment: Trim left whitespace
scope: keyword.operator.template.left.trim.terraform
- match: \s\~
comment: Trim right whitespace
scope: keyword.operator.template.right.trim.terraform
- match: \b(if|else|endif|for|in|endfor)\b
comment: if/else/endif and for/in/endfor directives
scope: keyword.control.terraform
Expand All @@ -253,7 +250,7 @@ contexts:
1: keyword.operator.heredoc.terraform
2: keyword.control.heredoc.terraform
push:
- meta_content_scope: string.unquoted.heredoc.terraform
- meta_content_scope: meta.string.terraform string.unquoted.heredoc.terraform
- match: ^\s*\2\s*$
comment: The heredoc token identifier (second capture above).
scope: keyword.control.heredoc.terraform
Expand Down Expand Up @@ -297,7 +294,7 @@ contexts:
scope: keyword.operator.terraform
- match: \.\.\. # ...
scope: keyword.operator.terraform
- match: "\\:" # :
- match: ':' # :
scope: keyword.operator.terraform

# Terraform "import" statements
Expand Down Expand Up @@ -412,7 +409,7 @@ contexts:
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#attribute-access-operator
attribute_access:
- match: \.
scope: keyword.operator.accessor.terraform
scope: punctuation.accessor.dot.terraform
push:
- match: "{{identifer}}"
comment: Attribute access
Expand Down Expand Up @@ -472,7 +469,7 @@ contexts:
tuple_for_expression:
- match: \bfor\b
comment: for expression (arrays)
scope: keyword.control.terraform
scope: keyword.control.loop.for.terraform
set:
- include: for_expression_body
- match: \]
Expand All @@ -488,10 +485,10 @@ contexts:
object_for_expression:
- match: \bfor\b
comment: for expression (arrays)
scope: keyword.control.terraform
scope: keyword.control.loop.for.terraform
set:
- match: \=\>
scope: storage.type.function.terraform
scope: punctuation.separator.key-value.terraform
- include: for_expression_body
- match: \}
scope: punctuation.section.braces.end.terraform
Expand All @@ -503,12 +500,12 @@ contexts:
for_expression_body:
- match: \bin\b
comment: in keyword
scope: keyword.operator.word.terraform
scope: keyword.control.loop.in.terraform
- match: \bif\b
comment: if keyword
scope: keyword.control.conditional.terraform
- match: '\:'
scope: keyword.operator.terraform
scope: punctuation.section.block.loop.for.terraform
- include: expressions
- include: comments
- include: comma
Expand All @@ -520,10 +517,10 @@ contexts:
#
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#structural-elements
block:
- match: '(\b({{terraform_known_blocks}})\b|({{identifer}}))(?=[\s\"\-[:word:]]*(\{))'
- match: (?:\b({{terraform_known_blocks}})\b|({{identifer}}))(?=[\s\"\-[:word:]]*(\{))
captures:
2: storage.type.terraform
3: entity.name.type.terraform
1: keyword.declaration.terraform
2: entity.name.type.terraform
push:
- meta_scope: meta.type.terraform
- match: \"
Expand Down
Loading

0 comments on commit cff50c9

Please sign in to comment.