Skip to content

Commit

Permalink
Variables with no space between them break syntax highlighting (#34)
Browse files Browse the repository at this point in the history
* Replace the anchor with negative lookbehind

* Add an example of two variables without whitespace between them to the test

* Update remaining HCL snapshots
  • Loading branch information
kamilturek authored May 20, 2022
1 parent 20b1f42 commit e1afa69
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ repository:
- include: "#string_interpolation"
- include: "#char_escapes"
string_interpolation:
begin: (\G|[^%$])([%$]{)
begin: '(?<![%$])([%$]{)'
comment: String interpolation
name: meta.interpolation.hcl
beginCaptures:
"2":
"1":
name: keyword.other.interpolation.begin.hcl
end: \}
endCaptures:
Expand Down
4 changes: 2 additions & 2 deletions syntaxes/hcl.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,11 @@
},
"string_interpolation": {
"name": "meta.interpolation.hcl",
"begin": "(\\G|[^%$])([%$]{)",
"begin": "(?<![%$])([%$]{)",
"end": "\\}",
"comment": "String interpolation",
"beginCaptures": {
"2": {
"1": {
"name": "keyword.other.interpolation.begin.hcl"
}
},
Expand Down
4 changes: 2 additions & 2 deletions syntaxes/terraform.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,11 @@
},
"string_interpolation": {
"name": "meta.interpolation.hcl",
"begin": "(\\G|[^%$])([%$]{)",
"begin": "(?<![%$])([%$]{)",
"end": "\\}",
"comment": "String interpolation",
"beginCaptures": {
"2": {
"1": {
"name": "keyword.other.interpolation.begin.hcl"
}
},
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshot/hcl/basic.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@
# ^ source.hcl variable.declaration.hcl keyword.operator.assignment.hcl
# ^ source.hcl variable.declaration.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshot/hcl/expressions_for.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshot/hcl/expressions_functions.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@
# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl
>" items: ${indent(2, "[\n foo,\n bar,\n]\n")}"
#^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl meta.function-call.hcl support.function.builtin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl
Expand Down
22 changes: 10 additions & 12 deletions tests/snapshot/hcl/expressions_strings.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
>
>"Hello, ${var.name}!"
#^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.operator.accessor.hcl
Expand All @@ -92,8 +91,7 @@
>
>"Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!"
#^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
Expand All @@ -108,15 +106,17 @@
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^^^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl variable.other.member.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^^^^ source.hcl string.quoted.double.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl string.quoted.double.hcl
# ^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^ source.hcl string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
Expand Down Expand Up @@ -146,8 +146,7 @@
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
>server ${ip}
#^^^^^^ source.hcl string.unquoted.heredoc.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl
#^^^^^^^ source.hcl string.unquoted.heredoc.hcl
# ^^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down Expand Up @@ -181,8 +180,7 @@
# ^^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.operator.template.right.trim.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
>server ${ip}
#^^^^^^ source.hcl string.unquoted.heredoc.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl
#^^^^^^^ source.hcl string.unquoted.heredoc.hcl
# ^^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshot/terraform/expressions_for.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^ source.hcl.terraform string.quoted.double.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshot/terraform/expressions_functions.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.end.hcl
>" items: ${indent(2, "[\n foo,\n bar,\n]\n")}"
#^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl meta.function-call.hcl support.function.builtin.terraform
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl meta.function-call.hcl punctuation.section.parens.begin.hcl
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshot/terraform/expressions_strings.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ block {
EOT
}

"Hello, ${var.name}!"
"Hello, ${var.name}${var.name}!"

"Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!"

Expand Down
33 changes: 18 additions & 15 deletions tests/snapshot/terraform/expressions_strings.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@
>}
#^ source.hcl.terraform meta.block.hcl punctuation.section.block.end.hcl
>
>"Hello, ${var.name}!"
>"Hello, ${var.name}${var.name}!"
#^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.terraform
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.member.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.terraform
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.member.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.end.hcl
>
>"Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!"
#^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
Expand All @@ -108,15 +111,17 @@
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.readwrite.terraform
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl variable.other.member.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
# ^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^^^ source.hcl.terraform string.quoted.double.hcl
# ^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl
# ^^^^^ source.hcl.terraform string.quoted.double.hcl meta.interpolation.hcl keyword.control.hcl
Expand Down Expand Up @@ -146,8 +151,7 @@
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
>server ${ip}
#^^^^^^ source.hcl.terraform string.unquoted.heredoc.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl
#^^^^^^^ source.hcl.terraform string.unquoted.heredoc.hcl
# ^^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down Expand Up @@ -181,8 +185,7 @@
# ^^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.operator.template.right.trim.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
>server ${ip}
#^^^^^^ source.hcl.terraform string.unquoted.heredoc.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl
#^^^^^^^ source.hcl.terraform string.unquoted.heredoc.hcl
# ^^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.begin.hcl
# ^^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl variable.other.readwrite.hcl
# ^ source.hcl.terraform string.unquoted.heredoc.hcl meta.interpolation.hcl keyword.other.interpolation.end.hcl
Expand Down

0 comments on commit e1afa69

Please sign in to comment.