vim-polyglot/syntax/elixir.vim

177 lines
12 KiB
VimL
Raw Normal View History

2013-09-12 11:31:56 -04:00
" Vim syntax file
" Language: Elixir
" Maintainer: Carlos Galdino <carloshsgaldino@gmail.com>
" Last Change: 2013 Apr 24
if exists("b:current_syntax")
finish
endif
" syncing starts 2000 lines before top line so docstrings don't screw things up
syn sync minlines=2000
syn cluster elixirNotTop contains=@elixirRegexSpecial,@elixirStringContained,@elixirDeclaration,elixirTodo,elixirArguments
syn match elixirComment '#.*' contains=elixirTodo
syn keyword elixirTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained
syn keyword elixirKeyword is_atom is_binary is_bitstring is_boolean is_float is_function is_integer is_list is_number is_pid is_port is_record is_reference is_tuple is_exception
2014-06-08 07:18:33 -04:00
syn keyword elixirKeyword case cond for if unless try receive send
2014-03-10 19:36:09 -04:00
syn keyword elixirKeyword exit raise throw after rescue catch else do end
2013-12-12 19:37:01 -05:00
syn keyword elixirKeyword quote unquote super
2013-09-12 11:31:56 -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-06-08 07:18:33 -04:00
syn match elixirId '\<[_a-zA-Z]\w*[!?]\?\>'
" This unfortunately also matches function names in function calls
syn match elixirUnusedVariable '\<_\w*\>'
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn keyword elixirOperator and not or when xor in
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
2014-06-08 07:18:33 -04:00
syn match elixirAlias '\<[A-Z]\w*\(\.[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__
syn match elixirNumber '\<\d\(_\?\d\)*\(\.[^[:space:][:digit:]]\@!\(_\?\d\)*\)\?\([eE][-+]\?\d\(_\?\d\)*\)\?\>'
syn match elixirNumber '\<0[xX][0-9A-Fa-f]\+\>'
syn match elixirNumber '\<0[bB][01]\+\>'
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
syn region elixirRegex matchgroup=elixirDelimiter start="%r/" end="/[uiomxfr]*" skip="\\\\" contains=@elixirRegexSpecial
syn cluster elixirRegexSpecial contains=elixirRegexEscape,elixirRegexCharClass,elixirRegexQuantifier,elixirRegexEscapePunctuation
syn cluster elixirStringContained contains=elixirInterpolation,elixirRegexEscape,elixirRegexCharClass
syn region elixirString matchgroup=elixirDelimiter start="'" end="'" skip="\\'"
syn region elixirString matchgroup=elixirDelimiter start='"' end='"' skip='\\"' contains=@elixirStringContained
syn region elixirInterpolation matchgroup=elixirDelimiter start="#{" end="}" contained contains=ALLBUT,elixirComment,@elixirNotTop
syn region elixirDocStringStart matchgroup=elixirDocString start=+"""+ end=+$+ oneline contains=ALLBUT,@elixirNotTop
syn region elixirDocStringStart matchgroup=elixirDocString start=+'''+ end=+$+ oneline contains=ALLBUT,@elixirNotTop
2014-01-09 05:59:09 -05:00
syn region elixirDocString start=+\z("""\)+ end=+^\s*\zs\z1+ contains=elixirDocStringStart,elixirTodo,elixirInterpolation fold keepend
syn region elixirDocString start=+\z('''\)+ end=+^\s*\zs\z1+ contains=elixirDocStringStart,elixirTodo,elixirInterpolation fold keepend
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\\]\)"
syn region elixirBlock matchgroup=elixirKeyword start="\<do\>\(:\)\@!" end="\<end\>" contains=ALLBUT,@elixirNotTop fold
syn region elixirAnonymousFunction matchgroup=elixirKeyword start="\<fn\>" end="\<end\>" contains=ALLBUT,@elixirNotTop fold
2014-06-08 07:18:33 -04:00
syn region elixirArguments start="(" end=")" contained contains=elixirOperator,elixirAtom,elixirPseudoVariable,elixirAlias,elixirBoolean,elixirVariable,elixirUnusedVariable,elixirNumber,elixirDocString,elixirAtomInterpolated,elixirRegex,elixirString,elixirDelimiter
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-06-08 07:18:33 -04:00
syn region elixirSigil matchgroup=elixirDelimiter start="\~\u\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirDelimiter start="\~\u{" end="}" skip="\\\\\|\\}" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirDelimiter start="\~\u<" end=">" skip="\\\\\|\\>" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirDelimiter start="\~\u\[" end="\]" skip="\\\\\|\\\]" contains=elixirDelimEscape fold
syn region elixirSigil matchgroup=elixirDelimiter start="\~\u(" end=")" skip="\\\\\|\\)" contains=elixirDelimEscape fold
2013-09-12 11:31:56 -04:00
2014-06-08 07:18:33 -04:00
syn region elixirSigil matchgroup=elixirDelimiter start="\~\l\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" fold
syn region elixirSigil matchgroup=elixirDelimiter start="\~\l{" end="}" skip="\\\\\|\\}" fold contains=@elixirStringContained,elixirRegexEscapePunctuation
syn region elixirSigil matchgroup=elixirDelimiter start="\~\l<" end=">" skip="\\\\\|\\>" fold contains=@elixirStringContained,elixirRegexEscapePunctuation
syn region elixirSigil matchgroup=elixirDelimiter start="\~\l\[" end="\]" skip="\\\\\|\\\]" fold contains=@elixirStringContained,elixirRegexEscapePunctuation
syn region elixirSigil matchgroup=elixirDelimiter start="\~\l(" end=")" skip="\\\\\|\\)" fold contains=@elixirStringContained,elixirRegexEscapePunctuation
2013-09-12 11:31:56 -04:00
2014-01-24 12:06:22 -05:00
" Sigils surrounded with docString
2014-06-08 07:18:33 -04:00
syn region elixirSigil matchgroup=elixirDelimiter start=+\~\a\z("""\)+ end=+^\s*\zs\z1+ skip=+\\"+ fold
syn region elixirSigil matchgroup=elixirDelimiter start=+\~\a\z('''\)+ end=+^\s*\zs\z1+ skip=+\\'+ fold
2014-01-24 12:06:22 -05:00
2013-09-12 11:31:56 -04:00
" Defines
syn keyword elixirDefine def nextgroup=elixirFunctionDeclaration skipwhite skipnl
syn keyword elixirPrivateDefine defp nextgroup=elixirFunctionDeclaration skipwhite skipnl
syn keyword elixirModuleDefine defmodule nextgroup=elixirModuleDeclaration skipwhite skipnl
syn keyword elixirProtocolDefine defprotocol nextgroup=elixirProtocolDeclaration skipwhite skipnl
syn keyword elixirImplDefine defimpl nextgroup=elixirImplDeclaration skipwhite skipnl
syn keyword elixirRecordDefine defrecord nextgroup=elixirRecordDeclaration skipwhite skipnl
syn keyword elixirPrivateRecordDefine defrecordp nextgroup=elixirRecordDeclaration skipwhite skipnl
syn keyword elixirMacroDefine defmacro nextgroup=elixirMacroDeclaration skipwhite skipnl
syn keyword elixirPrivateMacroDefine defmacrop nextgroup=elixirMacroDeclaration skipwhite skipnl
syn keyword elixirDelegateDefine defdelegate nextgroup=elixirDelegateDeclaration skipwhite skipnl
syn keyword elixirOverridableDefine defoverridable nextgroup=elixirOverridableDeclaration skipwhite skipnl
syn keyword elixirExceptionDefine defexception nextgroup=elixirExceptionDeclaration skipwhite skipnl
syn keyword elixirCallbackDefine defcallback nextgroup=elixirCallbackDeclaration skipwhite skipnl
2014-06-08 07:18:33 -04:00
syn keyword elixirStructDefine defstruct nextgroup=elixirStructDeclaration skipwhite skipnl
2013-09-12 11:31:56 -04:00
" Declarations
2014-06-08 07:18:33 -04:00
syn match elixirModuleDeclaration "[^[:space:];#<]\+" contained contains=elixirAlias nextgroup=elixirBlock skipwhite skipnl
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
syn match elixirStructDeclaration "[^[:space:];#<]\+" contained nextgroup=elixirArguments skipwhite skipnl
syn cluster elixirDeclaration contains=elixirFunctionDeclaration,elixirModuleDeclaration,elixirProtocolDeclaration,elixirImplDeclaration,elixirRecordDeclaration,elixirMacroDeclaration,elixirDelegateDeclaration,elixirOverridableDeclaration,elixirExceptionDeclaration,elixirCallbackDeclaration,elixirStructDeclaration
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
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
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
hi def link elixirUnusedVariable Comment
hi def link elixirNumber Number
2014-01-24 12:06:22 -05:00
hi def link elixirDocString String
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
hi def link elixirDelimiter Delimiter