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

Fix highlighting of .0, .* attribute access and [*] brackets #44

Merged
merged 7 commits into from
Jun 7, 2022
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
32 changes: 21 additions & 11 deletions src/_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ repository:
- include: "#brackets"
- include: "#objects"
- include: "#attribute_access"
- include: "#attribute_splat"
- include: "#functions"
- include: "#parens"
literal_values:
Expand Down Expand Up @@ -227,13 +228,14 @@ repository:
beginCaptures:
"0":
name: punctuation.section.brackets.begin.hcl
end: (\*?)\]
end: \]
endCaptures:
"0":
name: punctuation.section.brackets.end.hcl
"1":
name: keyword.operator.splat.hcl
patterns:
- match: \*
comment: Splat operator
name: keyword.operator.splat.hcl
- include: "#comma"
- include: "#comments"
- include: "#inline_for_expression"
Expand Down Expand Up @@ -290,6 +292,7 @@ repository:
name: keyword.operator.hcl
patterns:
- include: "#attribute_access"
- include: "#attribute_splat"
- include: "#object_key_values"
object_key_values:
patterns:
Expand Down Expand Up @@ -366,24 +369,31 @@ repository:
- include: "#comma"
- include: "#local_identifiers"
attribute_access:
begin: \.
begin: \.(?!\*)
beginCaptures:
"0":
name: keyword.operator.accessor.hcl
end: "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?"
comment: Matches a variable with an optional splat or index ([*]/[0])
end: '[[:alpha:]][\w-]*|\d*'
comment: Matches traversal attribute access such as .attr
endCaptures:
"0":
patterns:
- match: \b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\b
comment: Attribute name including - and _
- match: (?!null|false|true)[[:alpha:]][\w-]*
comment: Attribute name
name: variable.other.member.hcl
- match: \d+
comment: Optional attribute index
name: constant.numeric.integer.hcl
- match: \*
comment: Optional attribute-only splat
name: keyword.operator.splat.hcl
attribute_splat:
begin: \.
end: \*
comment: Legacy attribute-only splat
beginCaptures:
"0":
name: keyword.operator.accessor.hcl
endCaptures:
"0":
name: keyword.operator.splat.hcl
functions:
begin: (\w+)(\()
name: meta.function-call.hcl
Expand Down
46 changes: 32 additions & 14 deletions syntaxes/hcl.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
],
"repository": {
"attribute_access": {
"begin": "\\.",
"end": "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?",
"comment": "Matches a variable with an optional splat or index ([*]/[0])",
"begin": "\\.(?!\\*)",
"end": "[[:alpha:]][\\w-]*|\\d*",
"comment": "Matches traversal attribute access such as .attr",
"beginCaptures": {
"0": {
"name": "keyword.operator.accessor.hcl"
Expand All @@ -33,19 +33,14 @@
"0": {
"patterns": [
{
"match": "\\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\\b",
"comment": "Attribute name including - and _",
"match": "(?!null|false|true)[[:alpha:]][\\w-]*",
"comment": "Attribute name",
"name": "variable.other.member.hcl"
},
{
"match": "\\d+",
"comment": "Optional attribute index",
"name": "constant.numeric.integer.hcl"
},
{
"match": "\\*",
"comment": "Optional attribute-only splat",
"name": "keyword.operator.splat.hcl"
}
]
}
Expand All @@ -70,6 +65,21 @@
}
}
},
"attribute_splat": {
"begin": "\\.",
"end": "\\*",
"comment": "Legacy attribute-only splat",
"beginCaptures": {
"0": {
"name": "keyword.operator.accessor.hcl"
}
},
"endCaptures": {
"0": {
"name": "keyword.operator.splat.hcl"
}
}
},
"block": {
"name": "meta.block.hcl",
"begin": "(\\w+)([\\s\\\"\\-\\w]*)(\\{)",
Expand Down Expand Up @@ -131,7 +141,7 @@
},
"brackets": {
"begin": "\\[",
"end": "(\\*?)\\]",
"end": "\\]",
"beginCaptures": {
"0": {
"name": "punctuation.section.brackets.begin.hcl"
Expand All @@ -140,12 +150,14 @@
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.hcl"
},
"1": {
"name": "keyword.operator.splat.hcl"
}
},
"patterns": [
{
"name": "keyword.operator.splat.hcl",
"match": "\\*",
"comment": "Splat operator"
},
{
"include": "#comma"
},
Expand Down Expand Up @@ -223,6 +235,9 @@
{
"include": "#attribute_access"
},
{
"include": "#attribute_splat"
},
{
"include": "#functions"
},
Expand Down Expand Up @@ -573,6 +588,9 @@
"patterns": [
{
"include": "#attribute_access"
},
{
"include": "#attribute_splat"
}
]
},
Expand Down
43 changes: 29 additions & 14 deletions syntaxes/terraform.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
],
"repository": {
"attribute_access": {
"begin": "\\.",
"end": "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?",
"comment": "Matches a variable with an optional splat or index ([*]/[0])",
"begin": "\\.(?!\\*)",
"end": "[[:alpha:]][\\w-]*|\\d*",
"comment": "Matches traversal attribute access such as .attr",
"beginCaptures": {
"0": {
"name": "keyword.operator.accessor.hcl"
Expand All @@ -34,19 +34,14 @@
"0": {
"patterns": [
{
"match": "\\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\\b",
"comment": "Attribute name including - and _",
"match": "(?!null|false|true)[[:alpha:]][\\w-]*",
"comment": "Attribute name",
"name": "variable.other.member.hcl"
},
{
"match": "\\d+",
"comment": "Optional attribute index",
"name": "constant.numeric.integer.hcl"
},
{
"match": "\\*",
"comment": "Optional attribute-only splat",
"name": "keyword.operator.splat.hcl"
}
]
}
Expand All @@ -71,6 +66,21 @@
}
}
},
"attribute_splat": {
"begin": "\\.",
"end": "\\*",
"comment": "Legacy attribute-only splat",
"beginCaptures": {
"0": {
"name": "keyword.operator.accessor.hcl"
}
},
"endCaptures": {
"0": {
"name": "keyword.operator.splat.hcl"
}
}
},
"block": {
"name": "meta.block.hcl",
"begin": "(\\w+)([\\s\\\"\\-\\w]*)(\\{)",
Expand Down Expand Up @@ -137,7 +147,7 @@
},
"brackets": {
"begin": "\\[",
"end": "(\\*?)\\]",
"end": "\\]",
"beginCaptures": {
"0": {
"name": "punctuation.section.brackets.begin.hcl"
Expand All @@ -146,12 +156,14 @@
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.hcl"
},
"1": {
"name": "keyword.operator.splat.hcl"
}
},
"patterns": [
{
"name": "keyword.operator.splat.hcl",
"match": "\\*",
"comment": "Splat operator"
},
{
"include": "#comma"
},
Expand Down Expand Up @@ -229,6 +241,9 @@
{
"include": "#attribute_access"
},
{
"include": "#attribute_splat"
},
{
"include": "#functions"
},
Expand Down
14 changes: 11 additions & 3 deletions tests/snapshot/hcl/expressions_splat.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[for o in var.list : o.id]
attr = [for o in var.list : o.id]

var.list[*].id
attr = var.list[*].id

var.list[*].interfaces[0].name
attr = var.list[*].interfaces[0].name

attr = var.list.*.id

attr = "${var.list.*.id}"

attr = "${var.list.*}"

attr = var.list.*
Loading