Files
org-vim/runtime/syntax/scala.vim
T

234 lines
11 KiB
VimL
Raw Normal View History

2016-08-26 19:52:37 +02:00
" Vim syntax file
" Language: Scala
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Same as Vim
2022-01-23 12:07:04 +00:00
" Last Change: 23 January 2022
2016-08-26 19:52:37 +02:00
" ----------------------------------------------------------------------------
if !exists('main_syntax')
" quit when a syntax file was already loaded
if exists("b:current_syntax")
2016-08-26 19:52:37 +02:00
finish
endif
let main_syntax = 'scala'
endif
scriptencoding utf-8
let b:current_syntax = "scala"
" 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`.
function! s:ContainedGroup()
try
silent syn list @scala
return '@scala,@NoSpell'
catch /E392/
return 'TOP,@Spell'
endtry
endfunction
unlet! b:current_syntax
syn case match
syn sync minlines=200 maxlines=1000
syn keyword scalaKeyword catch do else final finally for forSome if
syn keyword scalaKeyword match return throw try while yield macro
syn keyword scalaKeyword class trait object extends with nextgroup=scalaInstanceDeclaration skipwhite
syn keyword scalaKeyword case nextgroup=scalaKeyword,scalaCaseFollowing skipwhite
syn keyword scalaKeyword val nextgroup=scalaNameDefinition,scalaQuasiQuotes skipwhite
syn keyword scalaKeyword def var nextgroup=scalaNameDefinition skipwhite
2022-01-23 12:07:04 +00:00
hi def link scalaKeyword Keyword
2016-08-26 19:52:37 +02:00
exe 'syn region scalaBlock start=/{/ end=/}/ contains=' . s:ContainedGroup() . ' fold'
syn keyword scalaAkkaSpecialWord when goto using startWith initialize onTransition stay become unbecome
2022-01-23 12:07:04 +00:00
hi def link scalaAkkaSpecialWord PreProc
2016-08-26 19:52:37 +02:00
syn keyword scalatestSpecialWord shouldBe
syn match scalatestShouldDSLA /^\s\+\zsit should/
syn match scalatestShouldDSLB /\<should\>/
2022-01-23 12:07:04 +00:00
hi def link scalatestSpecialWord PreProc
hi def link scalatestShouldDSLA PreProc
hi def link scalatestShouldDSLB PreProc
2016-08-26 19:52:37 +02:00
syn match scalaSymbol /'[_A-Za-z0-9$]\+/
2022-01-23 12:07:04 +00:00
hi def link scalaSymbol Number
2016-08-26 19:52:37 +02:00
syn match scalaChar /'.'/
syn match scalaChar /'\\[\\"'ntbrf]'/ contains=scalaEscapedChar
syn match scalaChar /'\\u[A-Fa-f0-9]\{4}'/ contains=scalaUnicodeChar
syn match scalaEscapedChar /\\[\\"'ntbrf]/
syn match scalaUnicodeChar /\\u[A-Fa-f0-9]\{4}/
2022-01-23 12:07:04 +00:00
hi def link scalaChar Character
hi def link scalaEscapedChar Special
hi def link scalaUnicodeChar Special
2016-08-26 19:52:37 +02:00
syn match scalaOperator "||"
syn match scalaOperator "&&"
2017-03-16 17:41:02 +01:00
syn match scalaOperator "|"
syn match scalaOperator "&"
2022-01-23 12:07:04 +00:00
hi def link scalaOperator Special
2016-08-26 19:52:37 +02:00
syn match scalaNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained nextgroup=scalaPostNameDefinition,scalaVariableDeclarationList
syn match scalaNameDefinition /`[^`]\+`/ contained nextgroup=scalaPostNameDefinition
syn match scalaVariableDeclarationList /\s*,\s*/ contained nextgroup=scalaNameDefinition
syn match scalaPostNameDefinition /\_s*:\_s*/ contained nextgroup=scalaTypeDeclaration
2022-01-23 12:07:04 +00:00
hi def link scalaNameDefinition Function
2016-08-26 19:52:37 +02:00
syn match scalaInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaInstanceHash
syn match scalaInstanceDeclaration /`[^`]\+`/ contained
syn match scalaInstanceHash /#/ contained nextgroup=scalaInstanceDeclaration
2022-01-23 12:07:04 +00:00
hi def link scalaInstanceDeclaration Special
hi def link scalaInstanceHash Type
2016-08-26 19:52:37 +02:00
syn match scalaUnimplemented /???/
2022-01-23 12:07:04 +00:00
hi def link scalaUnimplemented ERROR
2016-08-26 19:52:37 +02:00
syn match scalaCapitalWord /\<[A-Z][A-Za-z0-9$]*\>/
2022-01-23 12:07:04 +00:00
hi def link scalaCapitalWord Special
2016-08-26 19:52:37 +02:00
" Handle type declarations specially
syn region scalaTypeStatement matchgroup=Keyword start=/\<type\_s\+\ze/ end=/$/ contains=scalaTypeTypeDeclaration,scalaSquareBrackets,scalaTypeTypeEquals,scalaTypeStatement
" 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
2021-08-29 21:55:35 +02:00
syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypeDeclaration skipwhite
2016-08-26 19:52:37 +02:00
syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
2021-08-29 21:55:35 +02:00
syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypePostDeclaration skipwhite
2022-01-23 12:07:04 +00:00
hi def link scalaTypeTypeDeclaration Type
hi def link scalaTypeTypeExtension Keyword
hi def link scalaTypeTypePostDeclaration Special
hi def link scalaTypeTypePostExtension Keyword
2016-08-26 19:52:37 +02:00
syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
2021-08-29 21:55:35 +02:00
syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeDeclaration skipwhite
2022-01-23 12:07:04 +00:00
hi def link scalaTypeDeclaration Type
hi def link scalaTypeExtension Keyword
hi def link scalaTypePostExtension Keyword
2016-08-26 19:52:37 +02: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
2021-08-29 21:55:35 +02:00
hi clear scalaTypeAnnotation
2016-08-26 19:52:37 +02:00
2021-08-29 21:55:35 +02:00
syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained contains=scalaCapitalWord
syn match scalaCaseFollowing /`[^`]\+`/ contained contains=scalaCapitalWord
2022-01-23 12:07:04 +00:00
hi def link scalaCaseFollowing Special
2016-08-26 19:52:37 +02:00
2021-08-29 21:55:35 +02:00
syn keyword scalaKeywordModifier abstract override final lazy implicit private protected sealed null super
syn keyword scalaSpecialFunction implicitly require
2022-01-23 12:07:04 +00:00
hi def link scalaKeywordModifier Function
hi def link scalaSpecialFunction Function
2016-08-26 19:52:37 +02:00
syn keyword scalaSpecial this true false ne eq
syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
syn match scalaSpecial "\%(=>\|⇒\|<-\|←\|->\|→\)"
syn match scalaSpecial /`[^`]\+`/ " Backtick literals
2022-01-23 12:07:04 +00:00
hi def link scalaSpecial PreProc
2016-08-26 19:52:37 +02:00
syn keyword scalaExternal package import
2022-01-23 12:07:04 +00:00
hi def link scalaExternal Include
2016-08-26 19:52:37 +02:00
syn match scalaStringEmbeddedQuote /\\"/ contained
syn region scalaString start=/"/ end=/"/ contains=scalaStringEmbeddedQuote,scalaEscapedChar,scalaUnicodeChar
2022-01-23 12:07:04 +00:00
hi def link scalaString String
hi def link scalaStringEmbeddedQuote String
2016-08-26 19:52:37 +02:00
syn region scalaIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"/ skip=/\\"/ end=/"/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
2017-03-16 17:41:02 +01:00
syn region scalaTripleIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"""/ end=/"""\ze\%([^"]\|$\)/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
2022-01-23 12:07:04 +00:00
hi def link scalaIString String
hi def link scalaTripleIString String
2016-08-26 19:52:37 +02:00
syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
exe 'syn region scalaInterpolationB matchgroup=scalaInterpolationBoundary start=/\${/ end=/}/ contained contains=' . s:ContainedGroup()
2022-01-23 12:07:04 +00:00
hi def link scalaInterpolation Function
2021-08-29 21:55:35 +02:00
hi clear scalaInterpolationB
2016-08-26 19:52:37 +02:00
syn region scalaFString matchgroup=scalaInterpolationBrackets start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
exe 'syn region scalaFInterpolationB matchgroup=scalaInterpolationBoundary start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=' . s:ContainedGroup()
2022-01-23 12:07:04 +00:00
hi def link scalaFString String
hi def link scalaFInterpolation Function
2021-08-29 21:55:35 +02:00
hi clear scalaFInterpolationB
2016-08-26 19:52:37 +02:00
syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
syn region scalaTripleFString matchgroup=scalaInterpolationBrackets start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
2022-01-23 12:07:04 +00:00
hi def link scalaTripleString String
hi def link scalaTripleFString String
2016-08-26 19:52:37 +02:00
2022-01-23 12:07:04 +00:00
hi def link scalaInterpolationBrackets Special
hi def link scalaInterpolationBoundary Function
2016-08-26 19:52:37 +02: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
2022-01-23 12:07:04 +00:00
hi def link scalaNumber Number
2016-08-26 19:52:37 +02:00
syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets
syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter
syn match scalaTypeOperator /[-+=:<>]\+/ contained
syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained
2022-01-23 12:07:04 +00:00
hi def link scalaSquareBracketsBrackets Type
hi def link scalaTypeOperator Keyword
hi def link scalaTypeAnnotationParameter Function
2016-08-26 19:52:37 +02:00
syn match scalaShebang "\%^#!.*" display
syn region scalaMultilineComment start="/\*" end="\*/" contains=scalaMultilineComment,scalaDocLinks,scalaParameterAnnotation,scalaCommentAnnotation,scalaTodo,scalaCommentCodeBlock,@Spell keepend fold
syn match scalaCommentAnnotation "@[_A-Za-z0-9$]\+" contained
syn match scalaParameterAnnotation "\%(@tparam\|@param\|@see\)" nextgroup=scalaParamAnnotationValue skipwhite contained
syn match scalaParamAnnotationValue /[.`_A-Za-z0-9$]\+/ contained
syn region scalaDocLinks start="\[\[" end="\]\]" contained
syn region scalaCommentCodeBlock matchgroup=Keyword start="{{{" end="}}}" contained
syn match scalaTodo "\vTODO|FIXME|XXX" contained
2022-01-23 12:07:04 +00:00
hi def link scalaShebang Comment
hi def link scalaMultilineComment Comment
hi def link scalaDocLinks Function
hi def link scalaParameterAnnotation Function
hi def link scalaParamAnnotationValue Keyword
hi def link scalaCommentAnnotation Function
hi def link scalaCommentCodeBlock String
hi def link scalaTodo Todo
2016-08-26 19:52:37 +02:00
syn match scalaAnnotation /@\<[`_A-Za-z0-9$]\+\>/
2022-01-23 12:07:04 +00:00
hi def link scalaAnnotation PreProc
2016-08-26 19:52:37 +02:00
syn match scalaTrailingComment "//.*$" contains=scalaTodo,@Spell
2022-01-23 12:07:04 +00:00
hi def link scalaTrailingComment Comment
2016-08-26 19:52:37 +02: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\>/
2022-01-23 12:07:04 +00:00
hi def link scalaAkkaFSM PreProc
hi def link scalaAkkaFSMGotoUsing PreProc
2016-08-26 19:52:37 +02:00
let b:current_syntax = 'scala'
if main_syntax ==# 'scala'
unlet main_syntax
endif
" vim:set sw=2 sts=2 ts=8 et: