From 51dcc0d175df09bd9d275e5f9a4b53769b4bfde8 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sat, 10 May 2025 17:55:17 +0200 Subject: [PATCH 1/3] Match unclosed strings as invalid --- Terraform.sublime-syntax | 3 +++ tests/syntax_test_scope.tf | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/Terraform.sublime-syntax b/Terraform.sublime-syntax index 65ee72a..d805047 100644 --- a/Terraform.sublime-syntax +++ b/Terraform.sublime-syntax @@ -279,6 +279,9 @@ contexts: - match: \" scope: punctuation.definition.string.end.terraform pop: 1 + - match: \n + scope: invalid.illegal.unclosed-string.terraform + pop: 1 - include: character-escapes - include: string-interpolation - include: aws-acl diff --git a/tests/syntax_test_scope.tf b/tests/syntax_test_scope.tf index aba43d7..ab85552 100644 --- a/tests/syntax_test_scope.tf +++ b/tests/syntax_test_scope.tf @@ -256,6 +256,14 @@ # ^^^^^^^^^^ constant.character.escape.terraform # ^ punctuation.definition.string.end.terraform +///// +// Unclosed strings +///// + + " +# ^ meta.string.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^ invalid.illegal.unclosed-string.terraform + ///////////////////////////////////////////////////////////////////// // Identifiers ///////////////////////////////////////////////////////////////////// From 80c2f9869816878451b2eb2f0d07306e214d3603 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sat, 10 May 2025 18:03:40 +0200 Subject: [PATCH 2/3] Support comments inside JSON collections --- JSON (Terraform).sublime-syntax | 4 ++++ tests/syntax_test_scope.tf | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/JSON (Terraform).sublime-syntax b/JSON (Terraform).sublime-syntax index b6db95f..2042522 100644 --- a/JSON (Terraform).sublime-syntax +++ b/JSON (Terraform).sublime-syntax @@ -15,3 +15,7 @@ contexts: - meta_prepend: true - include: Packages/Terraform/Terraform.sublime-syntax#string-interpolation - include: Packages/Terraform/Terraform.sublime-syntax#aws-acl + + line-comments: + - meta_append: true + - include: Packages/Terraform/Terraform.sublime-syntax#inline-comments diff --git a/tests/syntax_test_scope.tf b/tests/syntax_test_scope.tf index ab85552..7630032 100644 --- a/tests/syntax_test_scope.tf +++ b/tests/syntax_test_scope.tf @@ -3394,6 +3394,8 @@ resource "aws_iam_role_policy" "attach-inline-policy-1" { # ^^^^^^^^^^^^ meta.string.terraform string.quoted.double.terraform # ^ punctuation.definition.string.begin.terraform # ^ punctuation.definition.string.end.terraform + # comment +# ^^^^^^^^^^ comment.line.terraform "Statement": [ #^^^^^^^^^^^^^^^^^^^^^ meta.block.body.terraform meta.function-call.arguments.terraform #^^^^^^^ meta.braces.terraform @@ -3403,6 +3405,8 @@ resource "aws_iam_role_policy" "attach-inline-policy-1" { # ^^ meta.braces.terraform # ^ punctuation.separator.key-value.json # ^ meta.mapping.value.json meta.sequence.json punctuation.section.sequence.begin.json + # comment +# ^^^^^^^^^^ comment.line.terraform { "Action": [ "lambda:InvokeFunction", From 36124ea14cabc69c53c2b8dd89329e6cb570f949 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sat, 10 May 2025 18:08:45 +0200 Subject: [PATCH 3/3] Highlight stray closing punctuation --- Terraform.sublime-syntax | 7 ++++++- tests/syntax_test_scope.tf | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Terraform.sublime-syntax b/Terraform.sublime-syntax index d805047..62048ae 100644 --- a/Terraform.sublime-syntax +++ b/Terraform.sublime-syntax @@ -160,6 +160,7 @@ contexts: - include: functions - include: parens - include: identifiers + - include: illegal-strays comma: - match: \, @@ -517,7 +518,6 @@ contexts: # https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#collection-values object-value: - include: comments - - include: expressions - match: \, comment: Pop scope on comma. scope: punctuation.separator.terraform @@ -529,6 +529,7 @@ contexts: comment: Lookahead (don't consume) and pop scope on a bracket. scope: punctuation.section.braces.end.terraform pop: 1 + - include: expressions # Attribute Access: "." Identifier # @@ -692,6 +693,10 @@ contexts: - match: '{{identifier}}' scope: variable.other.readwrite.terraform + illegal-strays: + - match: '[\])}]' + scope: invalid.illegal.stray.python + # Blocks: Identifier (StringLit|Identifier)* "{" Newline Body "}" Newline; # # https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#structural-elements diff --git a/tests/syntax_test_scope.tf b/tests/syntax_test_scope.tf index 7630032..2db1de7 100644 --- a/tests/syntax_test_scope.tf +++ b/tests/syntax_test_scope.tf @@ -3439,3 +3439,12 @@ resource "aws_iam_role_policy" "attach-inline-policy-1" { ] }) } + +] +# <- invalid.illegal.stray.python + +} +# <- invalid.illegal.stray.python + +) +# <- invalid.illegal.stray.python