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

(TFECO-7531) fix(hcl): don't parse expressions containing an open curly brace as blocks #149

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ repository:
block:
name: meta.block.hcl
comment: This will match HCL blocks like `thing1 "one" "two" {` or `thing2 {`
begin: ([\w][\-\w]*)([^?\r\n]*)(\{)
begin: ([\w][\-\w]*)(([^\S\r\n]*([\w][\-_\w]*|\"[^\"\r\n]*\"))*)[^\S\r\n]*(\{)
beginCaptures:
"1":
patterns:
Expand All @@ -89,9 +89,9 @@ repository:
comment: Block label (String Literal)
match: '\"[^\"\r\n]*\"'
- name: variable.other.enummember.hcl
comment: Block label (Indentifier)
comment: Block label (Identifier)
match: "[[:alpha:]][[:alnum:]_-]*"
"3":
"5":
name: punctuation.section.block.begin.hcl
end: \}
endCaptures:
Expand Down
6 changes: 3 additions & 3 deletions syntaxes/hcl.tmGrammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions syntaxes/terraform.tmGrammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/snapshot/hcl/block_labels.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ block-single-char-indentifier-newline a {
byte_match_statement_rules = local.enabled && var.byte_match_statement_rules != null ? {
}

# braces are fun (now)
a = not_a_block == "{"
brace_label "{" {}

path "secrets/data/users/{{identity.entity.name}}/*" {
capabilities = ["create", "update", "patch", "read", "delete", "list"]
}
Expand Down
22 changes: 22 additions & 0 deletions tests/snapshot/hcl/block_labels.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@
>}
#^ source.hcl meta.braces.hcl punctuation.section.braces.end.hcl
>
># braces are fun (now)
#^ source.hcl comment.line.number-sign.hcl punctuation.definition.comment.hcl
# ^^^^^^^^^^^^^^^^^^^^^ source.hcl comment.line.number-sign.hcl
>a = not_a_block == "{"
#^ source.hcl variable.declaration.hcl variable.other.readwrite.hcl
# ^ source.hcl variable.declaration.hcl
# ^ source.hcl variable.declaration.hcl keyword.operator.assignment.hcl
# ^ source.hcl variable.declaration.hcl
# ^^^^^^^^^^^^ source.hcl
# ^^ source.hcl keyword.operator.hcl
# ^ source.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
>brace_label "{" {}
#^^^^^^^^^^^ source.hcl meta.block.hcl entity.name.type.hcl
# ^ source.hcl meta.block.hcl
# ^^^ source.hcl meta.block.hcl variable.other.enummember.hcl
# ^ source.hcl meta.block.hcl
# ^ source.hcl meta.block.hcl punctuation.section.block.begin.hcl
# ^ source.hcl meta.block.hcl punctuation.section.block.end.hcl
>
>path "secrets/data/users/{{identity.entity.name}}/*" {
#^^^^ source.hcl meta.block.hcl entity.name.type.hcl
# ^ source.hcl meta.block.hcl
Expand Down