From e0b6f7b860df4d26e603ae68f956d39a8d85d36f Mon Sep 17 00:00:00 2001 From: bryn austin bellomy Date: Sun, 22 Nov 2015 08:15:26 -0600 Subject: [PATCH] Refinements to GoSublime-Go syntax --- syntax/GoSublime-Go.YAML-tmLanguage | 581 +++++++++ syntax/GoSublime-Go.tmLanguage | 1713 ++++++++++++++++++++++++--- syntax/GoSublime-Go.tmLanguage.json | 1307 ++++++++++++++++---- 3 files changed, 3218 insertions(+), 383 deletions(-) create mode 100644 syntax/GoSublime-Go.YAML-tmLanguage diff --git a/syntax/GoSublime-Go.YAML-tmLanguage b/syntax/GoSublime-Go.YAML-tmLanguage new file mode 100644 index 00000000..10627f1a --- /dev/null +++ b/syntax/GoSublime-Go.YAML-tmLanguage @@ -0,0 +1,581 @@ +# [PackageDev] target_format: json, ext: tmLanguage.json +# [PackageDev] target_format: plist, ext: tmLanguage + +name: 'GoSublime' +scopeName: source.go +fileTypes: [go] +uuid: 1ceaa75c-b61d-11e2-ba93-138feb5db969 + +patterns: +- include: '#comments' +- include: '#strings' + + +- include: '#struct-literal' + +- name: meta.function.method.go + begin: (?=\bfunc\s+\() + end: (?=\{) + patterns: + - match: \b(func)\s+(\()\s*([A-Za-z0-9_]+)\s+(\*)?\s*([[:alnum:]_]+)\s*(\))\s+([a-zA-Z0-9_]+) + captures: + '1': {name: storage.type.function.go} + '2': {name: punctuation.definition.method.go} + '3': {name: variable.language.this.go} + '4': {name: punctuation.definition.method.go} + '5': {name: storage.type.go} + '6': {name: punctuation.definition.method.go} + '7': {name: entity.name.function.go} + - begin: \( + end: \) + beginCaptures: { '0': {name: punctuation.definition.method.go} } + endCaptures: { '0': {name: punctuation.definition.method.go} } + patterns: + - include: '#types' + - match: \b([a-zA-Z0-9_]+)[\s\t]+((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)\b + captures: + '1': {name: variable.parameter.go} + '2': {name: storage.type.go} + '3': {name: punctuation.definition.type.pointer.go} + '4': {name: entity.name.package.go} + '5': {name: punctuation.definition.type.go} + - match: \b[a-zA-Z0-9_]+\b + name: variable.parameter.go + - name: punctuation.definition.param-list.go + match: ',' + + +- include: '#literals' + + +- include: '#keywords' +# - include: '#types' + + + + +- comment: This matches the 'x := 0' style of variable declaration. + name: meta.initialization.short.go + match: (?:[[:alpha:]_][[:alnum:]_]*)(?:,\s+[[:alpha:]_][[:alnum:]_]*)*\s*(:=) + captures: + '0': {name: variable.other.go} + '1': {name: keyword.operator.initialize.go} + +- name: storage.type.function.go + match: \b(func)\b + +- name: entity.name.function.go + match: (?<=(\Afunc|...\))\s)\b(\w+)\b(?=\() + +- name: entity.name.function.go + match: (?<=(\sfunc|....\))\s)\b(\w+)\b(?=\() + +- name: entity.name.function.go + match: (?<=(\Afunc|...\))\s)\b(\w+)\b(?=\() + +- include: '#type-block' +- include: '#type-statement' + +- include: '#var-and-const-blocks' +- include: '#var-and-const-statements' + +# - name: entity.name.type.go +# match: (?<=\Atype\s)\b(\w+)\b + +# - name: entity.name.type.go +# match: (?<=\stype\s)\b(\w+)\b + +- name: support.function.builtin.go + match: \b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\b + +# - name: support.function.go +# match: \b(\w+)\b(?=\() + + +- include: '#function-call' +- include: '#variable-dot-access' + +- include: '#assignment-expr' + +- include: '#operators' + +- include: '#punctuation' + +repository: + types: + patterns: + - include: '#storage-types' + + storage-types: + patterns: + - include: '#interface-type' + - include: '#chan-type' + - include: '#slice-type' + - include: '#map-type' + - include: '#struct-type' + - include: '#builtin-type' + - comment: userland type + match: \b(\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+\b + captures: + '1': {name: punctuation.definition.type.pointer.go} + '2': {name: entity.name.package.go} + '3': {name: punctuation.definition.type.go} + + + + builtin-type: + patterns: + - name: storage.type.builtin.go + match: \b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\b + + + slice-type: + patterns: + - name: storage.type.slice.go + begin: (\[\]) + end: (?=\s|$) + beginCaptures: { '1': {name: punctuation.declaration.slice.go} } + patterns: + - include: '#types' + + chan-type: + patterns: + - name: storage.type.chan.go + begin: (\<\-\s?)?chan(\s?\<\-)?[\s\t] + end: (?=\s|\t|$|,|;|\}) + beginCaptures: + '1': {name: punctuation.declaration.chan.go} + '2': {name: punctuation.declaration.chan.go} + patterns: + - include: '#types' + + map-type: + patterns: + - name: storage.type.map.go + match: (map)(\[)(\w+)(\]) + captures: + '1': {name: storage.type.go} + '2': {name: punctuation.definition.type.go} + '3': {name: storage.type.go} + '4': {name: punctuation.definition.type.go} + + struct-type: + patterns: + - name: meta.declaration.struct.go + begin: \b(struct)\s*(\{) + beginCaptures: + '1': {name: storage.type.go} + '2': {name: punctuation.declaration.struct.begin.go} + end: (\}) + endCaptures: + '1': {name: punctuation.declaration.struct.end.go} + patterns: + - include: '#comments' + - include: '#struct-field' + - include: '#embedded-type' + - include: '#struct-tags' + - include: '#function-call' + - include: '#variable-dot-access' + - match: (\*) + captures: { '1': {name: punctuation.definition.type.pointer.go} } + - match: (\.) + captures: { '1': {name: punctuation.definition.type.go} } + + + interface-type: + patterns: + - name: meta.declaration.interface.go + begin: \b(interface)\s*(\{) + beginCaptures: + '1': {name: storage.type.go} + '2': {name: punctuation.declaration.interface.begin.go} + end: (\}) + endCaptures: + '1': {name: punctuation.declaration.interface.end.go} + patterns: + - begin: \b([a-zA-Z0-9_]+)(\() + beginCaptures: + '1': {name: entity.name.function.go} + '2': {name: punctuation.definition.function.go} + end: (\)) + endCaptures: + '1': {name: punctuation.definition.function.go} + + - include: '#comments' + - include: '#types' + - include: '#embedded-type' + - match: (\*) + captures: { '1': {name: punctuation.definition.type.pointer.go} } + - match: (\.) + captures: { '1': {name: punctuation.definition.type.go} } + + + embedded-type: + patterns: + - name: meta.declaration.field.embedded.go + match: ^[\s\t]*((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)[\s\t]*$ + captures: + '1': {name: storage.type.go} + '2': {name: punctuation.definition.type.pointer.go} + '3': {name: entity.name.package.go} + '4': {name: punctuation.name.type.go} + + + struct-field: + patterns: + - name: meta.definition.struct-field.go + contentName: storage.type.go + begin: ^[\s\t]*([a-zA-Z0-9_]+)[\s\t]+ + end: (?=$|`) + beginCaptures: + '1': {name: variable.struct-field.go} + patterns: + - include: '#comments' + - include: '#types' + + + struct-tags: + patterns: + - name: string.tag.struct-field.go + begin: (`) + end: (`) + beginCaptures: { '1': {name: punctuation.definition.string.begin.go} } + endCaptures: { '1': {name: punctuation.definition.string.end.go} } + patterns: + - match: \b([a-z]+)(:) + captures: + '1': {name: entity.name.tag.struct-field.go} + '2': {name: punctuation.definition.tag.struct-field.go} + + + array-definition: + patterns: + - name: meta.definition.array.go + match: \b(\[\])(&)?(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\s*(?=\{) + captures: + '1': {name: punctuation.definition.array.go} + '2': {name: punctuation.definition.array.go} + '3': {name: support.type.builtin.go} + + + variable-dot-access: + patterns: + - name: variable.dot-access.go + match: (?<=\.)([A-Za-z0-9_]+)(?=\s*[^\(]) + + + struct-declaration: + patterns: + - begin: ([a-zA-Z0-9_]+)\s+(?=struct\b) + end: $ + beginCaptures: { '1': {name: entity.name.type.go} } + patterns: + - include: '#struct-type' + + + interface-declaration: + patterns: + - begin: ([a-zA-Z0-9_]+)\s+(?=interface\b) + end: $ + beginCaptures: { '1': {name: entity.name.type.go} } + patterns: + - include: '#interface-type' + + + type-block: + patterns: + - name: meta.type-block.go + begin: \b(type)[\s\t]*(\() + beginCaptures: + '1': {name: keyword.other.go} + '2': {name: punctuation.definition.type-block.begin.go} + end: (\)) + endCaptures: + '1': {name: punctuation.definition.type-block.end.go} + patterns: + - include: '#comments' + - include: '#struct-declaration' + - include: '#interface-declaration' + - match: ^[\s\t]*([a-zA-Z0-9_]+)[\s\t]+((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)[\s\t]*$ + captures: + '1': {name: entity.name.type.go} + '2': {name: storage.type.go} + '3': {name: punctuation.definition.type.pointer.go} + '4': {name: entity.name.package.go} + '5': {name: punctuation.name.type.go} + + - begin: \b([a-zA-Z0-9_]+)[\s\t]+(?=[a-zA-Z0-9_\<\[\*]) + beginCaptures: + '1': {name: entity.name.type.go} + end: $ + patterns: + - include: '#types' + - match: \b((\*)?([a-zA-Z0-9_])?(\.)[a-zA-Z0-9_]+)\b + captures: + '1': {name: storage.type.go} + '2': {name: punctuation.definition.type.pointer.go} + '3': {name: entity.name.package.go} + '4': {name: punctuation.definition.type.go} + + + type-statement: + patterns: + - begin: \b(type)[\s\t]+([a-zA-Z0-9_]+)[\s\t]+ + beginCaptures: + '1': {name: keyword.other.go} + '2': {name: entity.name.type.go} + end: $ + patterns: + - include: '#types' + + + var-and-const-statements: + patterns: + - begin: \b(var|const)[\s\t]+([a-zA-Z0-9_]+)[\s\t]* + beginCaptures: + '1': {name: keyword.other.go} + '2': {name: variable.other.go} + end: $ + patterns: + - include: '#assignment-expr' + - include: '#types' + + var-and-const-blocks: + patterns: + - contentName: meta.block.var.go + begin: \b(var|const)[\s\t]*(\() + beginCaptures: + '1': {name: keyword.other.go} + '2': {name: punctuation.definition.var-block.begin.go} + end: (\)) + endCaptures: + '1': {name: punctuation.definition.var-block.end.go} + patterns: + - include: '#comments' + - include: '#assignment-expr' + - match: \b([a-zA-Z0-9_]+)\b + name: variable.other.go + - include: '#types' + + assignment-expr: + patterns: + - name: meta.assignment-expr.go + begin: \s(=)[\s\t]+ + beginCaptures: { '1': {name: keyword.operator.assignment.go} } + end: $ + patterns: + - include: '#comments' + - include: '#expressions' + - include: '#types' + + function-call: + patterns: + - name: meta.function-call.go + begin: \b(?:[a-zA-Z0-9_]+(\.))*([a-zA-Z0-9_]+)(\() + beginCaptures: + # '1': {name: variable.dot-access.go} + '1': {name: punctuation.separator.dot-access.go} + '2': {name: entity.name.function.go} + '3': {name: punctuation.separator.function-call.begin.go} + end: (\)) + endCaptures: + '1': {name: punctuation.separator.function-call.end.go} + patterns: + - include: '#comments' + - include: '#expressions' + + keywords: + patterns: + - comment: A subset of keyword.other.go for flow control keywords. + name: keyword.control.go + match: \b(break|case|continue|default|defer|else|fallthrough|for|go|goto|if|range|return|select|switch)\b + + - name: keyword.other.go + match: \b(import|package)\b + + + expressions: + patterns: + - include: '#function-call' + - include: '#literals' + + operators: + patterns: + - name: keyword.operator.channel.go + match: (<-) + + - name: keyword.operator.comparison.go + match: (==|!=|<|<=|>|>=) + + - name: keyword.operator.logical.go + match: (&&|[|]{2}|!) + + - name: keyword.operator.increment.go + match: ([+]{2}) + + - name: keyword.operator.decrement.go + match: (--) + + # - name: keyword.operator.assignment.go + # match: (=|(?:[+]|-|[|]|^|[*]|/|%|<<|>>|&|&^)=) + + - name: keyword.operator.arithmetic.go + match: ([+]|-|[*]|/|%|&|[|]|^|&^|<<|>>) + + - name: keyword.operator.semi-colon.go + match: (;) + + literals: + patterns: + - include: '#struct-literal' + - include: '#slice-literal' + - include: '#strings' + - include: '#constants' + - include: '#pointer-literal' + + pointer-literal: + patterns: + - name: meta.literal.pointer.go + begin: (&) + beginCaptures: + '1': {name: punctuation.definition.pointer.go} + end: (?=[^a-zA-Z0-9_\.]) + patterns: + - include: '#struct-literal' + - include: '#slice-literal' + + struct-literal: + patterns: + - name: meta.literal.struct.go + begin: (&)?(?:([a-zA-Z0-9_]+)(\.))?([A-Za-z0-9_]+)(\{) + beginCaptures: + '1': {name: punctuation.definition.pointer.go} + '2': {name: entity.name.package.go} + '3': {name: punctuation.definition.type.go} + '4': {name: storage.type.go} + '5': {name: punctuation.definition.struct.begin.go} + end: (\}) + endCaptures: + '1': {name: punctuation.definition.struct.end.go} + patterns: + - include: '#struct-literal-field' + - include: '#comments' + - include: '#expressions' + - include: '#types' + - match: (,) + name: punctuation.separator.mapping.go + + + struct-literal-field: + patterns: + - match: \b(?:([a-zA-Z0-9_]+)\s*(:))? + captures: + '1': {name: variable.definition.struct-field.go} + '2': {name: punctuation.definition.struct-field.go} + + slice-literal: + patterns: + - name: meta.literal.slice.go + begin: (\[\])?(\*)?(?:([a-zA-Z0-9_]+)(\.))?([A-Za-z0-9_]+)(\{) + beginCaptures: + '1': {name: punctuation.definition.slice.go} + '2': {name: punctuation.definition.pointer.go} + '3': {name: entity.name.package.go} + '4': {name: punctuation.definition.type.go} + '5': {name: storage.type.go} + '6': {name: punctuation.definition.slice.begin.go} + end: (\}) + endCaptures: + '1': {name: punctuation.definition.slice.end.go} + patterns: + - include: '#comments' + - include: '#expressions' + - match: (,) + name: punctuation.separator.sequence.go + + string_escaped_char: + patterns: + - name: constant.character.escape.go + match: \\(\\|[abfnrtv'"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}) + - name: invalid.illegal.unknown-escape.go + match: \\. + + string_placeholder: + patterns: + - name: constant.other.placeholder.go + match: |- + (?x)% + (\d+\$)? # field (argument #) + [#0\- +']* # flags + [,;:_]? # separator character (AltiVec) + ((-?\d+)|\*(-?\d+\$)?)? # minimum field width + (\.((-?\d+)|\*(-?\d+\$)?)?)? # precision + [diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type + + + constants: + patterns: + - name: constant.language.go + match: \b(true|false|nil|iota)\b + + - name: constant.numeric.floating-point.go + match: \b((\d+\.(\d+)?([eE][+-]?\d+)?|\d+[eE][+-]?\d+|\.\d+([eE][+-]?\d+)?)i?)\b + + - name: constant.numeric.integer.go + match: \b(\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\b + + - name: constant.other.rune.go + match: '''(?:[^''\\]|\\(?:\\|[abfnrtv'']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))''' + + strings: + patterns: + - name: string.quoted.double.go + begin: '"' + beginCaptures: + '0': {name: punctuation.definition.string.begin.go} + end: '"' + endCaptures: + '0': {name: punctuation.definition.string.end.go} + patterns: + - include: '#string_placeholder' + - include: '#string_escaped_char' + + - name: string.quoted.raw.go + begin: '`' + beginCaptures: + '0': {name: punctuation.definition.string.begin.go} + end: '`' + endCaptures: + '0': {name: punctuation.definition.string.end.go} + patterns: + - include: '#string_placeholder' + - include: source.gotemplate + + + punctuation: + patterns: + - name: punctuation.definition.comma.go + match: (,) + + - name: punctuation.definition.dot.go + match: ([.]) + + - name: punctuation.definition.colon.go + match: (:) + + - name: punctuation.definition.bracket.go + match: (\[|\]|{|}|\(|\)) + + comments: + patterns: + - name: comment.block.go + begin: /\* + end: \*/ + + - name: comment.line.double-slash.go + begin: // + end: \z + + +firstLineMatch: -[*]-( Mode:)? Go -[*]- +keyEquivalent: ^~G diff --git a/syntax/GoSublime-Go.tmLanguage b/syntax/GoSublime-Go.tmLanguage index 8ccf2def..2d2e1021 100755 --- a/syntax/GoSublime-Go.tmLanguage +++ b/syntax/GoSublime-Go.tmLanguage @@ -2,8 +2,6 @@ - comment - Based on work from github.com/frou/GoFeather and github.com/DisposaBoy/GoSublime fileTypes go @@ -13,271 +11,985 @@ keyEquivalent ^~G name - GoSublime: Go + GoSublime patterns - begin - /\* - end - \*/ - name - comment.block.go + include + #comments - begin - // - end - \z - name - comment.line.double-slash.go + include + #strings + + + include + #struct-literal begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.go - - + (?=\bfunc\s+\() end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.go - - + (?=\{) name - string.quoted.double.go + meta.function.method.go patterns - include - #string_placeholder + captures + + 1 + + name + storage.type.function.go + + 2 + + name + punctuation.definition.method.go + + 3 + + name + variable.language.this.go + + 4 + + name + punctuation.definition.method.go + + 5 + + name + storage.type.go + + 6 + + name + punctuation.definition.method.go + + 7 + + name + entity.name.function.go + + + match + \b(func)\s+(\()\s*([A-Za-z0-9_]+)\s+(\*)?\s*([[:alnum:]_]+)\s*(\))\s+([a-zA-Z0-9_]+) - include - #string_escaped_char + begin + \( + beginCaptures + + 0 + + name + punctuation.definition.method.go + + + end + \) + endCaptures + + 0 + + name + punctuation.definition.method.go + + + patterns + + + include + #types + + + captures + + 1 + + name + variable.parameter.go + + 2 + + name + storage.type.go + + 3 + + name + punctuation.definition.type.pointer.go + + 4 + + name + entity.name.package.go + + 5 + + name + punctuation.definition.type.go + + + match + \b([a-zA-Z0-9_]+)[\s\t]+((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)\b + + + match + \b[a-zA-Z0-9_]+\b + name + variable.parameter.go + + + match + , + name + punctuation.definition.param-list.go + + - begin - ` - beginCaptures + include + #literals + + + include + #keywords + + + captures 0 name - punctuation.definition.string.begin.go + variable.other.go - - end - ` - endCaptures - - 0 + 1 name - punctuation.definition.string.end.go + keyword.operator.initialize.go + comment + This matches the 'x := 0' style of variable declaration. + match + (?:[[:alpha:]_][[:alnum:]_]*)(?:,\s+[[:alpha:]_][[:alnum:]_]*)*\s*(:=) name - string.quoted.raw.go - patterns - - - include - #string_placeholder - - - include - source.gotemplate - - + meta.initialization.short.go match - \b(true|false|nil|iota)\b + \b(func)\b name - constant.language.go + storage.type.function.go match - \b((\d+\.(\d+)?([eE][+-]?\d+)?|\d+[eE][+-]?\d+|\.\d+([eE][+-]?\d+)?)i?)\b + (?<=(\Afunc|...\))\s)\b(\w+)\b(?=\() name - constant.numeric.floating-point.go + entity.name.function.go match - \b(\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\b + (?<=(\sfunc|....\))\s)\b(\w+)\b(?=\() name - constant.numeric.integer.go + entity.name.function.go match - '(?:[^'\\]|\\(?:\\|[abfnrtv']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))' + (?<=(\Afunc|...\))\s)\b(\w+)\b(?=\() name - constant.other.rune.go + entity.name.function.go - match - \b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\b - name - storage.type.go + include + #type-block - comment - A subset of keyword.other.go for flow control keywords. - match - \b(break|case|continue|default|defer|else|for|go|goto|if|range|return|select|switch)\b - name - keyword.control.go + include + #type-statement + + + include + #var-and-const-blocks + + + include + #var-and-const-statements match - \b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b + \b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\b name - keyword.other.go + support.function.builtin.go - captures - - 0 + include + #function-call + + + include + #variable-dot-access + + + include + #assignment-expr + + + include + #operators + + + include + #punctuation + + + repository + + array-definition + + patterns + + captures + + 1 + + name + punctuation.definition.array.go + + 2 + + name + punctuation.definition.array.go + + 3 + + name + support.type.builtin.go + + + match + \b(\[\])(&)?(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\s*(?=\{) name - variable.other.go + meta.definition.array.go - 1 + + + assignment-expr + + patterns + + begin + \s(=)[\s\t]+ + beginCaptures + + 1 + + name + keyword.operator.assignment.go + + + end + $ name - keyword.operator.initialize.go + meta.assignment-expr.go + patterns + + + include + #comments + + + include + #expressions + + + include + #types + + - - comment - This matches the 'x := 0' style of variable declaration. - match - (?:[[:alpha:]_][[:alnum:]_]*)(?:,\s+[[:alpha:]_][[:alnum:]_]*)*\s*(:=) - name - meta.initialization.short.go + + builtin-type - match - (?<=(\Afunc|...\))\s)\b(\w+)\b(?=\() - name - entity.name.function.go + patterns + + + match + \b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\b + name + storage.type.builtin.go + + + chan-type - match - (?<=(\sfunc|....\))\s)\b(\w+)\b(?=\() - name - entity.name.function.go + patterns + + + begin + (\<\-\s?)?chan(\s?\<\-)?[\s\t] + beginCaptures + + 1 + + name + punctuation.declaration.chan.go + + 2 + + name + punctuation.declaration.chan.go + + + end + (?=\s|\t|$|,|;|\}) + name + storage.type.chan.go + patterns + + + include + #types + + + + + comments - match - (?<=\Atype\s)\b(\w+)\b - name - entity.name.type.go + patterns + + + begin + /\* + end + \*/ + name + comment.block.go + + + begin + // + end + \z + name + comment.line.double-slash.go + + + constants - match - (?<=\stype\s)\b(\w+)\b - name - entity.name.type.go + patterns + + + match + \b(true|false|nil|iota)\b + name + constant.language.go + + + match + \b((\d+\.(\d+)?([eE][+-]?\d+)?|\d+[eE][+-]?\d+|\.\d+([eE][+-]?\d+)?)i?)\b + name + constant.numeric.floating-point.go + + + match + \b(\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\b + name + constant.numeric.integer.go + + + match + '(?:[^'\\]|\\(?:\\|[abfnrtv']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))' + name + constant.other.rune.go + + + embedded-type - match - \b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\b - name - support.function.builtin.go + patterns + + + captures + + 1 + + name + storage.type.go + + 2 + + name + punctuation.definition.type.pointer.go + + 3 + + name + entity.name.package.go + + 4 + + name + punctuation.name.type.go + + + match + ^[\s\t]*((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)[\s\t]*$ + name + meta.declaration.field.embedded.go + + + expressions - match - \b(\w+)\b(?=\() - name - support.function.go + patterns + + + include + #function-call + + + include + #literals + + + function-call - match - (<-) - name - keyword.operator.channel.go + patterns + + + begin + \b(?:[a-zA-Z0-9_]+(\.))*([a-zA-Z0-9_]+)(\() + beginCaptures + + 1 + + name + punctuation.separator.dot-access.go + + 2 + + name + entity.name.function.go + + 3 + + name + punctuation.separator.function-call.begin.go + + + end + (\)) + endCaptures + + 1 + + name + punctuation.separator.function-call.end.go + + + name + meta.function-call.go + patterns + + + include + #comments + + + include + #expressions + + + + + interface-declaration - match - (==|!=|<|<=|>|>=) - name - keyword.operator.comparison.go + patterns + + + begin + ([a-zA-Z0-9_]+)\s+(?=interface\b) + beginCaptures + + 1 + + name + entity.name.type.go + + + end + $ + patterns + + + include + #interface-type + + + + + interface-type - match - (&&|[|]{2}|!) - name - keyword.operator.logical.go + patterns + + + begin + \b(interface)\s*(\{) + beginCaptures + + 1 + + name + storage.type.go + + 2 + + name + punctuation.declaration.interface.begin.go + + + end + (\}) + endCaptures + + 1 + + name + punctuation.declaration.interface.end.go + + + name + meta.declaration.interface.go + patterns + + + begin + \b([a-zA-Z0-9_]+)(\() + beginCaptures + + 1 + + name + entity.name.function.go + + 2 + + name + punctuation.definition.function.go + + + end + (\)) + endCaptures + + 1 + + name + punctuation.definition.function.go + + + + + include + #comments + + + include + #types + + + include + #embedded-type + + + captures + + 1 + + name + punctuation.definition.type.pointer.go + + + match + (\*) + + + captures + + 1 + + name + punctuation.definition.type.go + + + match + (\.) + + + + + keywords - match - ([+]{2}) - name - keyword.operator.increment.go + patterns + + + comment + A subset of keyword.other.go for flow control keywords. + match + \b(break|case|continue|default|defer|else|fallthrough|for|go|goto|if|range|return|select|switch)\b + name + keyword.control.go + + + match + \b(import|package)\b + name + keyword.other.go + + + literals - match - (--) - name - keyword.decrement.go + patterns + + + include + #struct-literal + + + include + #slice-literal + + + include + #strings + + + include + #constants + + + include + #pointer-literal + + + map-type - match - (=|(?:[+]|-|[|]|^|[*]|/|%|<<|>>|&|&^)=) - name - keyword.operator.assignment.go + patterns + + + captures + + 1 + + name + storage.type.go + + 2 + + name + punctuation.definition.type.go + + 3 + + name + storage.type.go + + 4 + + name + punctuation.definition.type.go + + + match + (map)(\[)(\w+)(\]) + name + storage.type.map.go + + + operators - match - ([+]|-|[*]|/|%|&|[|]|^|&^|<<|>>) - name - keyword.operator.arithmetic.go + patterns + + + match + (<-) + name + keyword.operator.channel.go + + + match + (==|!=|<|<=|>|>=) + name + keyword.operator.comparison.go + + + match + (&&|[|]{2}|!) + name + keyword.operator.logical.go + + + match + ([+]{2}) + name + keyword.operator.increment.go + + + match + (--) + name + keyword.operator.decrement.go + + + match + ([+]|-|[*]|/|%|&|[|]|^|&^|<<|>>) + name + keyword.operator.arithmetic.go + + + match + (;) + name + keyword.operator.semi-colon.go + + + pointer-literal - match - (;) - name - keyword.operator.semi-colon.go + patterns + + + begin + (&) + beginCaptures + + 1 + + name + punctuation.definition.pointer.go + + + end + (?=[^a-zA-Z0-9_\.]) + name + meta.literal.pointer.go + patterns + + + include + #struct-literal + + + include + #slice-literal + + + + + punctuation - match - (,) - name - punctuation.definition.comma.go + patterns + + + match + (,) + name + punctuation.definition.comma.go + + + match + ([.]) + name + punctuation.definition.dot.go + + + match + (:) + name + punctuation.definition.colon.go + + + match + (\[|\]|{|}|\(|\)) + name + punctuation.definition.bracket.go + + + slice-literal - match - ([.]) - name - punctuation.definition.dot.go + patterns + + + begin + (\[\])?(\*)?(?:([a-zA-Z0-9_]+)(\.))?([A-Za-z0-9_]+)(\{) + beginCaptures + + 1 + + name + punctuation.definition.slice.go + + 2 + + name + punctuation.definition.pointer.go + + 3 + + name + entity.name.package.go + + 4 + + name + punctuation.definition.type.go + + 5 + + name + storage.type.go + + 6 + + name + punctuation.definition.slice.begin.go + + + end + (\}) + endCaptures + + 1 + + name + punctuation.definition.slice.end.go + + + name + meta.literal.slice.go + patterns + + + include + #comments + + + include + #expressions + + + match + (,) + name + punctuation.separator.sequence.go + + + + + slice-type - match - (:) - name - punctuation.definition.colon.go + patterns + + + begin + (\[\]) + beginCaptures + + 1 + + name + punctuation.declaration.slice.go + + + end + (?=\s|$) + name + storage.type.slice.go + patterns + + + include + #types + + + + + storage-types - match - (\[|\]|{|}|\(|\)) - name - punctuation.definition.bracket.go + patterns + + + include + #interface-type + + + include + #chan-type + + + include + #slice-type + + + include + #map-type + + + include + #struct-type + + + include + #builtin-type + + + captures + + 1 + + name + punctuation.definition.type.pointer.go + + 2 + + name + entity.name.package.go + + 3 + + name + punctuation.definition.type.go + + + comment + userland type + match + \b(\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+\b + + - - repository - string_escaped_char patterns @@ -303,22 +1015,669 @@ match (?x)% - (\d+\$)? # field (argument #) - [#0\- +']* # flags - [,;:_]? # separator character (AltiVec) - ((-?\d+)|\*(-?\d+\$)?)? # minimum field width - (\.((-?\d+)|\*(-?\d+\$)?)?)? # precision - [diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type - +(\d+\$)? # field (argument #) +[#0\- +']* # flags +[,;:_]? # separator character (AltiVec) +((-?\d+)|\*(-?\d+\$)?)? # minimum field width +(\.((-?\d+)|\*(-?\d+\$)?)?)? # precision +[diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type name constant.other.placeholder.go + strings + + patterns + + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.go + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.go + + + name + string.quoted.double.go + patterns + + + include + #string_placeholder + + + include + #string_escaped_char + + + + + begin + ` + beginCaptures + + 0 + + name + punctuation.definition.string.begin.go + + + end + ` + endCaptures + + 0 + + name + punctuation.definition.string.end.go + + + name + string.quoted.raw.go + patterns + + + include + #string_placeholder + + + include + source.gotemplate + + + + + + struct-declaration + + patterns + + + begin + ([a-zA-Z0-9_]+)\s+(?=struct\b) + beginCaptures + + 1 + + name + entity.name.type.go + + + end + $ + patterns + + + include + #struct-type + + + + + + struct-field + + patterns + + + begin + ^[\s\t]*([a-zA-Z0-9_]+)[\s\t]+ + beginCaptures + + 1 + + name + variable.struct-field.go + + + contentName + storage.type.go + end + (?=$|`) + name + meta.definition.struct-field.go + patterns + + + include + #comments + + + include + #types + + + + + + struct-literal + + patterns + + + begin + (&)?(?:([a-zA-Z0-9_]+)(\.))?([A-Za-z0-9_]+)(\{) + beginCaptures + + 1 + + name + punctuation.definition.pointer.go + + 2 + + name + entity.name.package.go + + 3 + + name + punctuation.definition.type.go + + 4 + + name + storage.type.go + + 5 + + name + punctuation.definition.struct.begin.go + + + end + (\}) + endCaptures + + 1 + + name + punctuation.definition.struct.end.go + + + name + meta.literal.struct.go + patterns + + + include + #struct-literal-field + + + include + #comments + + + include + #expressions + + + include + #types + + + match + (,) + name + punctuation.separator.mapping.go + + + + + + struct-literal-field + + patterns + + + captures + + 1 + + name + variable.definition.struct-field.go + + 2 + + name + punctuation.definition.struct-field.go + + + match + \b(?:([a-zA-Z0-9_]+)\s*(:))? + + + + struct-tags + + patterns + + + begin + (`) + beginCaptures + + 1 + + name + punctuation.definition.string.begin.go + + + end + (`) + endCaptures + + 1 + + name + punctuation.definition.string.end.go + + + name + string.tag.struct-field.go + patterns + + + captures + + 1 + + name + entity.name.tag.struct-field.go + + 2 + + name + punctuation.definition.tag.struct-field.go + + + match + \b([a-z]+)(:) + + + + + + struct-type + + patterns + + + begin + \b(struct)\s*(\{) + beginCaptures + + 1 + + name + storage.type.go + + 2 + + name + punctuation.declaration.struct.begin.go + + + end + (\}) + endCaptures + + 1 + + name + punctuation.declaration.struct.end.go + + + name + meta.declaration.struct.go + patterns + + + include + #comments + + + include + #struct-field + + + include + #embedded-type + + + include + #struct-tags + + + include + #function-call + + + include + #variable-dot-access + + + captures + + 1 + + name + punctuation.definition.type.pointer.go + + + match + (\*) + + + captures + + 1 + + name + punctuation.definition.type.go + + + match + (\.) + + + + + + type-block + + patterns + + + begin + \b(type)[\s\t]*(\() + beginCaptures + + 1 + + name + keyword.other.go + + 2 + + name + punctuation.definition.type-block.begin.go + + + end + (\)) + endCaptures + + 1 + + name + punctuation.definition.type-block.end.go + + + name + meta.type-block.go + patterns + + + include + #comments + + + include + #struct-declaration + + + include + #interface-declaration + + + captures + + 1 + + name + entity.name.type.go + + 2 + + name + storage.type.go + + 3 + + name + punctuation.definition.type.pointer.go + + 4 + + name + entity.name.package.go + + 5 + + name + punctuation.name.type.go + + + match + ^[\s\t]*([a-zA-Z0-9_]+)[\s\t]+((\*)?(?:([a-zA-Z0-9_]+)(\.))?[a-zA-Z0-9_]+)[\s\t]*$ + + + begin + \b([a-zA-Z0-9_]+)[\s\t]+(?=[a-zA-Z0-9_\<\[\*]) + beginCaptures + + 1 + + name + entity.name.type.go + + + end + $ + patterns + + + include + #types + + + captures + + 1 + + name + storage.type.go + + 2 + + name + punctuation.definition.type.pointer.go + + 3 + + name + entity.name.package.go + + 4 + + name + punctuation.definition.type.go + + + match + \b((\*)?([a-zA-Z0-9_])?(\.)[a-zA-Z0-9_]+)\b + + + + + + + + type-statement + + patterns + + + begin + \b(type)[\s\t]+([a-zA-Z0-9_]+)[\s\t]+ + beginCaptures + + 1 + + name + keyword.other.go + + 2 + + name + entity.name.type.go + + + end + $ + patterns + + + include + #types + + + + + + types + + patterns + + + include + #storage-types + + + + var-and-const-blocks + + patterns + + + begin + \b(var|const)[\s\t]*(\() + beginCaptures + + 1 + + name + keyword.other.go + + 2 + + name + punctuation.definition.var-block.begin.go + + + contentName + meta.block.var.go + end + (\)) + endCaptures + + 1 + + name + punctuation.definition.var-block.end.go + + + patterns + + + include + #comments + + + include + #assignment-expr + + + match + \b([a-zA-Z0-9_]+)\b + name + variable.other.go + + + include + #types + + + + + + var-and-const-statements + + patterns + + + begin + \b(var|const)[\s\t]+([a-zA-Z0-9_]+)[\s\t]* + beginCaptures + + 1 + + name + keyword.other.go + + 2 + + name + variable.other.go + + + end + $ + patterns + + + include + #assignment-expr + + + include + #types + + + + + + variable-dot-access + + patterns + + + match + (?<=\.)([A-Za-z0-9_]+)(?=\s*[^\(]) + name + variable.dot-access.go + + + scopeName source.go uuid - 1caaa75c-b61d-11e2-ba93-138feb5db969 + 1ceaa75c-b61d-11e2-ba93-138feb5db969 diff --git a/syntax/GoSublime-Go.tmLanguage.json b/syntax/GoSublime-Go.tmLanguage.json index 668fc6f6..b29b0aae 100644 --- a/syntax/GoSublime-Go.tmLanguage.json +++ b/syntax/GoSublime-Go.tmLanguage.json @@ -1,207 +1,1102 @@ { - "comment": "Based on work from github.com/frou/GoFeather and github.com/DisposaBoy/GoSublime", - "fileTypes": [ - "go" - ], - "firstLineMatch": "-[*]-( Mode:)? Go -[*]-", - "keyEquivalent": "^~G", - "name": "GoSublime: Go", - "patterns": [ - { - "begin": "/\\*", - "end": "\\*/", - "name": "comment.block.go" - }, - { - "begin": "//", - "end": "\\z", - "name": "comment.line.double-slash.go" - }, - { - "begin": "\"", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.go" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.go" - } - }, - "name": "string.quoted.double.go", - "patterns": [ - { - "include": "#string_placeholder" - }, - { - "include": "#string_escaped_char" - } - ] - }, - { - "begin": "`", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.go" - } - }, - "end": "`", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.go" - } - }, - "name": "string.quoted.raw.go", - "patterns": [ - { - "include": "#string_placeholder" - }, - { - "include": "source.gotemplate" - } - ] - }, - { - "match": "\\b(true|false|nil|iota)\\b", - "name": "constant.language.go" - }, - { - "match": "\\b((\\d+\\.(\\d+)?([eE][+-]?\\d+)?|\\d+[eE][+-]?\\d+|\\.\\d+([eE][+-]?\\d+)?)i?)\\b", - "name": "constant.numeric.floating-point.go" - }, - { - "match": "\\b(\\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\\b", - "name": "constant.numeric.integer.go" - }, - { - "name": "constant.other.rune.go", - "match": "'(?:[^'\\\\]|\\\\(?:\\\\|[abfnrtv']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))'" - }, - { - "match": "\\b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\\b", - "name": "storage.type.go" - }, - { - "comment": "A subset of keyword.other.go for flow control keywords.", - "match": "\\b(break|case|continue|default|defer|else|for|go|goto|if|range|return|select|switch)\\b", - "name": "keyword.control.go" - }, - { - "match": "\\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\\b", - "name": "keyword.other.go" - }, - { - "captures": { - "0": { - "name": "variable.other.go" - }, - "1": { - "name": "keyword.operator.initialize.go" - } - }, - "comment": "This matches the 'x := 0' style of variable declaration.", - "match": "(?:[[:alpha:]_][[:alnum:]_]*)(?:,\\s+[[:alpha:]_][[:alnum:]_]*)*\\s*(:=)", - "name": "meta.initialization.short.go" - }, - { - "match": "(?<=(\\Afunc|...\\))\\s)\\b(\\w+)\\b(?=\\()", - "name": "entity.name.function.go" - }, - { - "match": "(?<=(\\sfunc|....\\))\\s)\\b(\\w+)\\b(?=\\()", - "name": "entity.name.function.go" - }, - { - "match": "(?<=\\Atype\\s)\\b(\\w+)\\b", - "name": "entity.name.type.go" - }, - { - "match": "(?<=\\stype\\s)\\b(\\w+)\\b", - "name": "entity.name.type.go" - }, - { - "match": "\\b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\\b", - "name": "support.function.builtin.go" - }, - { - "match": "\\b(\\w+)\\b(?=\\()", - "name": "support.function.go" - }, - { - "match": "(<-)", - "name": "keyword.operator.channel.go" - }, - { - "match": "(==|!=|<|<=|>|>=)", - "name": "keyword.operator.comparison.go" - }, - { - "match": "(&&|[|]{2}|!)", - "name": "keyword.operator.logical.go" - }, - { - "match": "([+]{2})", - "name": "keyword.operator.increment.go" - }, - { - "match": "(--)", - "name": "keyword.decrement.go" - }, - { - "match": "(=|(?:[+]|-|[|]|^|[*]|/|%|<<|>>|&|&^)=)", - "name": "keyword.operator.assignment.go" - }, - { - "match": "([+]|-|[*]|/|%|&|[|]|^|&^|<<|>>)", - "name": "keyword.operator.arithmetic.go" - }, - { - "match": "(;)", - "name": "keyword.operator.semi-colon.go" - }, - { - "match": "(,)", - "name": "punctuation.definition.comma.go" - }, - { - "match": "([.])", - "name": "punctuation.definition.dot.go" - }, - { - "match": "(:)", - "name": "punctuation.definition.colon.go" - }, - { - "match": "(\\[|\\]|{|}|\\(|\\))", - "name": "punctuation.definition.bracket.go" - } - ], - // note: keep this in sync with GoTemplate - "repository": { - "string_escaped_char": { - "patterns": [ - { - // note: keep this in sync with constant.other.rune.go - "match": "\\\\(\\\\|[abfnrtv'\"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3})", - "name": "constant.character.escape.go" - }, - { - "match": "\\\\.", - "name": "invalid.illegal.unknown-escape.go" - } - ] - }, - "string_placeholder": { - "patterns": [ - { - "match": "(?x)%\n (\\d+\\$)? # field (argument #)\n [#0\\- +']* # flags\n [,;:_]? # separator character (AltiVec)\n ((-?\\d+)|\\*(-?\\d+\\$)?)? # minimum field width\n (\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)? # precision\n [diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type\n ", - "name": "constant.other.placeholder.go" - } - ] - } - }, - "scopeName": "source.go", - "uuid": "1caaa75c-b61d-11e2-ba93-138feb5db969" -} + "name": "GoSublime", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#struct-literal" + }, + { + "patterns": [ + { + "captures": { + "7": { + "name": "entity.name.function.go" + }, + "6": { + "name": "punctuation.definition.method.go" + }, + "5": { + "name": "storage.type.go" + }, + "4": { + "name": "punctuation.definition.method.go" + }, + "3": { + "name": "variable.language.this.go" + }, + "2": { + "name": "punctuation.definition.method.go" + }, + "1": { + "name": "storage.type.function.go" + } + }, + "match": "\\b(func)\\s+(\\()\\s*([A-Za-z0-9_]+)\\s+(\\*)?\\s*([[:alnum:]_]+)\\s*(\\))\\s+([a-zA-Z0-9_]+)" + }, + { + "beginCaptures": { + "0": { + "name": "punctuation.definition.method.go" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.definition.method.go" + } + }, + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#types" + }, + { + "captures": { + "5": { + "name": "punctuation.definition.type.go" + }, + "4": { + "name": "entity.name.package.go" + }, + "3": { + "name": "punctuation.definition.type.pointer.go" + }, + "2": { + "name": "storage.type.go" + }, + "1": { + "name": "variable.parameter.go" + } + }, + "match": "\\b([a-zA-Z0-9_]+)[\\s\\t]+((\\*)?(?:([a-zA-Z0-9_]+)(\\.))?[a-zA-Z0-9_]+)\\b" + }, + { + "match": "\\b[a-zA-Z0-9_]+\\b", + "name": "variable.parameter.go" + }, + { + "match": ",", + "name": "punctuation.definition.param-list.go" + } + ] + } + ], + "begin": "(?=\\bfunc\\s+\\()", + "name": "meta.function.method.go", + "end": "(?=\\{)" + }, + { + "include": "#literals" + }, + { + "include": "#keywords" + }, + { + "captures": { + "1": { + "name": "keyword.operator.initialize.go" + }, + "0": { + "name": "variable.other.go" + } + }, + "match": "(?:[[:alpha:]_][[:alnum:]_]*)(?:,\\s+[[:alpha:]_][[:alnum:]_]*)*\\s*(:=)", + "name": "meta.initialization.short.go", + "comment": "This matches the 'x := 0' style of variable declaration." + }, + { + "match": "\\b(func)\\b", + "name": "storage.type.function.go" + }, + { + "match": "(?<=(\\Afunc|...\\))\\s)\\b(\\w+)\\b(?=\\()", + "name": "entity.name.function.go" + }, + { + "match": "(?<=(\\sfunc|....\\))\\s)\\b(\\w+)\\b(?=\\()", + "name": "entity.name.function.go" + }, + { + "match": "(?<=(\\Afunc|...\\))\\s)\\b(\\w+)\\b(?=\\()", + "name": "entity.name.function.go" + }, + { + "include": "#type-block" + }, + { + "include": "#type-statement" + }, + { + "include": "#var-and-const-blocks" + }, + { + "include": "#var-and-const-statements" + }, + { + "match": "\\b(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\\b", + "name": "support.function.builtin.go" + }, + { + "include": "#function-call" + }, + { + "include": "#variable-dot-access" + }, + { + "include": "#assignment-expr" + }, + { + "include": "#operators" + }, + { + "include": "#punctuation" + } + ], + "keyEquivalent": "^~G", + "repository": { + "var-and-const-blocks": { + "patterns": [ + { + "contentName": "meta.block.var.go", + "begin": "\\b(var|const)[\\s\\t]*(\\()", + "beginCaptures": { + "2": { + "name": "punctuation.definition.var-block.begin.go" + }, + "1": { + "name": "keyword.other.go" + } + }, + "endCaptures": { + "1": { + "name": "punctuation.definition.var-block.end.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#assignment-expr" + }, + { + "match": "\\b([a-zA-Z0-9_]+)\\b", + "name": "variable.other.go" + }, + { + "include": "#types" + } + ], + "end": "(\\))" + } + ] + }, + "type-block": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.definition.type-block.end.go" + } + }, + "begin": "\\b(type)[\\s\\t]*(\\()", + "name": "meta.type-block.go", + "beginCaptures": { + "2": { + "name": "punctuation.definition.type-block.begin.go" + }, + "1": { + "name": "keyword.other.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#struct-declaration" + }, + { + "include": "#interface-declaration" + }, + { + "captures": { + "5": { + "name": "punctuation.name.type.go" + }, + "4": { + "name": "entity.name.package.go" + }, + "3": { + "name": "punctuation.definition.type.pointer.go" + }, + "2": { + "name": "storage.type.go" + }, + "1": { + "name": "entity.name.type.go" + } + }, + "match": "^[\\s\\t]*([a-zA-Z0-9_]+)[\\s\\t]+((\\*)?(?:([a-zA-Z0-9_]+)(\\.))?[a-zA-Z0-9_]+)[\\s\\t]*$" + }, + { + "beginCaptures": { + "1": { + "name": "entity.name.type.go" + } + }, + "begin": "\\b([a-zA-Z0-9_]+)[\\s\\t]+(?=[a-zA-Z0-9_\\<\\[\\*])", + "end": "$", + "patterns": [ + { + "include": "#types" + }, + { + "captures": { + "4": { + "name": "punctuation.definition.type.go" + }, + "3": { + "name": "entity.name.package.go" + }, + "2": { + "name": "punctuation.definition.type.pointer.go" + }, + "1": { + "name": "storage.type.go" + } + }, + "match": "\\b((\\*)?([a-zA-Z0-9_])?(\\.)[a-zA-Z0-9_]+)\\b" + } + ] + } + ], + "end": "(\\))" + } + ] + }, + "operators": { + "patterns": [ + { + "match": "(<-)", + "name": "keyword.operator.channel.go" + }, + { + "match": "(==|!=|<|<=|>|>=)", + "name": "keyword.operator.comparison.go" + }, + { + "match": "(&&|[|]{2}|!)", + "name": "keyword.operator.logical.go" + }, + { + "match": "([+]{2})", + "name": "keyword.operator.increment.go" + }, + { + "match": "(--)", + "name": "keyword.operator.decrement.go" + }, + { + "match": "([+]|-|[*]|/|%|&|[|]|^|&^|<<|>>)", + "name": "keyword.operator.arithmetic.go" + }, + { + "match": "(;)", + "name": "keyword.operator.semi-colon.go" + } + ] + }, + "array-definition": { + "patterns": [ + { + "captures": { + "3": { + "name": "support.type.builtin.go" + }, + "2": { + "name": "punctuation.definition.array.go" + }, + "1": { + "name": "punctuation.definition.array.go" + } + }, + "match": "\\b(\\[\\])(&)?(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\\s*(?=\\{)", + "name": "meta.definition.array.go" + } + ] + }, + "variable-dot-access": { + "patterns": [ + { + "match": "(?<=\\.)([A-Za-z0-9_]+)(?=\\s*[^\\(])", + "name": "variable.dot-access.go" + } + ] + }, + "struct-literal-field": { + "patterns": [ + { + "captures": { + "2": { + "name": "punctuation.definition.struct-field.go" + }, + "1": { + "name": "variable.definition.struct-field.go" + } + }, + "match": "\\b(?:([a-zA-Z0-9_]+)\\s*(:))?" + } + ] + }, + "strings": { + "patterns": [ + { + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.go" + } + }, + "begin": "\"", + "name": "string.quoted.double.go", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.go" + } + }, + "patterns": [ + { + "include": "#string_placeholder" + }, + { + "include": "#string_escaped_char" + } + ], + "end": "\"" + }, + { + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.go" + } + }, + "begin": "`", + "name": "string.quoted.raw.go", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.go" + } + }, + "patterns": [ + { + "include": "#string_placeholder" + }, + { + "include": "source.gotemplate" + } + ], + "end": "`" + } + ] + }, + "interface-type": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.declaration.interface.end.go" + } + }, + "begin": "\\b(interface)\\s*(\\{)", + "name": "meta.declaration.interface.go", + "beginCaptures": { + "2": { + "name": "punctuation.declaration.interface.begin.go" + }, + "1": { + "name": "storage.type.go" + } + }, + "patterns": [ + { + "beginCaptures": { + "2": { + "name": "punctuation.definition.function.go" + }, + "1": { + "name": "entity.name.function.go" + } + }, + "endCaptures": { + "1": { + "name": "punctuation.definition.function.go" + } + }, + "begin": "\\b([a-zA-Z0-9_]+)(\\()", + "end": "(\\))" + }, + { + "include": "#comments" + }, + { + "include": "#types" + }, + { + "include": "#embedded-type" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.type.pointer.go" + } + }, + "match": "(\\*)" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.type.go" + } + }, + "match": "(\\.)" + } + ], + "end": "(\\})" + } + ] + }, + "struct-literal": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.definition.struct.end.go" + } + }, + "begin": "(&)?(?:([a-zA-Z0-9_]+)(\\.))?([A-Za-z0-9_]+)(\\{)", + "name": "meta.literal.struct.go", + "beginCaptures": { + "5": { + "name": "punctuation.definition.struct.begin.go" + }, + "4": { + "name": "storage.type.go" + }, + "3": { + "name": "punctuation.definition.type.go" + }, + "2": { + "name": "entity.name.package.go" + }, + "1": { + "name": "punctuation.definition.pointer.go" + } + }, + "patterns": [ + { + "include": "#struct-literal-field" + }, + { + "include": "#comments" + }, + { + "include": "#expressions" + }, + { + "include": "#types" + }, + { + "match": "(,)", + "name": "punctuation.separator.mapping.go" + } + ], + "end": "(\\})" + } + ] + }, + "comments": { + "patterns": [ + { + "begin": "/\\*", + "name": "comment.block.go", + "end": "\\*/" + }, + { + "begin": "//", + "name": "comment.line.double-slash.go", + "end": "\\z" + } + ] + }, + "pointer-literal": { + "patterns": [ + { + "beginCaptures": { + "1": { + "name": "punctuation.definition.pointer.go" + } + }, + "begin": "(&)", + "name": "meta.literal.pointer.go", + "end": "(?=[^a-zA-Z0-9_\\.])", + "patterns": [ + { + "include": "#struct-literal" + }, + { + "include": "#slice-literal" + } + ] + } + ] + }, + "struct-field": { + "patterns": [ + { + "contentName": "storage.type.go", + "begin": "^[\\s\\t]*([a-zA-Z0-9_]+)[\\s\\t]+", + "name": "meta.definition.struct-field.go", + "beginCaptures": { + "1": { + "name": "variable.struct-field.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#types" + } + ], + "end": "(?=$|`)" + } + ] + }, + "slice-type": { + "patterns": [ + { + "beginCaptures": { + "1": { + "name": "punctuation.declaration.slice.go" + } + }, + "begin": "(\\[\\])", + "name": "storage.type.slice.go", + "end": "(?=\\s|$)", + "patterns": [ + { + "include": "#types" + } + ] + } + ] + }, + "slice-literal": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.definition.slice.end.go" + } + }, + "begin": "(\\[\\])?(\\*)?(?:([a-zA-Z0-9_]+)(\\.))?([A-Za-z0-9_]+)(\\{)", + "name": "meta.literal.slice.go", + "beginCaptures": { + "6": { + "name": "punctuation.definition.slice.begin.go" + }, + "5": { + "name": "storage.type.go" + }, + "4": { + "name": "punctuation.definition.type.go" + }, + "3": { + "name": "entity.name.package.go" + }, + "2": { + "name": "punctuation.definition.pointer.go" + }, + "1": { + "name": "punctuation.definition.slice.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expressions" + }, + { + "match": "(,)", + "name": "punctuation.separator.sequence.go" + } + ], + "end": "(\\})" + } + ] + }, + "embedded-type": { + "patterns": [ + { + "captures": { + "4": { + "name": "punctuation.name.type.go" + }, + "3": { + "name": "entity.name.package.go" + }, + "2": { + "name": "punctuation.definition.type.pointer.go" + }, + "1": { + "name": "storage.type.go" + } + }, + "match": "^[\\s\\t]*((\\*)?(?:([a-zA-Z0-9_]+)(\\.))?[a-zA-Z0-9_]+)[\\s\\t]*$", + "name": "meta.declaration.field.embedded.go" + } + ] + }, + "struct-tags": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.definition.string.end.go" + } + }, + "begin": "(`)", + "name": "string.tag.struct-field.go", + "beginCaptures": { + "1": { + "name": "punctuation.definition.string.begin.go" + } + }, + "patterns": [ + { + "captures": { + "2": { + "name": "punctuation.definition.tag.struct-field.go" + }, + "1": { + "name": "entity.name.tag.struct-field.go" + } + }, + "match": "\\b([a-z]+)(:)" + } + ], + "end": "(`)" + } + ] + }, + "struct-type": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.declaration.struct.end.go" + } + }, + "begin": "\\b(struct)\\s*(\\{)", + "name": "meta.declaration.struct.go", + "beginCaptures": { + "2": { + "name": "punctuation.declaration.struct.begin.go" + }, + "1": { + "name": "storage.type.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#struct-field" + }, + { + "include": "#embedded-type" + }, + { + "include": "#struct-tags" + }, + { + "include": "#function-call" + }, + { + "include": "#variable-dot-access" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.type.pointer.go" + } + }, + "match": "(\\*)" + }, + { + "captures": { + "1": { + "name": "punctuation.definition.type.go" + } + }, + "match": "(\\.)" + } + ], + "end": "(\\})" + } + ] + }, + "keywords": { + "patterns": [ + { + "match": "\\b(break|case|continue|default|defer|else|fallthrough|for|go|goto|if|range|return|select|switch)\\b", + "name": "keyword.control.go", + "comment": "A subset of keyword.other.go for flow control keywords." + }, + { + "match": "\\b(import|package)\\b", + "name": "keyword.other.go" + } + ] + }, + "constants": { + "patterns": [ + { + "match": "\\b(true|false|nil|iota)\\b", + "name": "constant.language.go" + }, + { + "match": "\\b((\\d+\\.(\\d+)?([eE][+-]?\\d+)?|\\d+[eE][+-]?\\d+|\\.\\d+([eE][+-]?\\d+)?)i?)\\b", + "name": "constant.numeric.floating-point.go" + }, + { + "match": "\\b(\\d+i|0[xX][0-9A-Fa-f]+|0[0-7]*|[1-9][0-9]*)\\b", + "name": "constant.numeric.integer.go" + }, + { + "match": "'(?:[^'\\\\]|\\\\(?:\\\\|[abfnrtv']|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3}))'", + "name": "constant.other.rune.go" + } + ] + }, + "type-statement": { + "patterns": [ + { + "beginCaptures": { + "2": { + "name": "entity.name.type.go" + }, + "1": { + "name": "keyword.other.go" + } + }, + "begin": "\\b(type)[\\s\\t]+([a-zA-Z0-9_]+)[\\s\\t]+", + "end": "$", + "patterns": [ + { + "include": "#types" + } + ] + } + ] + }, + "string_placeholder": { + "patterns": [ + { + "match": "(?x)%\n(\\d+\\$)? # field (argument #)\n[#0\\- +']* # flags\n[,;:_]? # separator character (AltiVec)\n((-?\\d+)|\\*(-?\\d+\\$)?)? # minimum field width\n(\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)? # precision\n[diouxXDOUeEfFgGaAcCsSqpnvtTbyYhHmMzZ%] # conversion type", + "name": "constant.other.placeholder.go" + } + ] + }, + "expressions": { + "patterns": [ + { + "include": "#function-call" + }, + { + "include": "#literals" + } + ] + }, + "struct-declaration": { + "patterns": [ + { + "beginCaptures": { + "1": { + "name": "entity.name.type.go" + } + }, + "begin": "([a-zA-Z0-9_]+)\\s+(?=struct\\b)", + "end": "$", + "patterns": [ + { + "include": "#struct-type" + } + ] + } + ] + }, + "literals": { + "patterns": [ + { + "include": "#struct-literal" + }, + { + "include": "#slice-literal" + }, + { + "include": "#strings" + }, + { + "include": "#constants" + }, + { + "include": "#pointer-literal" + } + ] + }, + "types": { + "patterns": [ + { + "include": "#storage-types" + } + ] + }, + "builtin-type": { + "patterns": [ + { + "match": "\\b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64)?|uintptr)\\b", + "name": "storage.type.builtin.go" + } + ] + }, + "var-and-const-statements": { + "patterns": [ + { + "beginCaptures": { + "2": { + "name": "variable.other.go" + }, + "1": { + "name": "keyword.other.go" + } + }, + "begin": "\\b(var|const)[\\s\\t]+([a-zA-Z0-9_]+)[\\s\\t]*", + "end": "$", + "patterns": [ + { + "include": "#assignment-expr" + }, + { + "include": "#types" + } + ] + } + ] + }, + "storage-types": { + "patterns": [ + { + "include": "#interface-type" + }, + { + "include": "#chan-type" + }, + { + "include": "#slice-type" + }, + { + "include": "#map-type" + }, + { + "include": "#struct-type" + }, + { + "include": "#builtin-type" + }, + { + "captures": { + "3": { + "name": "punctuation.definition.type.go" + }, + "2": { + "name": "entity.name.package.go" + }, + "1": { + "name": "punctuation.definition.type.pointer.go" + } + }, + "match": "\\b(\\*)?(?:([a-zA-Z0-9_]+)(\\.))?[a-zA-Z0-9_]+\\b", + "comment": "userland type" + } + ] + }, + "chan-type": { + "patterns": [ + { + "beginCaptures": { + "2": { + "name": "punctuation.declaration.chan.go" + }, + "1": { + "name": "punctuation.declaration.chan.go" + } + }, + "begin": "(\\<\\-\\s?)?chan(\\s?\\<\\-)?[\\s\\t]", + "name": "storage.type.chan.go", + "end": "(?=\\s|\\t|$|,|;|\\})", + "patterns": [ + { + "include": "#types" + } + ] + } + ] + }, + "string_escaped_char": { + "patterns": [ + { + "match": "\\\\(\\\\|[abfnrtv'\"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{3})", + "name": "constant.character.escape.go" + }, + { + "match": "\\\\.", + "name": "invalid.illegal.unknown-escape.go" + } + ] + }, + "punctuation": { + "patterns": [ + { + "match": "(,)", + "name": "punctuation.definition.comma.go" + }, + { + "match": "([.])", + "name": "punctuation.definition.dot.go" + }, + { + "match": "(:)", + "name": "punctuation.definition.colon.go" + }, + { + "match": "(\\[|\\]|{|}|\\(|\\))", + "name": "punctuation.definition.bracket.go" + } + ] + }, + "assignment-expr": { + "patterns": [ + { + "beginCaptures": { + "1": { + "name": "keyword.operator.assignment.go" + } + }, + "begin": "\\s(=)[\\s\\t]+", + "name": "meta.assignment-expr.go", + "end": "$", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expressions" + }, + { + "include": "#types" + } + ] + } + ] + }, + "function-call": { + "patterns": [ + { + "endCaptures": { + "1": { + "name": "punctuation.separator.function-call.end.go" + } + }, + "begin": "\\b(?:[a-zA-Z0-9_]+(\\.))*([a-zA-Z0-9_]+)(\\()", + "name": "meta.function-call.go", + "beginCaptures": { + "3": { + "name": "punctuation.separator.function-call.begin.go" + }, + "2": { + "name": "entity.name.function.go" + }, + "1": { + "name": "punctuation.separator.dot-access.go" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expressions" + } + ], + "end": "(\\))" + } + ] + }, + "interface-declaration": { + "patterns": [ + { + "beginCaptures": { + "1": { + "name": "entity.name.type.go" + } + }, + "begin": "([a-zA-Z0-9_]+)\\s+(?=interface\\b)", + "end": "$", + "patterns": [ + { + "include": "#interface-type" + } + ] + } + ] + }, + "map-type": { + "patterns": [ + { + "captures": { + "4": { + "name": "punctuation.definition.type.go" + }, + "3": { + "name": "storage.type.go" + }, + "2": { + "name": "punctuation.definition.type.go" + }, + "1": { + "name": "storage.type.go" + } + }, + "match": "(map)(\\[)(\\w+)(\\])", + "name": "storage.type.map.go" + } + ] + } + }, + "firstLineMatch": "-[*]-( Mode:)? Go -[*]-", + "scopeName": "source.go", + "uuid": "1ceaa75c-b61d-11e2-ba93-138feb5db969", + "fileTypes": [ + "go" + ] +} \ No newline at end of file