7
|
1 " Vim syntax file
|
4437
|
2 " Language: Erlang (http://www.erlang.org)
|
|
3 " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
|
5277
|
4 " Last Update: 2013-Jul-25
|
3281
|
5 " License: Vim license
|
4437
|
6 " URL: https://github.com/hcs42/vim-erlang
|
7
|
7
|
4780
|
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].
|
|
13
|
|
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>
|
|
19
|
4437
|
20 " Customization:
|
|
21 "
|
4780
|
22 " To use the old highlighting style, add this to your .vimrc:
|
4437
|
23 "
|
4780
|
24 " let g:erlang_old_style_highlight = 1
|
4437
|
25 "
|
4780
|
26 " To highlight further module attributes, add them to
|
|
27 " ~/.vim/after/syntax/erlang.vim:
|
4437
|
28 "
|
4780
|
29 " syn keyword erlangAttribute myattr1 myattr2 contained
|
4437
|
30
|
|
31 " For version 5.x: Clear all syntax items
|
|
32 " For version 6.x: Quit when a syntax file was already loaded
|
|
33 if version < 600
|
|
34 syntax clear
|
|
35 elseif exists("b:current_syntax")
|
|
36 finish
|
7
|
37 endif
|
|
38
|
5277
|
39 let s:cpo_save = &cpo
|
|
40 set cpo&vim
|
|
41
|
4437
|
42 " Case sensitive
|
3281
|
43 syn case match
|
|
44
|
4437
|
45 if version >= 600
|
|
46 setlocal iskeyword+=$,@-@
|
|
47 endif
|
3281
|
48
|
4437
|
49 " Comments
|
4780
|
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 '^#!.*'
|
4437
|
55
|
|
56 " Numbers (minimum base is 2, maximum is 36.)
|
4780
|
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\+\)\=\>'
|
7
|
60
|
4437
|
61 " Strings, atoms, characters
|
4780
|
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\+}\|\^.\|.\)\)'
|
|
67
|
|
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 '->'
|
7
|
74
|
4780
|
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
|
3281
|
82
|
4780
|
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:]_@]*'
|
7
|
88
|
4780
|
89 " Bitstrings
|
|
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
|
4437
|
91
|
|
92 " Constants and Directives
|
5277
|
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
|
7
|
100
|
4437
|
101 " Keywords
|
4780
|
102 syn keyword erlangKeyword after begin case catch cond end fun if let of query
|
|
103 syn keyword erlangKeyword receive when try
|
7
|
104
|
4780
|
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
|
4437
|
136
|
|
137 " Sync at the beginning of functions: if this is not used, multiline string
|
4780
|
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).
|
4437
|
141 syn sync match erlangSync grouphere NONE "^[a-z]\s*("
|
4780
|
142 let b:erlang_syntax_synced = 1
|
4437
|
143
|
4780
|
144 " Define the default highlighting. See ":help group-name" for the groups and
|
|
145 " their colors.
|
|
146
|
5277
|
147 let s:old_style = (exists("g:erlang_old_style_highlight") &&
|
|
148 \g:erlang_old_style_highlight == 1)
|
4780
|
149
|
4437
|
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
|
4780
|
152 if version >= 508 || !exists("did_erlang_inits")
|
4437
|
153 if version < 508
|
|
154 let did_erlang_inits = 1
|
|
155 command -nargs=+ HiLink hi link <args>
|
|
156 else
|
|
157 command -nargs=+ HiLink hi def link <args>
|
|
158 endif
|
7
|
159
|
4780
|
160 " Comments
|
4437
|
161 HiLink erlangComment Comment
|
|
162 HiLink erlangCommentAnnotation Special
|
|
163 HiLink erlangTodo Todo
|
4780
|
164 HiLink erlangShebang Comment
|
4437
|
165
|
4780
|
166 " Numbers
|
4437
|
167 HiLink erlangNumberInteger Number
|
|
168 HiLink erlangNumberFloat Float
|
4780
|
169
|
|
170 " Strings, atoms, characters
|
|
171 HiLink erlangString String
|
4437
|
172
|
4780
|
173 if s:old_style
|
|
174 HiLink erlangQuotedAtom Type
|
|
175 else
|
|
176 HiLink erlangQuotedAtom String
|
|
177 endif
|
|
178
|
|
179 HiLink erlangStringModifier Special
|
|
180 HiLink erlangQuotedAtomModifier Special
|
4437
|
181 HiLink erlangModifier Special
|
7
|
182
|
4780
|
183 " Operators, separators
|
|
184 HiLink erlangOperator Operator
|
|
185 HiLink erlangRightArrow Operator
|
|
186 if s:old_style
|
|
187 HiLink erlangBracket Normal
|
|
188 HiLink erlangPipe Normal
|
|
189 else
|
|
190 HiLink erlangBracket Delimiter
|
|
191 HiLink erlangPipe Delimiter
|
|
192 endif
|
|
193
|
|
194 " Atoms, functions, variables, macros
|
|
195 if s:old_style
|
|
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
|
|
204 else
|
|
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
|
|
213 endif
|
|
214
|
|
215 " Bitstrings
|
|
216 if !s:old_style
|
|
217 HiLink erlangBitType Type
|
|
218 endif
|
|
219
|
|
220 " Constants and Directives
|
|
221 if s:old_style
|
|
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
|
|
230 else
|
|
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
|
|
239 endif
|
|
240
|
|
241 " Keywords
|
|
242 HiLink erlangKeyword Keyword
|
|
243
|
|
244 " Build-in-functions (BIFs)
|
4437
|
245 HiLink erlangBIF Function
|
|
246
|
4780
|
247 if s:old_style
|
|
248 HiLink erlangBoolean Statement
|
|
249 HiLink erlangExtra Statement
|
|
250 HiLink erlangSignal Statement
|
|
251 else
|
|
252 HiLink erlangBoolean Boolean
|
|
253 HiLink erlangExtra Statement
|
|
254 HiLink erlangSignal Statement
|
|
255 endif
|
4437
|
256
|
|
257 delcommand HiLink
|
7
|
258 endif
|
4437
|
259
|
|
260 let b:current_syntax = "erlang"
|
|
261
|
5277
|
262 let &cpo = s:cpo_save
|
|
263 unlet s:cpo_save
|
|
264
|
4437
|
265 " vim: sw=2 et
|