From df3499d1db14d66d603b5ff7dbf7c5048fa01c65 Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Sat, 2 Mar 2019 13:56:44 -0700 Subject: [PATCH] add grammar, syntax highlighting for go.mod and go.sum(#2344) * add go.mod and go.sum support * rename to Checksum --- package.json | 30 ++++++ syntaxes/go.mod.tmGrammar.json | 163 +++++++++++++++++++++++++++++++++ syntaxes/go.sum.tmGrammar.json | 44 +++++++++ 3 files changed, 237 insertions(+) create mode 100644 syntaxes/go.mod.tmGrammar.json create mode 100644 syntaxes/go.sum.tmGrammar.json diff --git a/package.json b/package.json index c68e92cf..25508ae6 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,36 @@ "aliases": [ "Go" ] + }, + { + "id": "go.mod", + "extensions": [ + "go.mod" + ], + "aliases": [ + "Go Module File" + ] + }, + { + "id": "go.sum", + "extensions": [ + "go.sum" + ], + "aliases": [ + "Go Checksum File" + ] + } + ], + "grammars": [ + { + "language": "go.mod", + "scopeName": "go.mod", + "path": "./syntaxes/go.mod.tmGrammar.json" + }, + { + "language": "go.sum", + "scopeName": "go.sum", + "path": "./syntaxes/go.sum.tmGrammar.json" } ], "snippets": [ diff --git a/syntaxes/go.mod.tmGrammar.json b/syntaxes/go.mod.tmGrammar.json new file mode 100644 index 00000000..17af25a6 --- /dev/null +++ b/syntaxes/go.mod.tmGrammar.json @@ -0,0 +1,163 @@ +{ + "scopeName": "go.mod", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#directive" + } + ], + "repository": { + "directive": { + "patterns": [ + { + "comment": "Multi-Line directive", + "begin": "(\\w+)\\s+\\(", + "beginCaptures": { + "1": { + "name": "keyword.go.mod" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#arguments" + } + ] + }, + { + "comment": "Single-Line directive", + "match": "(\\w+)\\s+(.*)", + "captures": { + "1": { + "name": "keyword.go.mod" + }, + "2": { + "patterns": [ + { + "include": "#arguments" + } + ] + } + } + } + ] + }, + "arguments": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#double_quoted_string" + }, + { + "include": "#raw_quoted_string" + }, + { + "include": "#operator" + }, + { + "include": "#semver" + }, + { + "include": "#unquoted_string" + } + ] + }, + "comments": { + "patterns": [ + { + "begin": "//", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.go.mod" + } + }, + "end": "$", + "name": "comment.line.double-slash.go.mod" + } + ] + }, + "operator": { + "match": "(=>)", + "name": "operator.go.mod" + }, + "unquoted_string": { + "comment": "Unquoted string", + "match": "[^\\s]+", + "name": "string.unquoted.go.mod" + }, + "double_quoted_string": { + "comment": "Interpreted string literals", + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.go.mod" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.go.mod" + } + }, + "name": "string.quoted.double", + "patterns": [ + { + "include": "#string_escaped_char" + }, + { + "include": "#string_placeholder" + } + ] + }, + "raw_quoted_string": { + "comment": "Raw string literals", + "begin": "`", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.go.mod" + } + }, + "end": "`", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.go.mod" + } + }, + "name": "string.quoted.raw", + "patterns": [ + { + "include": "#string_placeholder" + } + ] + }, + "semver": { + "comment": "Semver version strings (v1.2.3)", + "match": "v(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\da-z-]+(?:\\.[\\da-z-]+)*)?(?:\\+[\\da-z-]+(?:\\.[\\da-z-]+)*)?", + "name": "constant.language.go.mod" + }, + "string_escaped_char": { + "patterns": [ + { + "match": "\\\\([0-7]{3}|[abfnrtv\\\\'\"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})", + "name": "constant.character.escape.go.mod" + }, + { + "match": "\\\\[^0-7xuUabfnrtv\\'\"]", + "name": "invalid.illegal.unknown-escape.go.mod" + } + ] + }, + "string_placeholder": { + "patterns": [ + { + "match": "%(\\[\\d+\\])?([\\+#\\-0\\x20]{,2}((\\d+|\\*)?(\\.?(\\d+|\\*|(\\[\\d+\\])\\*?)?(\\[\\d+\\])?)?))?[vT%tbcdoqxXUbeEfFgGsp]", + "name": "constant.other.placeholder.go.mod" + } + ] + } + } +} \ No newline at end of file diff --git a/syntaxes/go.sum.tmGrammar.json b/syntaxes/go.sum.tmGrammar.json new file mode 100644 index 00000000..c6190058 --- /dev/null +++ b/syntaxes/go.sum.tmGrammar.json @@ -0,0 +1,44 @@ +{ + "scopeName": "go.sum", + "patterns": [ + { + "include": "#checksum" + }, + { + "include": "#semver" + }, + { + "include": "#unquoted_string" + } + ], + "repository": { + "checksum": { + "comment": "Checksum", + "match": "h1:([^\\s]+)=", + "captures": { + "1": { + "patterns": [ + { + "match": "[a-zA-Z\\d+\\/]{43}", + "name": "string.unquoted.go.sum" + }, + { + "match": ".*", + "name": "invalid.illegal.unknown-hash.go.sum" + } + ] + } + } + }, + "semver": { + "comment": "Semver version strings (v1.2.3)", + "match": "v(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\da-z-]+(?:\\.[\\da-z-]+)*)?(?:\\+[\\da-z-]+(?:\\.[\\da-z-]+)*)?", + "name": "constant.language.go.sum" + }, + "unquoted_string": { + "comment": "Unquoted string", + "match": "[^\\s]+", + "name": "string.unquoted.go.sum" + } + } +} \ No newline at end of file