Skip to content

Commit a2811b6

Browse files
michaelblyonsdeathaxe
authored andcommitted
Allow JSON mixed with TF object keys (#71)
Fixes #54 This commit extends Sublime Text's JSON syntax to implement Terraform specific string interpolation.
1 parent 8c14ad4 commit a2811b6

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

.github/workflows/syntax.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Syntax Tests
2+
# https://github.com/SublimeText/syntax-test-action
23

34
on:
45
push:
@@ -7,27 +8,30 @@ on:
78
paths:
89
- .github/workflows/syntax.yaml
910
- '**.sublime-syntax'
10-
- '**/syntax_test*'
11+
- '**/syntax_test_*'
1112
- '**.tmPreferences'
1213
pull_request:
1314
paths:
1415
- .github/workflows/syntax.yaml
1516
- '**.sublime-syntax'
16-
- '**/syntax_test*'
17+
- '**/syntax_test_*'
1718
- '**.tmPreferences'
1819

1920
jobs:
2021
syntax_tests:
2122
name: Syntax Tests (${{ matrix.build }})
2223
runs-on: ubuntu-latest
23-
timeout-minutes: 15 # default is 6 hours!
24+
timeout-minutes: 15
2425
strategy:
2526
matrix:
2627
include:
2728
- build: latest # Latest dev build
28-
- build: 4169 # Oldest stable version we intent to support
29+
packages: master
30+
- build: 4180 # Oldest version we intent to support
31+
packages: v4180
2932
steps:
3033
- uses: actions/checkout@v3
3134
- uses: SublimeText/syntax-test-action@v2
3235
with:
3336
build: ${{ matrix.build }}
37+
default_packages: ${{ matrix.packages }}

JSON (Terraform).sublime-syntax

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
%YAML 1.2
22
---
3-
# http://www.sublimetext.com/docs/3/syntax.html
3+
# http://www.sublimetext.com/docs/syntax.html
44
name: JSON (Terraform)
5+
scope: source.json.terraform
6+
version: 2
57
hidden: true
8+
9+
extends: Packages/JSON/JSON.sublime-syntax
10+
611
file_extensions:
712
- tfstate
8-
scope: source.json.terraform
13+
914
contexts:
10-
main:
11-
- include: scope:source.json
15+
double-quoted-string-body:
16+
- meta_prepend: true
17+
- include: Packages/Terraform/Terraform.sublime-syntax#string_interpolation

Terraform.sublime-syntax

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ contexts:
453453
2: keyword.operator.terraform
454454
set: object_value
455455
- include: expressions
456+
- include: scope:source.json.terraform#object-body
456457

457458
object_key:
458459
- match: '{{identifier}}'

syntax_test_terraform.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,3 +3178,56 @@
31783178
# ^ punctuation.accessor.dot.terraform
31793179
# ^^^^^ variable.other.member.terraform
31803180
# ^^^^^^ constant.numeric.integer.terraform
3181+
3182+
3183+
resource "aws_iam_role_policy" "attach-inline-policy-1" {
3184+
name = "xxx"
3185+
role = aws_iam_role.execution-role.name
3186+
policy = jsonencode({
3187+
Version = "2012-10-17"
3188+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.terraform meta.function-call.terraform meta.braces.terraform
3189+
# ^^^^^^^ meta.mapping.key.terraform string.unquoted.terraform
3190+
# ^ keyword.operator.assignment.terraform
3191+
# ^^^^^^^^^^^^ meta.string.terraform string.quoted.double.terraform
3192+
# ^ punctuation.definition.string.begin.terraform
3193+
# ^ punctuation.definition.string.end.terraform
3194+
"Statement": [
3195+
#^^^^^^^^^^^^^^^^^^^^^ meta.block.terraform meta.function-call.terraform
3196+
#^^^^^^^ meta.braces.terraform
3197+
# ^^^^^^^^^^^ meta.mapping.key.json string.quoted.double.json
3198+
# ^ punctuation.definition.string.begin.json
3199+
# ^ punctuation.definition.string.end.json
3200+
# ^^ meta.braces.terraform
3201+
# ^ punctuation.separator.key-value.json
3202+
# ^ meta.mapping.value.json meta.sequence.json punctuation.section.sequence.begin.json
3203+
{
3204+
"Action": [
3205+
"lambda:InvokeFunction",
3206+
"lambda:InvokeAsync"
3207+
],
3208+
"Resource": "arn:aws:lambda:*:*:function:${var.environment}-xxx",
3209+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.terraform meta.function-call.terraform meta.mapping.value.json meta.sequence.json
3210+
#^^^^^^^^^^^^^^^ meta.mapping.json
3211+
# ^^^^^^^^^^ meta.mapping.key.json string.quoted.double.json
3212+
# ^ punctuation.definition.string.begin.json
3213+
# ^ punctuation.definition.string.end.json
3214+
# ^^ meta.mapping.json
3215+
# ^ punctuation.separator.key-value.json
3216+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.json meta.string.json
3217+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.json
3218+
# ^ punctuation.definition.string.begin.json
3219+
# ^^^^^^^^^^^^^^^^^^ meta.interpolation.terraform
3220+
# ^^ punctuation.section.interpolation.begin.terraform
3221+
# ^^^^^^^^^^^^^^^ source.terraform
3222+
# ^^^ variable.language.terraform
3223+
# ^ punctuation.accessor.dot.terraform
3224+
# ^^^^^^^^^^^ variable.other.member.terraform
3225+
# ^ punctuation.section.interpolation.end.terraform
3226+
# ^^^^^ string.quoted.double.json
3227+
# ^ punctuation.definition.string.end.json
3228+
# ^ meta.mapping.json punctuation.separator.sequence.json
3229+
"Effect": "Allow"
3230+
}
3231+
]
3232+
})
3233+
}

0 commit comments

Comments
 (0)