summaryrefslogtreecommitdiffstats
path: root/syntax/go.vim
diff options
context:
space:
mode:
Diffstat (limited to 'syntax/go.vim')
-rw-r--r--syntax/go.vim74
1 files changed, 44 insertions, 30 deletions
diff --git a/syntax/go.vim b/syntax/go.vim
index 51f1a60e..a06f62d2 100644
--- a/syntax/go.vim
+++ b/syntax/go.vim
@@ -74,7 +74,7 @@ hi def link goComment Comment
hi def link goTodo Todo
if go#config#HighlightGenerateTags()
- syn match goGenerateVariables contained /\(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
+ syn match goGenerateVariables contained /\%(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables
hi def link goGenerate PreProc
hi def link goGenerateVariables Special
@@ -115,7 +115,7 @@ if go#config#HighlightFormatStrings()
" 5. Match [n] or nothing before a verb
" 6. Match a formatting verb
syn match goFormatSpecifier /\
- \([^%]\(%%\)*\)\
+ \%([^%]\%(%%\)*\)\
\@<=%[-#0 +]*\
\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\
\%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\
@@ -150,18 +150,18 @@ endif
" var, const
if go#config#FoldEnable('varconst')
syn region goVar start='var (' end='^\s*)$' transparent fold
- \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments,goPointerOperator
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
syn region goConst start='const (' end='^\s*)$' transparent fold
- \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments,goPointerOperator
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
else
syn region goVar start='var (' end='^\s*)$' transparent
- \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments,goPointerOperator
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
syn region goConst start='const (' end='^\s*)$' transparent
- \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments,goPointerOperator
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
endif
" Single-line var, const, and import.
-syn match goSingleDecl /\(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst
+syn match goSingleDecl /\%(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst
" Integers
syn match goDecimalInt "\<-\=\d\+\%([Ee][-+]\=\d\+\)\=\>"
@@ -192,7 +192,7 @@ hi def link goImaginaryFloat Float
" Spaces after "[]"
if go#config#HighlightArrayWhitespaceError()
- syn match goSpaceError display "\(\[\]\)\@<=\s\+"
+ syn match goSpaceError display "\%(\[\]\)\@<=\s\+"
endif
" Spacing errors around the 'chan' keyword
@@ -201,24 +201,24 @@ if go#config#HighlightChanWhitespaceError()
"
" \(\<chan\>\)\@<!<- (only pick arrow when it doesn't come after a chan)
" this prevents picking up 'chan<- chan<-' but not '<- chan'
- syn match goSpaceError display "\(\(\<chan\>\)\@<!<-\)\@<=\s\+\(\<chan\>\)\@="
+ syn match goSpaceError display "\%(\%(\<chan\>\)\@<!<-\)\@<=\s\+\%(\<chan\>\)\@="
" send-only annotation on chan type
"
" \(<-\)\@<!\<chan\> (only pick chan when it doesn't come after an arrow)
" this prevents picking up '<-chan <-chan' but not 'chan <-'
- syn match goSpaceError display "\(\(<-\)\@<!\<chan\>\)\@<=\s\+\(<-\)\@="
+ syn match goSpaceError display "\%(\%(<-\)\@<!\<chan\>\)\@<=\s\+\%(<-\)\@="
" value-ignoring receives in a few contexts
- syn match goSpaceError display "\(\(^\|[={(,;]\)\s*<-\)\@<=\s\+"
+ syn match goSpaceError display "\%(\%(^\|[={(,;]\)\s*<-\)\@<=\s\+"
endif
" Extra types commonly seen
if go#config#HighlightExtraTypes()
- syn match goExtraType /\<bytes\.\(Buffer\)\>/
- syn match goExtraType /\<context\.\(Context\)\>/
- syn match goExtraType /\<io\.\(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
- syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
+ syn match goExtraType /\<bytes\.\%(Buffer\)\>/
+ syn match goExtraType /\<context\.\%(Context\)\>/
+ syn match goExtraType /\<io\.\%(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
+ syn match goExtraType /\<reflect\.\%(Kind\|Type\|Value\)\>/
syn match goExtraType /\<unsafe\.Pointer\>/
endif
@@ -265,21 +265,22 @@ endif
hi def link goOperator Operator
" Functions;
-if go#config#HighlightFunctions() || go#config#HighlightFunctionArguments()
- syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleArguments skipwhite skipnl
- syn match goReceiverVar /\w\+\ze\s\+\(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
+if go#config#HighlightFunctions() || go#config#HighlightFunctionParameters()
+ syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleParams skipwhite skipnl
+ syn match goReceiverVar /\w\+\ze\s\+\%(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
- syn match goFunction /\w\+/ nextgroup=goSimpleArguments contained skipwhite skipnl
+ syn match goFunction /\w\+/ nextgroup=goSimpleParams contained skipwhite skipnl
syn match goReceiverType /\w\+/ contained
-if go#config#HighlightFunctionArguments()
- syn match goSimpleArguments /(\(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goArgumentName nextgroup=goSimpleArguments skipwhite skipnl
- syn match goArgumentName /\w\+\(\s*,\s*\w\+\)*\ze\s\+\(\w\|\.\|\*\|\[\)/ contained nextgroup=goArgumentType skipwhite skipnl
- syn match goArgumentType /\([^,)]\|\_s\)\+,\?/ contained nextgroup=goArgumentName skipwhite skipnl
- \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock
- hi def link goReceiverVar goArgumentName
- hi def link goArgumentName Identifier
-endif
- syn match goReceiver /(\s*\w\+\(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
+ if go#config#HighlightFunctionParameters()
+ syn match goSimpleParams /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType nextgroup=goFunctionReturn skipwhite skipnl
+ syn match goFunctionReturn /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType skipwhite skipnl
+ syn match goParamName /\w\+\%(\s*,\s*\w\+\)*\ze\s\+\%(\w\|\.\|\*\|\[\)/ contained nextgroup=goParamType skipwhite skipnl
+ syn match goParamType /\%([^,)]\|\_s\)\+,\?/ contained nextgroup=goParamName skipwhite skipnl
+ \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock
+ hi def link goReceiverVar goParamName
+ hi def link goParamName Identifier
+ endif
+ syn match goReceiver /(\s*\w\+\%(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
else
syn keyword goDeclaration func
endif
@@ -293,7 +294,20 @@ hi def link goFunctionCall Type
" Fields;
if go#config#HighlightFields()
- syn match goField /\.\w\+\([.\ \n\r\:\)\[,]\)\@=/hs=s+1
+ " 1. Match a sequence of word characters coming after a '.'
+ " 2. Require the following but dont match it: ( \@= see :h E59)
+ " - The symbols: / - + * % OR
+ " - The symbols: [] {} <> ) OR
+ " - The symbols: \n \r space OR
+ " - The symbols: , : .
+ " 3. Have the start of highlight (hs) be the start of matched
+ " pattern (s) offsetted one to the right (+1) (see :h E401)
+ syn match goField /\.\w\+\
+ \%(\%([\/\-\+*%]\)\|\
+ \%([\[\]{}<\>\)]\)\|\
+ \%([\!=\^|&]\)\|\
+ \%([\n\r\ ]\)\|\
+ \%([,\:.]\)\)\@=/hs=s+1
endif
hi def link goField Identifier
@@ -302,7 +316,7 @@ if go#config#HighlightTypes()
syn match goTypeConstructor /\<\w\+{\@=/
syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
- syn match goDeclType /\<\(interface\|struct\)\>/ skipwhite skipnl
+ syn match goDeclType /\<\%(interface\|struct\)\>/ skipwhite skipnl
hi def link goReceiverType Type
else
syn keyword goDeclType struct interface