vim-polyglot/syntax/elixir.vim

233 lines
16 KiB
VimL
Raw Normal View History

if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
2013-09-12 11:31:56 -04:00
if exists("b:current_syntax")
finish
endif
2016-09-11 07:24:17 -04:00
let s:cpo_save = &cpo
set cpo&vim
2013-09-12 11:31:56 -04:00
" syncing starts 2000 lines before top line so docstrings don't screw things up
syn sync minlines=2000
2017-02-02 15:16:29 -05:00
syn cluster elixirNotTop contains=@elixirRegexSpecial,@elixirStringContained,@elixirDeclaration,elixirTodo,elixirArguments,elixirBlockDefinition,elixirUnusedVariable,elixirStructDelimiter
2016-09-11 07:24:17 -04:00
syn cluster elixirRegexSpecial contains=elixirRegexEscape,elixirRegexCharClass,elixirRegexQuantifier,elixirRegexEscapePunctuation
syn cluster elixirStringContained contains=elixirInterpolation,elixirRegexEscape,elixirRegexCharClass
syn cluster elixirDeclaration contains=elixirFunctionDeclaration,elixirModuleDeclaration,elixirProtocolDeclaration,elixirImplDeclaration,elixirRecordDeclaration,elixirMacroDeclaration,elixirDelegateDeclaration,elixirOverridableDeclaration,elixirExceptionDeclaration,elixirCallbackDeclaration,elixirStructDeclaration
2013-09-12 11:31:56 -04:00
2016-12-20 14:57:20 -05:00
syn match elixirComment '#.*' contains=elixirTodo,@Spell
2013-09-12 11:31:56 -04:00
syn keyword elixirTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained
2017-09-27 13:57:29 -04:00
syn match elixirId '\<[_a-zA-Z]\w*[!?]\?\>' contains=elixirUnusedVariable,elixirKernelFunction
2016-12-20 14:57:20 -05:00
syn match elixirKeyword '\(\.\)\@<!\<\(for\|case\|when\|with\|cond\|if\|unless\|try\|receive\|send\)\>'
syn match elixirKeyword '\(\.\)\@<!\<\(exit\|raise\|throw\|after\|rescue\|catch\|else\)\>'
syn match elixirKeyword '\(\.\)\@<!\<\(quote\|unquote\|super\|spawn\|spawn_link\|spawn_monitor\)\>'
2013-09-12 11:31:56 -04:00
2016-12-20 14:57:20 -05:00
" Kernel functions
2017-09-27 13:57:29 -04:00
syn keyword elixirKernelFunction contained is_atom is_binary is_bitstring is_boolean is_float
syn keyword elixirKernelFunction contained is_function is_integer is_list is_map is_nil
syn keyword elixirKernelFunction contained is_number is_pid is_port is_reference is_tuple
syn keyword elixirKernelFunction contained abs binary_part bit_size byte_size div elem hd length
syn keyword elixirKernelFunction contained map_size node rem round tl trunc tuple_size
2015-05-24 17:42:59 -04:00
2013-12-12 19:37:01 -05:00
syn keyword elixirInclude import require alias use
2013-09-12 11:31:56 -04:00
2014-12-09 17:09:20 -05:00
syn keyword elixirSelf self
2014-06-08 07:18:33 -04:00
" This unfortunately also matches function names in function calls
2017-09-27 13:57:29 -04:00
syn match elixirUnusedVariable contained '\v%(^|[^.])@<=<_\w*>'
2013-09-12 11:31:56 -04:00
2017-09-27 13:57:29 -04:00
syn match elixirOperator '\v\.@<!<%(and|or|in|not)>'
2014-06-08 07:18:33 -04:00
syn match elixirOperator '!==\|!=\|!'
syn match elixirOperator '=\~\|===\|==\|='
syn match elixirOperator '<<<\|<<\|<=\|<-\|<'
syn match elixirOperator '>>>\|>>\|>=\|>'
syn match elixirOperator '->\|--\|-'
syn match elixirOperator '++\|+'
syn match elixirOperator '&&&\|&&\|&'
syn match elixirOperator '|||\|||\||>\||'
syn match elixirOperator '\.\.\|\.'
syn match elixirOperator "\^\^\^\|\^"
syn match elixirOperator '\\\\\|::\|\*\|/\|\~\~\~\|@'
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn match elixirAtom '\(:\)\@<!:\%([a-zA-Z_]\w*\%([?!]\|=[>=]\@!\)\?\|<>\|===\?\|>=\?\|<=\?\)'
syn match elixirAtom '\(:\)\@<!:\%(<=>\|&&\?\|%\(()\|\[\]\|{}\)\|++\?\|--\?\|||\?\|!\|//\|[%&`/|]\)'
syn match elixirAtom "\%([a-zA-Z_]\w*[?!]\?\):\(:\)\@!"
2013-09-12 11:31:56 -04:00
2017-02-02 15:16:29 -05:00
syn match elixirAlias '\([a-z]\)\@<![A-Z]\w*'
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn keyword elixirBoolean true false nil
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn match elixirVariable '@[a-z]\w*'
syn match elixirVariable '&\d\+'
2013-09-12 11:31:56 -04:00
syn keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__
2017-12-30 05:10:32 -05:00
syn match elixirNumber '\<-\?\d\(_\?\d\)*\(\.[^[:space:][:digit:]]\@!\(_\?\d\)*\)\?\([eE][-+]\?\d\(_\?\d\)*\)\?\>'
syn match elixirNumber '\<-\?0[xX][0-9A-Fa-f]\+\>'
syn match elixirNumber '\<-\?0[oO][0-7]\+\>'
syn match elixirNumber '\<-\?0[bB][01]\+\>'
2013-09-12 11:31:56 -04:00
syn match elixirRegexEscape "\\\\\|\\[aAbBcdDefGhHnrsStvVwW]\|\\\d\{3}\|\\x[0-9a-fA-F]\{2}" contained
syn match elixirRegexEscapePunctuation "?\|\\.\|*\|\\\[\|\\\]\|+\|\\^\|\\\$\|\\|\|\\(\|\\)\|\\{\|\\}" contained
syn match elixirRegexQuantifier "[*?+][?+]\=" contained display
syn match elixirRegexQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display
syn match elixirRegexCharClass "\[:\(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained display
2014-11-10 20:37:21 -05:00
syn region elixirRegex matchgroup=elixirRegexDelimiter start="%r/" end="/[uiomxfr]*" skip="\\\\" contains=@elixirRegexSpecial
2013-09-12 11:31:56 -04:00
2017-02-02 15:16:29 -05:00
syn region elixirTuple matchgroup=elixirTupleDelimiter start="\(\w\|#\)\@<!{" end="}" contains=ALLBUT,@elixirNotTop
syn match elixirStructDelimiter '{' contained containedin=elixirStruct
syn region elixirStruct matchgroup=elixirStructDelimiter start="%\(\w\+{\)\@=" end="}" contains=ALLBUT,@elixirNotTop
syn region elixirMap matchgroup=elixirMapDelimiter start="%{" end="}" contains=ALLBUT,@elixirNotTop
2017-09-27 13:57:29 -04:00
syn region elixirString matchgroup=elixirStringDelimiter start=+\z('\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@Spell,@elixirStringContained
syn region elixirString matchgroup=elixirStringDelimiter start=+\z("\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@Spell,@elixirStringContained
syn region elixirString matchgroup=elixirStringDelimiter start=+\z('''\)+ end=+^\s*\z1+ contains=@Spell,@elixirStringContained
syn region elixirString matchgroup=elixirStringDelimiter start=+\z("""\)+ end=+^\s*\z1+ contains=@Spell,@elixirStringContained
2016-12-20 14:57:20 -05:00
syn region elixirInterpolation matchgroup=elixirInterpolationDelimiter start="#{" end="}" contained contains=ALLBUT,elixirKernelFunction,elixirComment,@elixirNotTop
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn match elixirAtomInterpolated ':\("\)\@=' contains=elixirString
2013-09-12 11:31:56 -04:00
syn match elixirString "\(\w\)\@<!?\%(\\\(x\d{1,2}\|\h{1,2}\h\@!\>\|0[0-7]{0,2}[0-7]\@!\>\|[^x0MC]\)\|(\\[MC]-)+\w\|[^\s\\]\)"
2016-12-20 14:57:20 -05:00
syn region elixirBlock matchgroup=elixirBlockDefinition start="\<do\>:\@!" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
syn region elixirElseBlock matchgroup=elixirBlockDefinition start="\<else\>:\@!" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
syn region elixirAnonymousFunction matchgroup=elixirBlockDefinition start="\<fn\>" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
2013-09-12 11:31:56 -04:00
2017-09-27 13:57:29 -04:00
syn region elixirArguments start="(" end=")" contained contains=elixirOperator,elixirAtom,elixirPseudoVariable,elixirAlias,elixirBoolean,elixirVariable,elixirUnusedVariable,elixirNumber,elixirDocString,elixirAtomInterpolated,elixirRegex,elixirString,elixirStringDelimiter,elixirRegexDelimiter,elixirInterpolationDelimiter,elixirSigil,elixirAnonymousFunction
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn match elixirDelimEscape "\\[(<{\[)>}\]/\"'|]" transparent display contained contains=NONE
2013-09-12 11:31:56 -04:00
2014-11-10 20:37:21 -05:00
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\u\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\u{" end="}" skip="\\\\\|\\}" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\u<" end=">" skip="\\\\\|\\>" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\u\[" end="\]" skip="\\\\\|\\\]" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\u(" end=")" skip="\\\\\|\\)" contains=elixirDelimEscape fold
2013-09-12 11:31:56 -04:00
2016-01-22 03:08:00 -05:00
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l{" end="}" skip="\\\\\|\\}" contains=@elixirStringContained,elixirRegexEscapePunctuation fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l<" end=">" skip="\\\\\|\\>" contains=@elixirStringContained,elixirRegexEscapePunctuation fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\[" end="\]" skip="\\\\\|\\\]" contains=@elixirStringContained,elixirRegexEscapePunctuation fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l(" end=")" skip="\\\\\|\\)" contains=@elixirStringContained,elixirRegexEscapePunctuation fold
2016-12-20 14:57:20 -05:00
syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\/" end="\/" skip="\\\\\|\\\/" contains=@elixirStringContained,elixirRegexEscapePunctuation fold
" Sigils surrounded with heredoc
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\zs\z1\s*$+ skip=+\\"+ fold
syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z('''\)+ end=+^\s*\zs\z1\s*$+ skip=+\\'+ fold
" Documentation
if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs
syn include @markdown syntax/markdown.vim
2017-11-19 15:26:59 -05:00
syn cluster elixirDocStringContained contains=@markdown,@Spell,elixirInterpolation
2016-12-20 14:57:20 -05:00
else
let g:elixir_use_markdown_for_docs = 0
2017-11-19 15:26:59 -05:00
syn cluster elixirDocStringContained contains=elixirDocTest,elixirTodo,@Spell,elixirInterpolation
2016-12-20 14:57:20 -05:00
" doctests
syn region elixirDocTest start="^\s*\%(iex\|\.\.\.\)\%((\d*)\)\?>\s" end="^\s*$" contained
endif
2013-09-12 11:31:56 -04:00
2016-12-20 14:57:20 -05:00
syn region elixirDocString matchgroup=elixirSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]{" end="}" skip="\\\\\|\\}" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]<" end=">" skip="\\\\\|\\>" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]\[" end="\]" skip="\\\\\|\\\]" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss](" end=")" skip="\\\\\|\\)" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirStringDelimiter start=+\%(@\w*doc\s\+\)\@<=\z("\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@elixirDocStringContained keepend
syn region elixirDocString matchgroup=elixirStringDelimiter start=+\%(@\w*doc\s\+\)\@<=\z("""\)+ end=+\z1+ contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start=+\%(@\w*doc\s\+\)\@<=\~[Ss]\z('''\)+ end=+\z1+ skip=+\\'+ contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirSigilDelimiter start=+\%(@\w*doc\s\+\)\@<=\~[Ss]\z("""\)+ end=+\z1+ skip=+\\"+ contains=@elixirDocStringContained fold keepend
2014-01-24 12:06:22 -05:00
2013-09-12 11:31:56 -04:00
" Defines
2016-12-20 14:57:20 -05:00
syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
syn match elixirPrivateDefine '\<defp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
syn match elixirModuleDefine '\<defmodule\>\(:\)\@!' nextgroup=elixirModuleDeclaration skipwhite skipnl
syn match elixirProtocolDefine '\<defprotocol\>\(:\)\@!' nextgroup=elixirProtocolDeclaration skipwhite skipnl
syn match elixirImplDefine '\<defimpl\>\(:\)\@!' nextgroup=elixirImplDeclaration skipwhite skipnl
syn match elixirRecordDefine '\<defrecord\>\(:\)\@!' nextgroup=elixirRecordDeclaration skipwhite skipnl
syn match elixirPrivateRecordDefine '\<defrecordp\>\(:\)\@!' nextgroup=elixirRecordDeclaration skipwhite skipnl
syn match elixirMacroDefine '\<defmacro\>\(:\)\@!' nextgroup=elixirMacroDeclaration skipwhite skipnl
syn match elixirPrivateMacroDefine '\<defmacrop\>\(:\)\@!' nextgroup=elixirMacroDeclaration skipwhite skipnl
syn match elixirDelegateDefine '\<defdelegate\>\(:\)\@!' nextgroup=elixirDelegateDeclaration skipwhite skipnl
syn match elixirOverridableDefine '\<defoverridable\>\(:\)\@!' nextgroup=elixirOverridableDeclaration skipwhite skipnl
syn match elixirExceptionDefine '\<defexception\>\(:\)\@!' nextgroup=elixirExceptionDeclaration skipwhite skipnl
syn match elixirCallbackDefine '\<defcallback\>\(:\)\@!' nextgroup=elixirCallbackDeclaration skipwhite skipnl
syn match elixirStructDefine '\<defstruct\>\(:\)\@!' skipwhite skipnl
2013-09-12 11:31:56 -04:00
" Declarations
2016-07-26 07:43:53 -04:00
syn match elixirModuleDeclaration "[^[:space:];#<]\+" contained nextgroup=elixirBlock skipwhite skipnl
2014-06-08 07:18:33 -04:00
syn match elixirFunctionDeclaration "[^[:space:];#<,()\[\]]\+" contained nextgroup=elixirArguments skipwhite skipnl
syn match elixirProtocolDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias skipwhite skipnl
syn match elixirImplDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias skipwhite skipnl
syn match elixirRecordDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias,elixirAtom skipwhite skipnl
syn match elixirMacroDeclaration "[^[:space:];#<,()\[\]]\+" contained nextgroup=elixirArguments skipwhite skipnl
syn match elixirDelegateDeclaration "[^[:space:];#<,()\[\]]\+" contained contains=elixirFunctionDeclaration skipwhite skipnl
syn region elixirDelegateDeclaration start='\[' end='\]' contained contains=elixirFunctionDeclaration skipwhite skipnl
syn match elixirOverridableDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias skipwhite skipnl
syn match elixirExceptionDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias skipwhite skipnl
syn match elixirCallbackDeclaration "[^[:space:];#<,()\[\]]\+" contained contains=elixirFunctionDeclaration skipwhite skipnl
2016-12-20 14:57:20 -05:00
" ExUnit
syn match elixirExUnitMacro "\(^\s*\)\@<=\<\(test\|describe\|setup\|setup_all\|on_exit\|doctest\)\>"
syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(assert\|assert_in_delta\|assert_raise\|assert_receive\|assert_received\|catch_error\)\>"
syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(catch_exit\|catch_throw\|flunk\|refute\|refute_in_delta\|refute_receive\|refute_received\)\>"
2016-01-22 03:08:00 -05:00
hi def link elixirBlockDefinition Keyword
2013-09-12 11:31:56 -04:00
hi def link elixirDefine Define
hi def link elixirPrivateDefine Define
hi def link elixirModuleDefine Define
hi def link elixirProtocolDefine Define
hi def link elixirImplDefine Define
hi def link elixirRecordDefine Define
hi def link elixirPrivateRecordDefine Define
hi def link elixirMacroDefine Define
hi def link elixirPrivateMacroDefine Define
hi def link elixirDelegateDefine Define
hi def link elixirOverridableDefine Define
hi def link elixirExceptionDefine Define
hi def link elixirCallbackDefine Define
2014-06-08 07:18:33 -04:00
hi def link elixirStructDefine Define
2016-12-20 14:57:20 -05:00
hi def link elixirExUnitMacro Define
2016-09-11 07:24:17 -04:00
hi def link elixirModuleDeclaration Type
2013-09-12 11:31:56 -04:00
hi def link elixirFunctionDeclaration Function
hi def link elixirMacroDeclaration Macro
hi def link elixirInclude Include
hi def link elixirComment Comment
hi def link elixirTodo Todo
hi def link elixirKeyword Keyword
2016-12-20 14:57:20 -05:00
hi def link elixirExUnitAssert Keyword
hi def link elixirKernelFunction Keyword
2013-09-12 11:31:56 -04:00
hi def link elixirOperator Operator
2014-06-08 07:18:33 -04:00
hi def link elixirAtom Constant
2013-09-12 11:31:56 -04:00
hi def link elixirPseudoVariable Constant
2014-06-08 07:18:33 -04:00
hi def link elixirAlias Type
2013-09-12 11:31:56 -04:00
hi def link elixirBoolean Boolean
hi def link elixirVariable Identifier
2014-12-09 17:09:20 -05:00
hi def link elixirSelf Identifier
2013-09-12 11:31:56 -04:00
hi def link elixirUnusedVariable Comment
hi def link elixirNumber Number
2016-09-11 07:24:17 -04:00
hi def link elixirDocString Comment
2016-12-20 14:57:20 -05:00
hi def link elixirDocTest elixirKeyword
2014-06-08 07:18:33 -04:00
hi def link elixirAtomInterpolated elixirAtom
2013-09-12 11:31:56 -04:00
hi def link elixirRegex elixirString
hi def link elixirRegexEscape elixirSpecial
hi def link elixirRegexEscapePunctuation elixirSpecial
hi def link elixirRegexCharClass elixirSpecial
hi def link elixirRegexQuantifier elixirSpecial
hi def link elixirSpecial Special
hi def link elixirString String
hi def link elixirSigil String
2014-11-10 20:37:21 -05:00
hi def link elixirStringDelimiter Delimiter
hi def link elixirRegexDelimiter Delimiter
hi def link elixirInterpolationDelimiter Delimiter
hi def link elixirSigilDelimiter Delimiter
2016-05-02 04:42:37 -04:00
let b:current_syntax = "elixir"
2016-09-11 07:24:17 -04:00
let &cpo = s:cpo_save
unlet s:cpo_save
endif