2 " Language: Erlang (http://www.erlang.org)
3 " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
4 " Last Update: 2013-Jul-25
6 " URL: https://github.com/hcs42/vim-erlang
8 " Acknowledgements: This script was originally created by Kresimir Marzic [1].
9 " The script was then revamped by Csaba Hoch [2]. During the revamp, the new
10 " highlighting style and some code was taken from the Erlang syntax script
11 " that is part of vimerl [3], created by Oscar Hellström [4] and improved by
12 " Ricardo Catalinas Jiménez [5].
14 " [1]: Kreąimir Marľić (Kresimir Marzic) <kmarzic@fly.srk.fer.hr>
15 " [2]: Csaba Hoch <csaba.hoch@gmail.com>
16 " [3]: https://github.com/jimenezrick/vimerl
17 " [4]: Oscar Hellström <oscar@oscarh.net> (http://oscar.hellstrom.st)
18 " [5]: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
22 " To use the old highlighting style, add this to your .vimrc:
24 " let g:erlang_old_style_highlight = 1
26 " To highlight further module attributes, add them to
27 " ~/.vim/after/syntax/erlang.vim:
29 " syn keyword erlangAttribute myattr1 myattr2 contained
31 " For version 5.x: Clear all syntax items
32 " For version 6.x: Quit when a syntax file was already loaded
35 elseif exists("b:current_syntax")
46 setlocal iskeyword+=$,@-@
50 syn match erlangComment '%.*$' contains=erlangCommentAnnotation,erlangTodo
51 syn match erlangCommentAnnotation ' \@<=@\%(clear\|docfile\|end\|headerfile\|todo\|TODO\|type\|author\|copyright\|doc\|reference\|see\|since\|title\|version\|deprecated\|hidden\|private\|equiv\|spec\|throws\)' contained
52 syn match erlangCommentAnnotation /`[^']*'/ contained
53 syn keyword erlangTodo TODO FIXME XXX contained
54 syn match erlangShebang '^#!.*'
56 " Numbers (minimum base is 2, maximum is 36.)
57 syn match erlangNumberInteger '\<\d\+\>'
58 syn match erlangNumberInteger '\<\%([2-9]\|[12]\d\|3[0-6]\)\+#[[:alnum:]]\+\>'
59 syn match erlangNumberFloat '\<\d\+\.\d\+\%([eE][+-]\=\d\+\)\=\>'
61 " Strings, atoms, characters
62 syn region erlangString start=/"/ end=/"/ contains=erlangStringModifier
63 syn region erlangQuotedAtom start=/'/ end=/'/ contains=erlangQuotedAtomModifier
64 syn match erlangStringModifier '\~\a\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
65 syn match erlangQuotedAtomModifier '\~\a\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
66 syn match erlangModifier '\$\%([^\\]\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\)'
68 " Operators, separators
69 syn match erlangOperator '==\|=:=\|/=\|=/=\|<\|=<\|>\|>=\|++\|--\|=\|!\|<-\|+\|-\|\*\|\/'
70 syn keyword erlangOperator div rem or xor bor bxor bsl bsr and band not bnot andalso orelse
71 syn match erlangBracket '{\|}\|\[\|]\||\|||'
72 syn match erlangPipe '|'
73 syn match erlangRightArrow '->'
75 " Atoms, function calls (order is important)
76 syn match erlangAtom '\<\l[[:alnum:]_@]*' contains=erlangBoolean
77 syn keyword erlangBoolean true false contained
78 syn match erlangLocalFuncCall '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangBIF
79 syn match erlangLocalFuncRef '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@='
80 syn match erlangGlobalFuncCall '\<\%(\a[[:alnum:]_@]*\%(\s\|\n\|%.*\n\)*\.\%(\s\|\n\|%.*\n\)*\)*\a[[:alnum:]_@]*\%(\s\|\n\|%.*\n\)*:\%(\s\|\n\|%.*\n\)*\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangComment
81 syn match erlangGlobalFuncRef '\<\%(\a[[:alnum:]_@]*\%(\s\|\n\|%.*\n\)*\.\%(\s\|\n\|%.*\n\)*\)*\a[[:alnum:]_@]*\%(\s\|\n\|%.*\n\)*:\%(\s\|\n\|%.*\n\)*\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@=' contains=erlangComment
83 " Variables, macros, records
84 syn match erlangVariable '\<[A-Z_][[:alnum:]_@]*'
85 syn match erlangMacro '??\=[[:alnum:]_@]\+'
86 syn match erlangMacro '\%(-define(\)\@<=[[:alnum:]_@]\+'
87 syn match erlangRecord '#\s*\l[[:alnum:]_@]*'
90 syn match erlangBitType '\%(\/\%(\s\|\n\|%.*\n\)*\)\@<=\%(integer\|float\|binary\|bytes\|bitstring\|bits\|binary\|utf8\|utf16\|utf32\|signed\|unsigned\|big\|little\|native\|unit\)\%(\%(\s\|\n\|%.*\n\)*-\%(\s\|\n\|%.*\n\)*\%(integer\|float\|binary\|bytes\|bitstring\|bits\|binary\|utf8\|utf16\|utf32\|signed\|unsigned\|big\|little\|native\|unit\)\)*' contains=erlangComment
92 " Constants and Directives
93 syn match erlangUnknownAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\l[[:alnum:]_@]*' contains=erlangComment
94 syn match erlangAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(behaviou\=r\|compile\|export\(_type\)\=\|file\|import\|module\|author\|copyright\|doc\|vsn\|on_load\)\>' contains=erlangComment
95 syn match erlangInclude '^\s*-\%(\s\|\n\|%.*\n\)*\%(include\|include_lib\)\>' contains=erlangComment
96 syn match erlangRecordDef '^\s*-\%(\s\|\n\|%.*\n\)*record\>' contains=erlangComment
97 syn match erlangDefine '^\s*-\%(\s\|\n\|%.*\n\)*\%(define\|undef\)\>' contains=erlangComment
98 syn match erlangPreCondit '^\s*-\%(\s\|\n\|%.*\n\)*\%(ifdef\|ifndef\|else\|endif\)\>' contains=erlangComment
99 syn match erlangType '^\s*-\%(\s\|\n\|%.*\n\)*\%(spec\|type\|opaque\|callback\)\>' contains=erlangComment
102 syn keyword erlangKeyword after begin case catch cond end fun if let of query
103 syn keyword erlangKeyword receive when try
105 " Build-in-functions (BIFs)
106 syn keyword erlangBIF abs alive apply atom_to_binary atom_to_list contained
107 syn keyword erlangBIF binary_part binary_to_atom contained
108 syn keyword erlangBIF binary_to_existing_atom binary_to_float contained
109 syn keyword erlangBIF binary_to_integer bitstring_to_list contained
110 syn keyword erlangBIF binary_to_list binary_to_term bit_size contained
111 syn keyword erlangBIF byte_size check_old_code check_process_code contained
112 syn keyword erlangBIF concat_binary date delete_module demonitor contained
113 syn keyword erlangBIF disconnect_node element erase error exit contained
114 syn keyword erlangBIF float float_to_binary float_to_list contained
115 syn keyword erlangBIF garbage_collect get get_keys group_leader contained
116 syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained
117 syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained
118 syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained
119 syn keyword erlangBIF is_float is_function is_integer is_list contained
120 syn keyword erlangBIF is_number is_pid is_port is_process_alive contained
121 syn keyword erlangBIF is_record is_reference is_tuple length link contained
122 syn keyword erlangBIF list_to_atom list_to_binary contained
123 syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained
124 syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained
125 syn keyword erlangBIF list_to_tuple load_module make_ref max min contained
126 syn keyword erlangBIF module_loaded monitor monitor_node node contained
127 syn keyword erlangBIF nodes now open_port pid_to_list port_close contained
128 syn keyword erlangBIF port_command port_connect pre_loaded contained
129 syn keyword erlangBIF process_flag process_flag process_info contained
130 syn keyword erlangBIF process purge_module put register registered contained
131 syn keyword erlangBIF round self setelement size spawn spawn_link contained
132 syn keyword erlangBIF spawn_monitor spawn_opt split_binary contained
133 syn keyword erlangBIF statistics term_to_binary throw time tl contained
134 syn keyword erlangBIF trunc tuple_size tuple_to_list unlink contained
135 syn keyword erlangBIF unregister whereis contained
137 " Sync at the beginning of functions: if this is not used, multiline string
138 " are not always recognized, and the indentation script cannot use the
139 " "searchpair" (because it would not always skip strings and comments when
140 " looking for keywords and opening parens/brackets).
141 syn sync match erlangSync grouphere NONE "^[a-z]\s*("
142 let b:erlang_syntax_synced = 1
144 " Define the default highlighting. See ":help group-name" for the groups and
147 let s:old_style = (exists("g:erlang_old_style_highlight") &&
148 \g:erlang_old_style_highlight == 1)
150 " For version 5.7 and earlier: only when not done already
151 " For version 5.8 and later: only when an item doesn't have highlighting yet
152 if version >= 508 || !exists("did_erlang_inits")
154 let did_erlang_inits = 1
155 command -nargs=+ HiLink hi link <args>
157 command -nargs=+ HiLink hi def link <args>
161 HiLink erlangComment Comment
162 HiLink erlangCommentAnnotation Special
163 HiLink erlangTodo Todo
164 HiLink erlangShebang Comment
167 HiLink erlangNumberInteger Number
168 HiLink erlangNumberFloat Float
170 " Strings, atoms, characters
171 HiLink erlangString String
174 HiLink erlangQuotedAtom Type
176 HiLink erlangQuotedAtom String
179 HiLink erlangStringModifier Special
180 HiLink erlangQuotedAtomModifier Special
181 HiLink erlangModifier Special
183 " Operators, separators
184 HiLink erlangOperator Operator
185 HiLink erlangRightArrow Operator
187 HiLink erlangBracket Normal
188 HiLink erlangPipe Normal
190 HiLink erlangBracket Delimiter
191 HiLink erlangPipe Delimiter
194 " Atoms, functions, variables, macros
196 HiLink erlangAtom Normal
197 HiLink erlangLocalFuncCall Normal
198 HiLink erlangLocalFuncRef Normal
199 HiLink erlangGlobalFuncCall Function
200 HiLink erlangGlobalFuncRef Function
201 HiLink erlangVariable Normal
202 HiLink erlangMacro Normal
203 HiLink erlangRecord Normal
205 HiLink erlangAtom String
206 HiLink erlangLocalFuncCall Normal
207 HiLink erlangLocalFuncRef Normal
208 HiLink erlangGlobalFuncCall Normal
209 HiLink erlangGlobalFuncRef Normal
210 HiLink erlangVariable Identifier
211 HiLink erlangMacro Macro
212 HiLink erlangRecord Structure
217 HiLink erlangBitType Type
220 " Constants and Directives
222 HiLink erlangAttribute Type
223 HiLink erlangMacroDef Type
224 HiLink erlangUnknownAttribute Normal
225 HiLink erlangInclude Type
226 HiLink erlangRecordDef Type
227 HiLink erlangDefine Type
228 HiLink erlangPreCondit Type
229 HiLink erlangType Type
231 HiLink erlangAttribute Keyword
232 HiLink erlangMacroDef Macro
233 HiLink erlangUnknownAttribute Normal
234 HiLink erlangInclude Include
235 HiLink erlangRecordDef Keyword
236 HiLink erlangDefine Define
237 HiLink erlangPreCondit PreCondit
238 HiLink erlangType Type
242 HiLink erlangKeyword Keyword
244 " Build-in-functions (BIFs)
245 HiLink erlangBIF Function
248 HiLink erlangBoolean Statement
249 HiLink erlangExtra Statement
250 HiLink erlangSignal Statement
252 HiLink erlangBoolean Boolean
253 HiLink erlangExtra Statement
254 HiLink erlangSignal Statement
260 let b:current_syntax = "erlang"
262 let &cpo = s:cpo_save