-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be more permissive in allowed characters in a block label (#94)
* Be more permissive in allowed characters in a block label Previously a block label would only be allowed to contain the set of characters in an Indentifier, however a block label string literal can contain pretty much any character. This commit updates the base HCL grammar to support both indentifiers and string literals in block labels and adds tests to ensure this behaviour works as expected. * Add additional tests for edgecases in block labels
- Loading branch information
1 parent
ad29c91
commit ac3ca8c
Showing
6 changed files
with
449 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// generic blocks with multiple labels as strings | ||
block0 {} | ||
block0-newline { | ||
} | ||
|
||
block1 "foo" {} | ||
block1-newline "foo" { | ||
} | ||
|
||
block2 "foo" "bar" {} | ||
block2-newline "foo" "bar" { | ||
} | ||
|
||
block3 "foo" "bar" "baz" {} | ||
block3-newline "foo" "bar" "baz" { | ||
} | ||
|
||
block4 "foo" "bar" "baz" "lorum" {} | ||
block4-newline "foo" "bar" "baz" "lorum" { | ||
} | ||
|
||
block5 "foo" "bar" "baz" "lorum" "ipsum" {} | ||
block5-newline "foo" "bar" "baz" "lorum" "ipsum" { | ||
} | ||
|
||
// generic blocks with indentifier labels | ||
blocklabel1 foo bar lorum-ipsum {} | ||
blocklabel1-newline foo bar lorum-ipsum { | ||
} | ||
|
||
blocklabelmixed "foo" bar "loru" m-ipsum {} | ||
blocklabelmixed-newline "foo" bar "loru" m-ipsum { | ||
} | ||
|
||
// utf8 labels | ||
blockutf8 "foož:/ᚠᚢ" {} | ||
blockutf8-newline "foož:/ᚠᚢ" { | ||
} | ||
|
||
// edgecases | ||
blockempty "" {} | ||
blockempty-newline "" { | ||
} | ||
|
||
block-single-char-indentifier a {} | ||
block-single-char-indentifier-newline a { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
>// generic blocks with multiple labels as strings | ||
#^^ source.hcl comment.line.double-slash.hcl punctuation.definition.comment.hcl | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl comment.line.double-slash.hcl | ||
>block0 {} | ||
#^^^^^^ source.hcl meta.block.hcl entity.name.type.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 | ||
>block0-newline { | ||
#^^^^^^^^^^^^^^ source.hcl meta.block.hcl entity.name.type.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 | ||
> | ||
>block1 "foo" {} | ||
#^^^^^^ 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 | ||
>block1-newline "foo" { | ||
#^^^^^^^^^^^^^^ 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 | ||
> | ||
>block2 "foo" "bar" {} | ||
#^^^^^^ 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 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 | ||
>block2-newline "foo" "bar" { | ||
#^^^^^^^^^^^^^^ 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 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 | ||
> | ||
>block3 "foo" "bar" "baz" {} | ||
#^^^^^^ 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 variable.other.enummember.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 | ||
>block3-newline "foo" "bar" "baz" { | ||
#^^^^^^^^^^^^^^ 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 variable.other.enummember.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 | ||
> | ||
>block4 "foo" "bar" "baz" "lorum" {} | ||
#^^^^^^ 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 variable.other.enummember.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 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 | ||
>block4-newline "foo" "bar" "baz" "lorum" { | ||
#^^^^^^^^^^^^^^ 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 variable.other.enummember.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 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 | ||
> | ||
>block5 "foo" "bar" "baz" "lorum" "ipsum" {} | ||
#^^^^^^ 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 variable.other.enummember.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 variable.other.enummember.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 | ||
>block5-newline "foo" "bar" "baz" "lorum" "ipsum" { | ||
#^^^^^^^^^^^^^^ 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 variable.other.enummember.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 variable.other.enummember.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 | ||
> | ||
>// generic blocks with indentifier labels | ||
#^^ source.hcl comment.line.double-slash.hcl punctuation.definition.comment.hcl | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl comment.line.double-slash.hcl | ||
>blocklabel1 foo bar lorum-ipsum {} | ||
#^^^^^^^^^^^ 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 variable.other.enummember.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 | ||
>blocklabel1-newline foo bar lorum-ipsum { | ||
#^^^^^^^^^^^^^^^^^^^ 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 variable.other.enummember.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 | ||
> | ||
>blocklabelmixed "foo" bar "loru" m-ipsum {} | ||
#^^^^^^^^^^^^^^^ 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 variable.other.enummember.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 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 | ||
>blocklabelmixed-newline "foo" bar "loru" m-ipsum { | ||
#^^^^^^^^^^^^^^^^^^^^^^^ 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 variable.other.enummember.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 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 | ||
> | ||
>// utf8 labels | ||
#^^ source.hcl comment.line.double-slash.hcl punctuation.definition.comment.hcl | ||
# ^^^^^^^^^^^^ source.hcl comment.line.double-slash.hcl | ||
>blockutf8 "foož:/ᚠᚢ" {} | ||
#^^^^^^^^^ 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 | ||
>blockutf8-newline "foož:/ᚠᚢ" { | ||
#^^^^^^^^^^^^^^^^^ 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 | ||
> | ||
>// edgecases | ||
#^^ source.hcl comment.line.double-slash.hcl punctuation.definition.comment.hcl | ||
# ^^^^^^^^^^ source.hcl comment.line.double-slash.hcl | ||
>blockempty "" {} | ||
#^^^^^^^^^^ 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 | ||
>blockempty-newline "" { | ||
#^^^^^^^^^^^^^^^^^^ 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 | ||
> | ||
>block-single-char-indentifier a {} | ||
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 | ||
>block-single-char-indentifier-newline a { | ||
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
resource "aws_instance" "web" { | ||
// The trailing { can confuse the regex into thinking it's a block | ||
type = list(object({ | ||
internal = number | ||
external = number | ||
protocol = string | ||
})) | ||
|
||
// The trailing { can confuse the regex into thinking it's a block | ||
default = [{ | ||
internal = 8300 | ||
external = 8300 | ||
protocol = "tcp" | ||
} | ||
] | ||
|
||
# This is a nested block and should highlight correctly | ||
nested-resource "aws_instance" "foo" { | ||
type = "nested" | ||
} | ||
} |
Oops, something went wrong.