vim-polyglot/syntax/scala.vim

236 lines
11 KiB
VimL
Raw Normal View History

if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'scala') != -1
finish
endif
2015-02-11 14:27:11 -05:00
" Vim syntax file
" Language: Scala
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Apache 2
" ----------------------------------------------------------------------------
if !exists('main_syntax')
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'scala'
2013-09-12 11:02:41 -04:00
endif
2014-06-08 13:35:34 -04:00
scriptencoding utf-8
2013-12-12 19:37:01 -05:00
let b:current_syntax = "scala"
2013-09-12 11:02:41 -04:00
2015-02-11 14:27:11 -05:00
" Allows for embedding, see #59; main_syntax convention instead? Refactor TOP
"
" The @Spell here is a weird hack, it means *exclude* if the first group is
" TOP. Otherwise we get spelling errors highlighted on code elements that
" match scalaBlock, even with `syn spell notoplevel`.
2014-06-08 13:35:34 -04:00
function! s:ContainedGroup()
try
silent syn list @scala
2015-02-11 14:27:11 -05:00
return '@scala,@NoSpell'
2014-06-08 13:35:34 -04:00
catch /E392/
2015-02-11 14:27:11 -05:00
return 'TOP,@Spell'
2014-06-08 13:35:34 -04:00
endtry
endfunction
2015-02-11 14:27:11 -05:00
unlet! b:current_syntax
2013-12-12 19:37:01 -05:00
syn case match
syn sync minlines=200 maxlines=1000
syn keyword scalaKeyword catch do else final finally for forSome if
2014-02-28 18:15:51 -05:00
syn keyword scalaKeyword match return throw try while yield macro
2013-12-25 21:34:22 -05:00
syn keyword scalaKeyword class trait object extends with nextgroup=scalaInstanceDeclaration skipwhite
syn keyword scalaKeyword case nextgroup=scalaKeyword,scalaCaseFollowing skipwhite
2013-12-12 19:37:01 -05:00
syn keyword scalaKeyword val nextgroup=scalaNameDefinition,scalaQuasiQuotes skipwhite
syn keyword scalaKeyword def var nextgroup=scalaNameDefinition skipwhite
hi link scalaKeyword Keyword
2013-09-12 11:02:41 -04:00
2014-06-08 13:35:34 -04:00
exe 'syn region scalaBlock start=/{/ end=/}/ contains=' . s:ContainedGroup() . ' fold'
2014-04-14 19:05:44 -04:00
2014-01-09 05:59:09 -05:00
syn keyword scalaAkkaSpecialWord when goto using startWith initialize onTransition stay become unbecome
hi link scalaAkkaSpecialWord PreProc
2016-05-02 04:42:37 -04:00
syn keyword scalatestSpecialWord shouldBe
syn match scalatestShouldDSLA /^\s\+\zsit should/
syn match scalatestShouldDSLB /\<should\>/
hi link scalatestSpecialWord PreProc
hi link scalatestShouldDSLA PreProc
hi link scalatestShouldDSLB PreProc
2013-12-25 21:34:22 -05:00
syn match scalaSymbol /'[_A-Za-z0-9$]\+/
hi link scalaSymbol Number
syn match scalaChar /'.'/
2015-03-09 00:32:50 -04:00
syn match scalaChar /'\\[\\"'ntbrf]'/ contains=scalaEscapedChar
syn match scalaChar /'\\u[A-Fa-f0-9]\{4}'/ contains=scalaUnicodeChar
syn match scalaEscapedChar /\\[\\"'ntbrf]/
2013-12-25 21:34:22 -05:00
syn match scalaUnicodeChar /\\u[A-Fa-f0-9]\{4}/
hi link scalaChar Character
hi link scalaEscapedChar Function
hi link scalaUnicodeChar Special
2014-01-09 05:59:09 -05:00
syn match scalaOperator "||"
syn match scalaOperator "&&"
hi link scalaOperator Special
2016-05-02 04:42:37 -04:00
syn match scalaNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained nextgroup=scalaPostNameDefinition,scalaVariableDeclarationList
2013-12-26 18:01:27 -05:00
syn match scalaNameDefinition /`[^`]\+`/ contained nextgroup=scalaPostNameDefinition
2016-05-02 04:42:37 -04:00
syn match scalaVariableDeclarationList /\s*,\s*/ contained nextgroup=scalaNameDefinition
2013-12-26 18:01:27 -05:00
syn match scalaPostNameDefinition /\_s*:\_s*/ contained nextgroup=scalaTypeDeclaration
2013-12-12 19:37:01 -05:00
hi link scalaNameDefinition Function
2013-09-12 11:02:41 -04:00
2014-01-09 05:59:09 -05:00
syn match scalaInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaInstanceHash
2013-12-12 19:37:01 -05:00
syn match scalaInstanceDeclaration /`[^`]\+`/ contained
2014-01-09 05:59:09 -05:00
syn match scalaInstanceHash /#/ contained nextgroup=scalaInstanceDeclaration
2013-12-12 19:37:01 -05:00
hi link scalaInstanceDeclaration Special
2014-01-09 05:59:09 -05:00
hi link scalaInstanceHash Type
2015-02-11 14:27:11 -05:00
syn match scalaUnimplemented /???/
hi link scalaUnimplemented ERROR
2014-01-09 05:59:09 -05:00
syn match scalaCapitalWord /\<[A-Z][A-Za-z0-9$]*\>/
hi link scalaCapitalWord Special
" Handle type declarations specially
syn region scalaTypeStatement matchgroup=Keyword start=/\<type\_s\+\ze/ end=/$/ contains=scalaTypeTypeDeclaration,scalaSquareBrackets,scalaTypeTypeEquals,scalaTypeStatement
2013-09-12 11:02:41 -04:00
2013-12-26 18:01:27 -05:00
" Ugh... duplication of all the scalaType* stuff to handle special highlighting
" of `type X =` declarations
syn match scalaTypeTypeDeclaration /(/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals contains=scalaRoundBrackets skipwhite
syn match scalaTypeTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeTypeDeclaration contains=scalaTypeTypeExtension skipwhite
syn match scalaTypeTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals skipwhite
syn match scalaTypeTypeEquals /=\ze[^>]/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
2017-11-19 15:26:59 -05:00
syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypeDeclaration skipwhite
2014-01-09 05:59:09 -05:00
syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
2017-11-19 15:26:59 -05:00
syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypePostDeclaration skipwhite
2013-12-26 18:01:27 -05:00
hi link scalaTypeTypeDeclaration Type
hi link scalaTypeTypeExtension Keyword
hi link scalaTypeTypePostDeclaration Special
hi link scalaTypeTypePostExtension Keyword
2014-01-09 05:59:09 -05:00
syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
2013-12-26 18:01:27 -05:00
syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
2014-01-09 05:59:09 -05:00
syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
2017-11-19 15:26:59 -05:00
syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeDeclaration skipwhite
2013-12-25 21:34:22 -05:00
hi link scalaTypeDeclaration Type
hi link scalaTypeExtension Keyword
hi link scalaTypePostExtension Keyword
2013-12-26 18:01:27 -05:00
syn match scalaTypeAnnotation /\%([_a-zA-Z0-9$\s]:\_s*\)\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration contains=scalaRoundBrackets
syn match scalaTypeAnnotation /)\_s*:\_s*\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration
hi link scalaTypeAnnotation Normal
2013-12-25 21:34:22 -05:00
2017-11-19 15:26:59 -05:00
syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained contains=scalaCapitalWord
syn match scalaCaseFollowing /`[^`]\+`/ contained contains=scalaCapitalWord
2013-12-12 19:37:01 -05:00
hi link scalaCaseFollowing Special
2013-09-12 11:02:41 -04:00
2017-11-19 15:26:59 -05:00
syn keyword scalaKeywordModifier abstract override final lazy implicit private protected sealed null super
syn keyword scalaSpecialFunction implicitly require
2013-12-12 19:37:01 -05:00
hi link scalaKeywordModifier Function
2017-11-19 15:26:59 -05:00
hi link scalaSpecialFunction Function
2013-09-12 11:02:41 -04:00
2015-02-11 14:27:11 -05:00
syn keyword scalaSpecial this true false ne eq
2013-12-12 19:37:01 -05:00
syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
syn match scalaSpecial "\%(=>\|⇒\|<-\|←\|->\|→\)"
2016-05-30 19:53:12 -04:00
syn match scalaSpecial /`[^`]\+`/ " Backtick literals
2013-12-12 19:37:01 -05:00
hi link scalaSpecial PreProc
2013-09-12 11:02:41 -04:00
2015-02-11 14:27:11 -05:00
syn keyword scalaExternal package import
hi link scalaExternal Include
2013-12-25 21:34:22 -05:00
syn match scalaStringEmbeddedQuote /\\"/ contained
syn region scalaString start=/"/ end=/"/ contains=scalaStringEmbeddedQuote,scalaEscapedChar,scalaUnicodeChar
2013-09-12 11:02:41 -04:00
hi link scalaString String
2013-12-25 21:34:22 -05:00
hi link scalaStringEmbeddedQuote String
2013-09-12 11:02:41 -04:00
2015-03-09 00:32:50 -04:00
syn region scalaIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"/ skip=/\\"/ end=/"/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
syn region scalaTripleIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"""/ end=/"""\%([^"]\|$\)/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
2014-04-14 19:05:44 -04:00
hi link scalaIString String
hi link scalaTripleIString String
2013-12-12 19:37:01 -05:00
syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
2015-03-09 00:32:50 -04:00
exe 'syn region scalaInterpolationB matchgroup=scalaInterpolationBoundary start=/\${/ end=/}/ contained contains=' . s:ContainedGroup()
2013-12-12 19:37:01 -05:00
hi link scalaInterpolation Function
2014-04-14 19:05:44 -04:00
hi link scalaInterpolationB Normal
2013-12-12 19:37:01 -05:00
2015-03-09 00:32:50 -04:00
syn region scalaFString matchgroup=scalaInterpolationBrackets start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
2014-04-14 19:05:44 -04:00
syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
2015-03-09 00:32:50 -04:00
exe 'syn region scalaFInterpolationB matchgroup=scalaInterpolationBoundary start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=' . s:ContainedGroup()
2013-12-12 19:37:01 -05:00
hi link scalaFString String
hi link scalaFInterpolation Function
2014-04-14 19:05:44 -04:00
hi link scalaFInterpolationB Normal
2013-12-12 19:37:01 -05:00
2014-01-09 05:59:09 -05:00
syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
2015-03-09 00:32:50 -04:00
syn region scalaTripleFString matchgroup=scalaInterpolationBrackets start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
2013-12-12 19:37:01 -05:00
hi link scalaTripleString String
hi link scalaTripleFString String
2015-03-09 00:32:50 -04:00
hi link scalaInterpolationBrackets Special
hi link scalaInterpolationBoundary Function
2014-01-09 05:59:09 -05:00
syn match scalaNumber /\<0[dDfFlL]\?\>/ " Just a bare 0
syn match scalaNumber /\<[1-9]\d*[dDfFlL]\?\>/ " A multi-digit number - octal numbers with leading 0's are deprecated in Scala
syn match scalaNumber /\<0[xX][0-9a-fA-F]\+[dDfFlL]\?\>/ " Hex number
syn match scalaNumber /\%(\<\d\+\.\d*\|\.\d\+\)\%([eE][-+]\=\d\+\)\=[fFdD]\=/ " exponential notation 1
syn match scalaNumber /\<\d\+[eE][-+]\=\d\+[fFdD]\=\>/ " exponential notation 2
syn match scalaNumber /\<\d\+\%([eE][-+]\=\d\+\)\=[fFdD]\>/ " exponential notation 3
2013-12-12 19:37:01 -05:00
hi link scalaNumber Number
2013-09-12 11:02:41 -04:00
2013-12-26 18:01:27 -05:00
syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets
2013-12-25 21:34:22 -05:00
2015-03-09 00:32:50 -04:00
syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter
2013-12-25 21:34:22 -05:00
syn match scalaTypeOperator /[-+=:<>]\+/ contained
syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained
2015-03-09 00:32:50 -04:00
hi link scalaSquareBracketsBrackets Type
2013-12-25 21:34:22 -05:00
hi link scalaTypeOperator Keyword
hi link scalaTypeAnnotationParameter Function
2013-12-12 19:37:01 -05:00
2015-03-09 00:32:50 -04:00
syn match scalaShebang "\%^#!.*" display
2016-05-02 04:42:37 -04:00
syn region scalaMultilineComment start="/\*" end="\*/" contains=scalaMultilineComment,scalaDocLinks,scalaParameterAnnotation,scalaCommentAnnotation,scalaTodo,scalaCommentCodeBlock,@Spell keepend fold
2013-12-12 19:37:01 -05:00
syn match scalaCommentAnnotation "@[_A-Za-z0-9$]\+" contained
2016-05-30 19:53:12 -04:00
syn match scalaParameterAnnotation "\%(@tparam\|@param\|@see\)" nextgroup=scalaParamAnnotationValue skipwhite contained
syn match scalaParamAnnotationValue /[.`_A-Za-z0-9$]\+/ contained
2013-12-12 19:37:01 -05:00
syn region scalaDocLinks start="\[\[" end="\]\]" contained
syn region scalaCommentCodeBlock matchgroup=Keyword start="{{{" end="}}}" contained
2015-03-09 00:32:50 -04:00
syn match scalaTodo "\vTODO|FIXME|XXX" contained
hi link scalaShebang Comment
2013-12-12 19:37:01 -05:00
hi link scalaMultilineComment Comment
hi link scalaDocLinks Function
hi link scalaParameterAnnotation Function
hi link scalaParamAnnotationValue Keyword
hi link scalaCommentAnnotation Function
hi link scalaCommentCodeBlock String
2015-03-09 00:32:50 -04:00
hi link scalaTodo Todo
2013-12-12 19:37:01 -05:00
syn match scalaAnnotation /@\<[`_A-Za-z0-9$]\+\>/
hi link scalaAnnotation PreProc
2015-03-09 00:32:50 -04:00
syn match scalaTrailingComment "//.*$" contains=scalaTodo,@Spell
2013-12-12 19:37:01 -05:00
hi link scalaTrailingComment Comment
2014-01-09 05:59:09 -05:00
syn match scalaAkkaFSM /goto([^)]*)\_s\+\<using\>/ contains=scalaAkkaFSMGotoUsing
syn match scalaAkkaFSM /stay\_s\+using/
syn match scalaAkkaFSM /^\s*stay\s*$/
syn match scalaAkkaFSM /when\ze([^)]*)/
syn match scalaAkkaFSM /startWith\ze([^)]*)/
syn match scalaAkkaFSM /initialize\ze()/
syn match scalaAkkaFSM /onTransition/
syn match scalaAkkaFSM /onTermination/
syn match scalaAkkaFSM /whenUnhandled/
syn match scalaAkkaFSMGotoUsing /\<using\>/
syn match scalaAkkaFSMGotoUsing /\<goto\>/
hi link scalaAkkaFSM PreProc
hi link scalaAkkaFSMGotoUsing PreProc
2015-02-11 14:27:11 -05:00
let b:current_syntax = 'scala'
if main_syntax ==# 'scala'
unlet main_syntax
endif
" vim:set sw=2 sts=2 ts=8 et: