Update grammars (#254634)

This commit is contained in:
Alex Ross
2025-07-08 12:59:18 +02:00
committed by GitHub
parent a31b87c942
commit f8bb386a48
12 changed files with 214 additions and 90 deletions

View File

@@ -4,7 +4,7 @@
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
"Once accepted there, we are happy to receive an update request."
],
"version": "https://github.com/worlpaker/go-syntax/commit/0ce19cdf1cb5dab6aa99ccc933be9bd21e855ed1",
"version": "https://github.com/worlpaker/go-syntax/commit/8c70c078f56d237f72574ce49cc95839c4f8a741",
"name": "Go",
"scopeName": "source.go",
"patterns": [
@@ -34,7 +34,7 @@
"include": "#group-variables"
},
{
"include": "#field_hover"
"include": "#hover"
}
]
},
@@ -115,7 +115,7 @@
"include": "#property_variables"
},
{
"include": "#switch_select_case_variables"
"include": "#switch_variables"
},
{
"include": "#other_variables"
@@ -1704,7 +1704,7 @@
},
"support_functions": {
"comment": "Support Functions",
"match": "(?:(?:((?<=\\.)\\b\\w+)|(\\b\\w+))(\\[(?:(?:[\\w\\.\\*\\[\\]\\{\\}\"\\']+)(?:(?:\\,\\s*(?:[\\w\\.\\*\\[\\]\\{\\}]+))*))?\\])?(?=\\())",
"match": "(?:(?:((?<=\\.)\\b\\w+)|(\\b\\w+))(?<brackets>\\[(?:[^\\[\\]]|\\g<brackets>)*\\])?(?=\\())",
"captures": {
"1": {
"name": "entity.name.function.support.go"
@@ -1761,7 +1761,8 @@
"include": "#after_control_variables"
},
{
"match": "(\\b[\\w\\.]+)(\\[(?:(?:[\\w\\.\\*\\[\\]\\{\\}]+)(?:(?:\\,\\s*(?:[\\w\\.\\*\\[\\]\\{\\}]+))*))?\\])?(?=\\{)(?<!\\bstruct\\b|\\binterface\\b)",
"comment": "uses a named group to recursively match generic type with nested brackets, like 'Foo[A[B, C]]{}'",
"match": "\\b(?!struct\\b|interface\\b)([\\w\\.]+)(?<brackets>\\[(?:[^\\[\\]]|\\g<brackets>)*\\])?(?=\\{)",
"captures": {
"1": {
"patterns": [
@@ -1807,7 +1808,7 @@
},
"type_assertion_inline": {
"comment": "struct/interface types in-line (type assertion) | switch type keyword",
"match": "(?:(?<=\\.\\()(?:(\\btype\\b)|((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?[\\w\\.\\[\\]\\*]+))(?=\\)))",
"match": "(?:(?<=\\.\\()(?:(\\btype\\b)|((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[\\[\\]\\*]+)?(?:[\\w\\.]+)(?:\\[(?:(?:[\\w\\.\\*\\[\\]\\{\\}]+)(?:(?:\\,\\s*(?:[\\w\\.\\*\\[\\]\\{\\}]+))*))?\\])?))(?=\\)))",
"captures": {
"1": {
"name": "keyword.type.go"
@@ -1815,7 +1816,31 @@
"2": {
"patterns": [
{
"include": "#type-declarations"
"include": "#type-declarations-without-brackets"
},
{
"match": "\\(",
"name": "punctuation.definition.begin.bracket.round.go"
},
{
"match": "\\)",
"name": "punctuation.definition.end.bracket.round.go"
},
{
"match": "\\[",
"name": "punctuation.definition.begin.bracket.square.go"
},
{
"match": "\\]",
"name": "punctuation.definition.end.bracket.square.go"
},
{
"match": "\\{",
"name": "punctuation.definition.begin.bracket.curly.go"
},
{
"match": "\\}",
"name": "punctuation.definition.end.bracket.curly.go"
},
{
"match": "\\w+",
@@ -1904,12 +1929,12 @@
},
{
"comment": "one line with semicolon(;) without formatting gofmt - single type | property variables and types",
"match": "(?:(?<=\\{)((?:\\s*(?:(?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?(?:(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[\\S]+)(?:\\;)?))+)\\s*(?=\\}))",
"match": "(?:(?<=\\{)((?:\\s*(?:(?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?(?:(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/]+)(?:\\;)?))+)\\s*(?=\\}))",
"captures": {
"1": {
"patterns": [
{
"match": "(?:((?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[\\S]+)(?:\\;)?))",
"match": "(?:((?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))?((?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[^\\s/]+)(?:\\;)?))",
"captures": {
"1": {
"patterns": [
@@ -1958,7 +1983,7 @@
},
{
"comment": "property variables and types",
"match": "(?:((?:(?:\\w+\\,\\s*)+)?(?:\\w+\\s+))([^\\`\"\\/]+))",
"match": "(\\b\\w+(?:\\s*\\,\\s*\\b\\w+)*)\\s*([^\\`\"\\/]+)",
"captures": {
"1": {
"patterns": [
@@ -1994,7 +2019,7 @@
"patterns": [
{
"comment": "struct in struct types",
"begin": "(?:((?:\\w+(?:\\,\\s*\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s+)(?:[\\[\\]\\*]+)?)(\\bstruct\\b)(?:\\s*)(\\{))",
"begin": "(?:((?:\\b\\w+(?:\\,\\s*\\b\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s*)(?:[\\[\\]\\*]+)?)(\\bstruct\\b)(?:\\s*)(\\{))",
"beginCaptures": {
"1": {
"patterns": [
@@ -2031,7 +2056,7 @@
},
{
"comment": "interface in struct types",
"begin": "(?:((?:\\w+(?:\\,\\s*\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s+)(?:[\\[\\]\\*]+)?)(\\binterface\\b)(?:\\s*)(\\{))",
"begin": "(?:((?:\\b\\w+(?:\\,\\s*\\b\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s*)(?:[\\[\\]\\*]+)?)(\\binterface\\b)(?:\\s*)(\\{))",
"beginCaptures": {
"1": {
"patterns": [
@@ -2068,7 +2093,7 @@
},
{
"comment": "function in struct types",
"begin": "(?:((?:\\w+(?:\\,\\s*\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s+)(?:[\\[\\]\\*]+)?)(\\bfunc\\b)(?:\\s*)(\\())",
"begin": "(?:((?:\\b\\w+(?:\\,\\s*\\b\\w+)*)(?:(?:\\s*(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:\\s*)(?:[\\[\\]\\*]+)?)(\\bfunc\\b)(?:\\s*)(\\())",
"beginCaptures": {
"1": {
"patterns": [
@@ -2390,7 +2415,7 @@
},
"after_control_variables": {
"comment": "After control variables, to not highlight as a struct/interface (before formatting with gofmt)",
"match": "(?:(?<=\\brange\\b|\\bswitch\\b|\\;|\\bif\\b|\\bfor\\b|\\<|\\>|\\<\\=|\\>\\=|\\=\\=|\\!\\=|\\w(?:\\+|/|\\-|\\*|\\%)|\\w(?:\\+|/|\\-|\\*|\\%)\\=|\\|\\||\\&\\&)(?:\\s*)((?![\\[\\]]+)[[:alnum:]\\-\\_\\!\\.\\[\\]\\<\\>\\=\\*/\\+\\%\\:]+)(?:\\s*)(?=\\{))",
"match": "(?:(?<=\\brange\\b|\\;|\\bif\\b|\\bfor\\b|\\<|\\>|\\<\\=|\\>\\=|\\=\\=|\\!\\=|\\w(?:\\+|/|\\-|\\*|\\%)|\\w(?:\\+|/|\\-|\\*|\\%)\\=|\\|\\||\\&\\&)(?:\\s*)((?![\\[\\]]+)[[:alnum:]\\-\\_\\!\\.\\[\\]\\<\\>\\=\\*/\\+\\%\\:]+)(?:\\s*)(?=\\{))",
"captures": {
"1": {
"patterns": [
@@ -2649,6 +2674,103 @@
}
]
},
"switch_variables": {
"comment": "variables after case control keyword in switch/select expression, to not scope them as property variables",
"patterns": [
{
"comment": "single line",
"match": "(?:(?:^\\s*(\\bcase\\b))(?:\\s+)([\\s\\S]+(?:\\:)\\s*(?:/(?:/|\\*).*)?)$)",
"captures": {
"1": {
"name": "keyword.control.go"
},
"2": {
"patterns": [
{
"include": "#type-declarations"
},
{
"include": "#support_functions"
},
{
"include": "#variable_assignment"
},
{
"match": "\\w+",
"name": "variable.other.go"
}
]
}
}
},
{
"comment": "multi lines",
"begin": "(?<=\\bswitch\\b)(?:\\s*)((?:[\\w\\.]+(?:\\s*(?:[\\:\\=\\!\\,\\+/\\-\\%\\<\\>\\|\\&]+)\\s*[\\w\\.]+)*\\s*(?:[\\:\\=\\!\\,\\+/\\-\\%\\<\\>\\|\\&]+))?(?:\\s*(?:[\\w\\.\\*\\(\\)\\[\\]\\+/\\-\\%\\<\\>\\|\\&]+)?\\s*(?:\\;\\s*(?:[\\w\\.\\*\\(\\)\\[\\]\\+/\\-\\%\\<\\>\\|\\&]+)\\s*)?))(\\{)",
"beginCaptures": {
"1": {
"patterns": [
{
"include": "#support_functions"
},
{
"include": "#type-declarations"
},
{
"include": "#variable_assignment"
},
{
"match": "\\w+",
"name": "variable.other.go"
}
]
},
"2": {
"name": "punctuation.definition.begin.bracket.curly.go"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.definition.end.bracket.curly.go"
}
},
"patterns": [
{
"begin": "\\bcase\\b",
"beginCaptures": {
"0": {
"name": "keyword.control.go"
}
},
"end": "\\:",
"endCaptures": {
"0": {
"name": "punctuation.other.colon.go"
}
},
"patterns": [
{
"include": "#support_functions"
},
{
"include": "#type-declarations"
},
{
"include": "#variable_assignment"
},
{
"match": "\\w+",
"name": "variable.other.go"
}
]
},
{
"include": "$self"
}
]
}
]
},
"var_assignment": {
"comment": "variable assignment with var keyword",
"patterns": [
@@ -2959,32 +3081,6 @@
}
}
},
"switch_select_case_variables": {
"comment": "variables after case control keyword in switch/select expression, to not scope them as property variables",
"match": "(?:(?:^\\s*(\\bcase\\b))(?:\\s+)([\\s\\S]+(?:\\:)\\s*(?:/(?:/|\\*).*)?)$)",
"captures": {
"1": {
"name": "keyword.control.go"
},
"2": {
"patterns": [
{
"include": "#type-declarations"
},
{
"include": "#support_functions"
},
{
"include": "#variable_assignment"
},
{
"match": "\\w+",
"name": "variable.other.go"
}
]
}
}
},
"slice_index_variables": {
"comment": "slice index and capacity variables, to not scope them as property variables",
"match": "(?<=\\w\\[)((?:(?:\\b[\\w\\.\\*\\+/\\-\\%\\<\\>\\|\\&]+\\:)|(?:\\:\\b[\\w\\.\\*\\+/\\-\\%\\<\\>\\|\\&]+))(?:\\b[\\w\\.\\*\\+/\\-\\%\\<\\>\\|\\&]+)?(?:\\:\\b[\\w\\.\\*\\+/\\-\\%\\<\\>\\|\\&]+)?)(?=\\])",
@@ -3077,40 +3173,65 @@
}
}
},
"field_hover": {
"comment": "struct field property and types when hovering with the mouse",
"match": "(?:(?<=^\\bfield\\b)\\s+([\\w\\*\\.]+)\\s+([\\s\\S]+))",
"captures": {
"1": {
"patterns": [
{
"include": "#type-declarations"
"hover": {
"comment": "hovering with the mouse",
"patterns": [
{
"comment": "struct field property and types when hovering with the mouse",
"match": "(?:(?<=^\\bfield\\b)\\s+([\\w\\*\\.]+)\\s+([\\s\\S]+))",
"captures": {
"1": {
"patterns": [
{
"include": "#type-declarations"
},
{
"match": "\\w+",
"name": "variable.other.property.go"
}
]
},
{
"match": "\\w+",
"name": "variable.other.property.go"
"2": {
"patterns": [
{
"match": "\\binvalid\\b\\s+\\btype\\b",
"name": "invalid.field.go"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
]
}
},
"2": {
"patterns": [
{
"match": "\\binvalid\\b\\s+\\btype\\b",
"name": "invalid.field.go"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
{
"comment": "return types when hovering with the mouse",
"match": "(?:(?<=^\\breturns\\b)\\s+([\\s\\S]+))",
"captures": {
"1": {
"patterns": [
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
]
}
}
}
]
},
"other_variables": {
"comment": "all other variables",