Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS blocks #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Terraform.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ contexts:
- match: '{{char_escapes}}'
comment: Character Escapes
scope: constant.character.escape.terraform
- include: aws-acl

# String Interpolation: ("${" | "${~") Expression ("}" | "~}"
#
Expand Down Expand Up @@ -597,6 +598,21 @@ contexts:
#
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#structural-elements
block:
# Special case heuristic for the two-term ones
- match: (\b({{terraform_known_blocks}})\b\s*(")({{identifier}})(")\s*(")({{identifier}})("))\s*(\{)
Comment on lines +601 to +602
Copy link
Contributor Author

@michaelblyons michaelblyons Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceivably, this could even be ratcheted down to

\b(resource)\b\s+(")(aws_{{identifier}})(")\s+(")({{identifier}})("))\s*(\{)

at least in my limited experience.

captures:
1: meta.type.terraform
2: keyword.declaration.terraform
3: punctuation.definition.begin.terraform
4: support.type.terraform
5: punctuation.definition.end.terraform
6: punctuation.definition.begin.terraform
7: entity.name.type.terraform
8: punctuation.definition.end.terraform
9: punctuation.section.block.begin.terraform
push: block_body

# Generic
- match: (?:\b({{terraform_known_blocks}})\b|({{identifier}}))(?=[\s\"\-[:word:]]*(\{))
captures:
1: keyword.declaration.terraform
Expand Down Expand Up @@ -627,6 +643,18 @@ contexts:
scope: punctuation.section.block.end.terraform
pop: true

aws-acl:
- match: (?=\barn:aws:)
push:
- meta_scope: variable.language.acl.terraform
- include: string_interpolation
- match: :|/
scope: punctuation.separator.sequence.terraform
- match: \*
scope: constant.other.wildcard.asterisk.terraform
- match: (?![\w-])
pop: true

else_pop:
- match: (?=\S)
pop: true
11 changes: 11 additions & 0 deletions syntax_test_terraform-vars.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
# ^ punctuation.definition.string.end.terraform
# ^ -punctuation -string

"arn:aws:sns:us-east-1:123456789012:example-sns-topic-name"
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.terraform string.quoted.double.terraform
# ^ punctuation.definition.string.begin.terraform
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language.acl.terraform
# ^ punctuation.separator.sequence.terraform
# ^ punctuation.separator.sequence.terraform
# ^ punctuation.separator.sequence.terraform
# ^ punctuation.separator.sequence.terraform
# ^ punctuation.separator.sequence.terraform
# ^ punctuation.definition.string.end.terraform

a + b
# ^ -keyword -operator
# ^ keyword.operator.arithmetic.terraform
Expand Down
16 changes: 10 additions & 6 deletions syntax_test_terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2880,12 +2880,16 @@
/////

resource "aws_security_group" "example" {
# ^^^^^^^^ meta.type.terraform keyword.declaration.terraform
# ^ meta.type.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform
# ^^^^^^^^^^^^^^^^^^^ meta.type.terraform string.quoted.double.terraform
# ^ meta.type.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform
# ^^^^^^^^ meta.type.terraform string.quoted.double.terraform
# ^ meta.type.terraform meta.block.terraform punctuation.section.block.begin.terraform
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.terraform
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.type.terraform
# ^^^^^^^^ keyword.declaration.terraform
# ^ punctuation.definition.begin.terraform
# ^^^^^^^^^^^^^^^^^^ support.type.terraform
# ^ punctuation.definition.end.terraform
# ^ punctuation.definition.begin.terraform
# ^^^^^^^ entity.name.type.terraform
# ^ punctuation.definition.end.terraform
# ^ punctuation.section.block.begin.terraform
name = "example"
# ^^^^ meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform
# ^ meta.block.terraform keyword.operator.assignment.terraform
Expand Down