Update Go grammar (#204590)

This commit is contained in:
Alex Ross 2024-02-07 14:33:31 +01:00 committed by GitHub
parent 7c16d665f9
commit fc771c597f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 239 additions and 206 deletions

View file

@ -6,12 +6,12 @@
"git": {
"name": "go-syntax",
"repositoryUrl": "https://github.com/worlpaker/go-syntax",
"commitHash": "80a9e153c018b6c3b9c52766b39d7be9d915f68b"
"commitHash": "de0edabe11035e7035155c68eddc5817d5ec4af9"
}
},
"license": "MIT",
"description": "The file syntaxes/go.tmLanguage.json is from https://github.com/worlpaker/go-syntax, which in turn was derived from https://github.com/jeff-hykin/better-go-syntax.",
"version": "0.5.5"
"version": "0.5.6"
}
],
"version": 1

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/80a9e153c018b6c3b9c52766b39d7be9d915f68b",
"version": "https://github.com/worlpaker/go-syntax/commit/de0edabe11035e7035155c68eddc5817d5ec4af9",
"name": "Go",
"scopeName": "source.go",
"patterns": [
@ -126,7 +126,7 @@
"include": "#comments"
},
{
"include": "#map_other_types"
"include": "#map_types"
},
{
"include": "#brackets"
@ -170,7 +170,7 @@
"include": "#comments"
},
{
"include": "#map_other_types"
"include": "#map_types"
},
{
"include": "#delimiters"
@ -297,62 +297,79 @@
}
]
},
"map_other_types": {
"map_types": {
"comment": "map types",
"begin": "(?:(\\bmap\\b)(\\[))",
"beginCaptures": {
"1": {
"name": "keyword.map.go"
},
"2": {
"name": "punctuation.definition.begin.bracket.square.go"
}
},
"end": "(?:(\\])((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?!(?:[\\[\\]\\*]+)?\\b(?:func|struct|map)\\b)[\\w\\.\\[\\]\\*]+)?)",
"endCaptures": {
"1": {
"name": "punctuation.definition.end.bracket.square.go"
},
"2": {
"patterns": [
{
"include": "#type-declarations-without-brackets"
},
{
"match": "\\[",
"name": "punctuation.definition.begin.bracket.square.go"
},
{
"match": "\\]",
"name": "punctuation.definition.end.bracket.square.go"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
},
"patterns": [
{
"comment": "Other map type names (struct/interface)",
"match": "(?:(\\bmap\\b)(\\[(?:.*)\\])?((?!\\bfunc\\b|\\bstruct\\b)[\\w\\.\\*]+)?)",
"captures": {
"1": {
"name": "keyword.map.go"
},
"2": {
"patterns": [
{
"include": "#type-declarations-without-brackets"
},
{
"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": "\\(",
"name": "punctuation.definition.begin.bracket.round.go"
},
{
"match": "\\)",
"name": "punctuation.definition.end.bracket.round.go"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
},
"3": {
"patterns": [
{
"include": "#type-declarations"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
}
"include": "#type-declarations-without-brackets"
},
{
"include": "#generic_types"
},
{
"include": "#functions"
},
{
"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": "\\(",
"name": "punctuation.definition.begin.bracket.round.go"
},
{
"match": "\\)",
"name": "punctuation.definition.end.bracket.round.go"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
},
@ -1496,7 +1513,7 @@
},
"functions_inline": {
"comment": "functions in-line with multi return types",
"match": "(?:(\\bfunc\\b)((?:\\((?:.*)\\))(?:\\s+)(?:\\((?:.*)\\)))(?:\\s+)(?=\\{))",
"match": "(?:(\\bfunc\\b)((?:\\((?:[^/]*)\\))(?:\\s+)(?:\\((?:[^/]*)\\)))(?:\\s+)(?=\\{))",
"captures": {
"1": {
"name": "keyword.function.go"
@ -1554,7 +1571,7 @@
},
"support_functions": {
"comment": "Support Functions",
"match": "(?:(?:((?<=\\.)\\w+)|(\\w+))(\\[(?:.*)?\\])?(?=\\())",
"match": "(?:(?:((?<=\\.)\\w+)|(\\w+))(\\[(?:(?:[\\w\\.\\*\\[\\]\\{\\}\"\\']+)(?:(?:\\,\\s*(?:[\\w\\.\\*\\[\\]\\{\\}]+))*))?\\])?(?=\\())",
"captures": {
"1": {
"name": "entity.name.function.support.go"
@ -1588,7 +1605,15 @@
"name": "punctuation.definition.end.bracket.square.go"
},
{
"match": "(?:\\w+)",
"match": "\\{",
"name": "punctuation.definition.begin.bracket.curly.go"
},
{
"match": "\\}",
"name": "punctuation.definition.end.bracket.curly.go"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
@ -1599,6 +1624,7 @@
"comment": "struct and interface expression in-line (before curly bracket)",
"patterns": [
{
"comment": "after control variables must be added exactly here, do not move it! (changing may not affect tests, so be careful!)",
"include": "#after_control_variables"
},
{
@ -1947,7 +1973,7 @@
"patterns": [
{
"comment": "single type declaration",
"match": "(?:(?:^|\\s+)(\\btype\\b)(?:\\s*)([\\w\\.\\*]+)(\\[(?:.*)\\])?(?:\\s+)((?!(?:[\\[\\]\\*]+)?(?:\\bstruct\\b|\\binterface\\b))([\\s\\S]+)))",
"match": "(?:(?:^\\s*)(\\btype\\b)(?:\\s*)([\\w\\.\\*]+)(?:\\s+)(?!(?:[\\[\\]\\*]+)?\\b(?:struct|interface)\\b)([\\s\\S]+))",
"captures": {
"1": {
"name": "keyword.type.go"
@ -1958,38 +1984,12 @@
"include": "#type-declarations"
},
{
"match": "(?:\\w+)",
"match": "\\w+",
"name": "entity.name.type.go"
}
]
},
"3": {
"patterns": [
{
"begin": "\\[",
"beginCaptures": {
"0": {
"name": "punctuation.definition.begin.bracket.square.go"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.definition.end.bracket.square.go"
}
},
"patterns": [
{
"include": "#generic_param_types"
},
{
"include": "$self"
}
]
}
]
},
"4": {
"patterns": [
{
"begin": "\\(",
@ -2020,52 +2020,15 @@
"include": "#generic_types"
},
{
"match": "(?:\\w+)",
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
}
}
]
},
"multi_types": {
"patterns": [
{
"comment": "multi type declaration",
"begin": "(\\btype\\b)\\s*(\\()",
"beginCaptures": {
"1": {
"name": "keyword.type.go"
},
"2": {
"name": "punctuation.definition.begin.bracket.round.go"
}
},
"patterns": [
{
"include": "#struct_variables_types"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "(?:\\w+)",
"name": "entity.name.type.go"
}
],
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.definition.end.bracket.round.go"
}
}
},
{
"comment": "single type declaration with multi-lines generics",
"comment": "single type declaration with generics",
"begin": "(?:(?:^|\\s+)(\\btype\\b)(?:\\s*)([\\w\\.\\*]+)(?=\\[))",
"beginCaptures": {
"1": {
@ -2077,7 +2040,7 @@
"include": "#type-declarations-without-brackets"
},
{
"match": "(?:\\w+)",
"match": "\\w+",
"name": "entity.name.type.go"
}
]
@ -2085,42 +2048,6 @@
},
"end": "(?:(?<=\\])((?:\\s+)(?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:(?!(?:[\\[\\]\\*]+)?(?:\\bstruct\\b|\\binterface\\b|\\bfunc\\b))[\\w\\.\\-\\*\\[\\]]+))?)",
"endCaptures": {
"1": {
"patterns": [
{
"include": "#type-declarations-without-brackets"
},
{
"match": "(?:\\w+)",
"name": "entity.name.type.go"
}
]
}
},
"patterns": [
{
"include": "#struct_variables_types"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "(?:\\w+)",
"name": "entity.name.type.go"
}
]
}
]
},
"after_control_variables": {
"patterns": [
{
"comment": "After control variables, to not highlight as a struct/interface",
"match": "(?:(?<=\\brange\\b|\\bswitch\\b|\\;|\\bif\\b|\\bfor\\b|\\<|\\>|\\<\\=|\\>\\=|\\=\\=|\\!\\=|\\w(?:\\+|/|\\-|\\*|\\%)|\\w(?:\\+|/|\\-|\\*|\\%)\\=|\\|\\||\\&\\&)(?:\\s*)([[:alnum:]\\-\\_\\!\\.\\[\\]\\<\\>\\=\\*/\\+\\%\\:]+)(?:\\s*)(?=\\{))",
"captures": {
"1": {
"patterns": [
{
@ -2135,15 +2062,112 @@
"name": "punctuation.definition.end.bracket.square.go"
},
{
"match": "(?:\\w+)",
"name": "variable.other.go"
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
}
},
"patterns": [
{
"include": "#struct_variables_types"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"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": "\\(",
"name": "punctuation.definition.begin.bracket.round.go"
},
{
"match": "\\)",
"name": "punctuation.definition.end.bracket.round.go"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
}
]
},
"multi_types": {
"comment": "multi type declaration",
"begin": "(\\btype\\b)\\s*(\\()",
"beginCaptures": {
"1": {
"name": "keyword.type.go"
},
"2": {
"name": "punctuation.definition.begin.bracket.round.go"
}
},
"patterns": [
{
"include": "#struct_variables_types"
},
{
"include": "#type-declarations-without-brackets"
},
{
"include": "#parameter-variable-types"
},
{
"match": "(?:\\w+)",
"name": "entity.name.type.go"
}
],
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.definition.end.bracket.round.go"
}
}
},
"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*)(?=\\{))",
"captures": {
"1": {
"patterns": [
{
"include": "#type-declarations-without-brackets"
},
{
"match": "\\[",
"name": "punctuation.definition.begin.bracket.square.go"
},
{
"match": "\\]",
"name": "punctuation.definition.end.bracket.square.go"
},
{
"match": "(?:\\w+)",
"name": "variable.other.go"
}
]
}
}
},
"syntax_errors": {
"patterns": [
{
@ -2210,7 +2234,7 @@
},
{
"comment": "make keyword",
"match": "(?:(\\bmake\\b)(?:(\\()((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?:[\\w\\.\\*\\[\\]\\{\\}]+)(?:\\[(?:[^\\]]+)?\\])?(?:[\\w\\.\\*\\[\\]\\{\\}]+)?)?((?:\\,\\s*[\\w\\.\\(\\)]+)+)?(\\))))",
"match": "(?:(\\bmake\\b)(?:(\\()((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+(?:\\([^\\)]+\\))?)?(?:[\\w\\.\\*\\[\\]\\{\\}]+)?(?:\\[(?:[^\\]]+)?\\])?(?:[\\w\\.\\*\\[\\]\\{\\}]+)?)?((?:\\,\\s*(?:[\\w\\.\\(\\)]+)?)+)?(\\))))",
"captures": {
"1": {
"name": "entity.name.function.support.builtin.go"
@ -2247,45 +2271,22 @@
]
},
"struct_interface_declaration": {
"comment": "struct, interface type declarations",
"match": "(?:(?:^|\\s+)(\\btype\\b)(?:\\s+)([\\w\\.]+)(\\[(?:.*)\\])?)",
"comment": "struct, interface type declarations (related to: struct_variables_types, interface_variables_types)",
"match": "(?:(?:^\\s*)(\\btype\\b)(?:\\s*)([\\w\\.]+))",
"captures": {
"1": {
"name": "keyword.type.go"
},
"2": {
"patterns": [
{
"include": "#type-declarations"
},
{
"match": "\\w+",
"name": "entity.name.type.go"
}
]
},
"3": {
"patterns": [
{
"begin": "\\[",
"beginCaptures": {
"0": {
"name": "punctuation.definition.begin.bracket.square.go"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.definition.end.bracket.square.go"
}
},
"patterns": [
{
"include": "#generic_param_types"
},
{
"include": "$self"
}
]
}
]
}
}
},
@ -2384,7 +2385,7 @@
"patterns": [
{
"comment": "var and const with single type assignment",
"match": "(?:(?<=\\bvar\\b|\\bconst\\b)(?:\\s*)([\\w\\.]+(?:(?:\\,\\s*[\\w\\.]+)+)?)(?:\\s*)(?:((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?!(?:(?:[\\[\\]\\*]+)?\\bstruct\\b\\s*\\{)|(?:(?:[\\[\\]\\*]+)?\\bfunc\\b))(?:(?:(?:[\\w\\.\\*]+)?(?:\\[(?:.*)\\])?(?:[\\w\\.\\*]+)?))?\\s*(?:\\=)?))?)",
"match": "(?:(?<=\\bvar\\b|\\bconst\\b)(?:\\s*)(\\b[\\w\\.]+(?:\\,\\s*[\\w\\.]+)*)(?:\\s*)((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+(?:\\([^\\)]+\\))?)?(?!(?:[\\[\\]\\*]+)?\\b(?:struct|func|map)\\b)(?:[\\w\\.\\[\\]\\*]+(?:\\,\\s*[\\w\\.\\[\\]\\*]+)*)?(?:\\s*)(?:\\=)?)?)",
"captures": {
"1": {
"patterns": [
@ -2392,7 +2393,7 @@
"include": "#delimiters"
},
{
"match": "(?:\\w+)",
"match": "\\w+",
"name": "variable.other.assignment.go"
}
]
@ -2400,13 +2401,29 @@
"2": {
"patterns": [
{
"include": "#type-declarations"
"include": "#type-declarations-without-brackets"
},
{
"include": "#generic_types"
},
{
"match": "(?:\\w+)",
"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": "\\w+",
"name": "entity.name.type.go"
}
]
@ -2429,7 +2446,7 @@
},
"patterns": [
{
"match": "(?:(?:^\\s+)([\\w\\.]+(?:(?:\\,\\s*[\\w\\.]+)+)?)(?:\\s*)((?:((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+)?(?!(?:(?:[\\[\\]\\*]+)?\\bstruct\\b\\s*\\{)|(?:(?:[\\[\\]\\*]+)?\\bfunc\\b))(?:(?:(?:[\\w\\.\\*]+)?(?:\\[(?:.*)\\])?(?:[\\w\\.\\*]+)?))?\\s*(?:\\=)?))?))",
"match": "(?:(?:^\\s*)(\\b[\\w\\.]+(?:\\,\\s*[\\w\\.]+)*)(?:\\s*)((?:(?:(?:[\\*\\[\\]]+)?(?:\\<\\-\\s*)?\\bchan\\b(?:\\s*\\<\\-)?\\s*)+(?:\\([^\\)]+\\))?)?(?!(?:[\\[\\]\\*]+)?\\b(?:struct|func|map)\\b)(?:[\\w\\.\\[\\]\\*]+(?:\\,\\s*[\\w\\.\\[\\]\\*]+)*)?(?:\\s*)(?:\\=)?)?)",
"captures": {
"1": {
"patterns": [
@ -2437,7 +2454,7 @@
"include": "#delimiters"
},
{
"match": "(?:\\w+)",
"match": "\\w+",
"name": "variable.other.assignment.go"
}
]
@ -2445,13 +2462,29 @@
"2": {
"patterns": [
{
"include": "#type-declarations"
"include": "#type-declarations-without-brackets"
},
{
"include": "#generic_types"
},
{
"match": "(?:\\w+)",
"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": "\\w+",
"name": "entity.name.type.go"
}
]