7
|
1 " Vim syntax file
|
4437
|
2 " Language: Erlang (http://www.erlang.org)
|
|
3 " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
|
4780
|
4 " Last Update: 2013-Jun-01
|
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
|
4437
|
39 " Case sensitive
|
3281
|
40 syn case match
|
|
41
|
4437
|
42 if version >= 600
|
|
43 setlocal iskeyword+=$,@-@
|
|
44 endif
|
3281
|
45
|
4437
|
46 " Comments
|
4780
|
47 syn match erlangComment '%.*$' contains=erlangCommentAnnotation,erlangTodo
|
|
48 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
|
|
49 syn match erlangCommentAnnotation /`[^']*'/ contained
|
|
50 syn keyword erlangTodo TODO FIXME XXX contained
|
|
51 syn match erlangShebang '^#!.*'
|
4437
|
52
|
|
53 " Numbers (minimum base is 2, maximum is 36.)
|
4780
|
54 syn match erlangNumberInteger '\<\d\+\>'
|
|
55 syn match erlangNumberInteger '\<\%([2-9]\|[12]\d\|3[0-6]\)\+#[[:alnum:]]\+\>'
|
|
56 syn match erlangNumberFloat '\<\d\+\.\d\+\%([eE][+-]\=\d\+\)\=\>'
|
7
|
57
|
4437
|
58 " Strings, atoms, characters
|
4780
|
59 syn region erlangString start=/"/ end=/"/ contains=erlangStringModifier
|
|
60 syn region erlangQuotedAtom start=/'/ end=/'/ contains=erlangQuotedAtomModifier
|
|
61 syn match erlangStringModifier '\~\a\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
|
|
62 syn match erlangQuotedAtomModifier '\~\a\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
|
|
63 syn match erlangModifier '\$\%([^\\]\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\)'
|
|
64
|
|
65 " Operators, separators
|
|
66 syn match erlangOperator '==\|=:=\|/=\|=/=\|<\|=<\|>\|>=\|++\|--\|=\|!\|<-\|+\|-\|\*\|\/'
|
|
67 syn keyword erlangOperator div rem or xor bor bxor bsl bsr and band not bnot andalso orelse
|
|
68 syn match erlangBracket '{\|}\|\[\|]\||\|||'
|
|
69 syn match erlangPipe '|'
|
|
70 syn match erlangRightArrow '->'
|
7
|
71
|
4780
|
72 " Atoms, function calls (order is important)
|
|
73 syn match erlangAtom '\<\l[[:alnum:]_@]*' contains=erlangBoolean
|
|
74 syn keyword erlangBoolean true false contained
|
|
75 syn match erlangLocalFuncCall '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangBIF
|
|
76 syn match erlangLocalFuncRef '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@='
|
|
77 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
|
|
78 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
|
79
|
4780
|
80 " Variables, macros, records
|
|
81 syn match erlangVariable '\<[A-Z_][[:alnum:]_@]*'
|
|
82 syn match erlangMacro '??\=[[:alnum:]_@]\+'
|
|
83 syn match erlangMacro '\%(-define(\)\@<=[[:alnum:]_@]\+'
|
|
84 syn match erlangRecord '#\s*\l[[:alnum:]_@]*'
|
7
|
85
|
4780
|
86 " Bitstrings
|
|
87 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
|
88
|
|
89 " Constants and Directives
|
4780
|
90 syn match erlangUnknownAttribute '-\%(\s\|\n\|%.*\n\)*\l[[:alnum:]_@]*' contains=erlangComment
|
|
91 syn match erlangAttribute '-\%(\s\|\n\|%.*\n\)*\%(behaviou\=r\|compile\|export\|file\|import\|module\|author\|copyright\|doc\|vsn\|on_load\|export_type\)' contains=erlangComment
|
|
92 syn match erlangInclude '-\%(\s\|\n\|%.*\n\)*\%(include\|include_lib\)\>' contains=erlangComment
|
|
93 syn match erlangRecordDef '-\%(\s\|\n\|%.*\n\)*record\>' contains=erlangComment
|
|
94 syn match erlangDefine '-\%(\s\|\n\|%.*\n\)*\%(define\|undef\)\>' contains=erlangComment
|
|
95 syn match erlangPreCondit '-\%(\s\|\n\|%.*\n\)*\%(ifdef\|ifndef\|else\|endif\)\>' contains=erlangComment
|
|
96 syn match erlangType '-\%(\s\|\n\|%.*\n\)*\%(spec\|type\|opaque\|callback\)\>' contains=erlangComment
|
7
|
97
|
4437
|
98 " Keywords
|
4780
|
99 syn keyword erlangKeyword after begin case catch cond end fun if let of query
|
|
100 syn keyword erlangKeyword receive when try
|
7
|
101
|
4780
|
102 " Build-in-functions (BIFs)
|
|
103 syn keyword erlangBIF abs alive apply atom_to_binary atom_to_list contained
|
|
104 syn keyword erlangBIF binary_part binary_to_atom contained
|
|
105 syn keyword erlangBIF binary_to_existing_atom binary_to_float contained
|
|
106 syn keyword erlangBIF binary_to_integer bitstring_to_list contained
|
|
107 syn keyword erlangBIF binary_to_list binary_to_term bit_size contained
|
|
108 syn keyword erlangBIF byte_size check_old_code check_process_code contained
|
|
109 syn keyword erlangBIF concat_binary date delete_module demonitor contained
|
|
110 syn keyword erlangBIF disconnect_node element erase error exit contained
|
|
111 syn keyword erlangBIF float float_to_binary float_to_list contained
|
|
112 syn keyword erlangBIF garbage_collect get get_keys group_leader contained
|
|
113 syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained
|
|
114 syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained
|
|
115 syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained
|
|
116 syn keyword erlangBIF is_float is_function is_integer is_list contained
|
|
117 syn keyword erlangBIF is_number is_pid is_port is_process_alive contained
|
|
118 syn keyword erlangBIF is_record is_reference is_tuple length link contained
|
|
119 syn keyword erlangBIF list_to_atom list_to_binary contained
|
|
120 syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained
|
|
121 syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained
|
|
122 syn keyword erlangBIF list_to_tuple load_module make_ref max min contained
|
|
123 syn keyword erlangBIF module_loaded monitor monitor_node node contained
|
|
124 syn keyword erlangBIF nodes now open_port pid_to_list port_close contained
|
|
125 syn keyword erlangBIF port_command port_connect pre_loaded contained
|
|
126 syn keyword erlangBIF process_flag process_flag process_info contained
|
|
127 syn keyword erlangBIF process purge_module put register registered contained
|
|
128 syn keyword erlangBIF round self setelement size spawn spawn_link contained
|
|
129 syn keyword erlangBIF spawn_monitor spawn_opt split_binary contained
|
|
130 syn keyword erlangBIF statistics term_to_binary throw time tl contained
|
|
131 syn keyword erlangBIF trunc tuple_size tuple_to_list unlink contained
|
|
132 syn keyword erlangBIF unregister whereis contained
|
4437
|
133
|
|
134 " Sync at the beginning of functions: if this is not used, multiline string
|
4780
|
135 " are not always recognized, and the indentation script cannot use the
|
|
136 " "searchpair" (because it would not always skip strings and comments when
|
|
137 " looking for keywords and opening parens/brackets).
|
4437
|
138 syn sync match erlangSync grouphere NONE "^[a-z]\s*("
|
4780
|
139 let b:erlang_syntax_synced = 1
|
4437
|
140
|
4780
|
141 " Define the default highlighting. See ":help group-name" for the groups and
|
|
142 " their colors.
|
|
143
|
|
144 let s:old_style = (exists("g:erlang_old_style_highlight") && g:erlang_old_style_highlight == 1)
|
|
145
|
4437
|
146 " For version 5.7 and earlier: only when not done already
|
|
147 " For version 5.8 and later: only when an item doesn't have highlighting yet
|
4780
|
148 if version >= 508 || !exists("did_erlang_inits")
|
4437
|
149 if version < 508
|
|
150 let did_erlang_inits = 1
|
|
151 command -nargs=+ HiLink hi link <args>
|
|
152 else
|
|
153 command -nargs=+ HiLink hi def link <args>
|
|
154 endif
|
7
|
155
|
4780
|
156 " Comments
|
4437
|
157 HiLink erlangComment Comment
|
|
158 HiLink erlangCommentAnnotation Special
|
|
159 HiLink erlangTodo Todo
|
4780
|
160 HiLink erlangShebang Comment
|
4437
|
161
|
4780
|
162 " Numbers
|
4437
|
163 HiLink erlangNumberInteger Number
|
|
164 HiLink erlangNumberFloat Float
|
4780
|
165
|
|
166 " Strings, atoms, characters
|
|
167 HiLink erlangString String
|
4437
|
168
|
4780
|
169 if s:old_style
|
|
170 HiLink erlangQuotedAtom Type
|
|
171 else
|
|
172 HiLink erlangQuotedAtom String
|
|
173 endif
|
|
174
|
|
175 HiLink erlangStringModifier Special
|
|
176 HiLink erlangQuotedAtomModifier Special
|
4437
|
177 HiLink erlangModifier Special
|
7
|
178
|
4780
|
179 " Operators, separators
|
|
180 HiLink erlangOperator Operator
|
|
181 HiLink erlangRightArrow Operator
|
|
182 if s:old_style
|
|
183 HiLink erlangBracket Normal
|
|
184 HiLink erlangPipe Normal
|
|
185 else
|
|
186 HiLink erlangBracket Delimiter
|
|
187 HiLink erlangPipe Delimiter
|
|
188 endif
|
|
189
|
|
190 " Atoms, functions, variables, macros
|
|
191 if s:old_style
|
|
192 HiLink erlangAtom Normal
|
|
193 HiLink erlangLocalFuncCall Normal
|
|
194 HiLink erlangLocalFuncRef Normal
|
|
195 HiLink erlangGlobalFuncCall Function
|
|
196 HiLink erlangGlobalFuncRef Function
|
|
197 HiLink erlangVariable Normal
|
|
198 HiLink erlangMacro Normal
|
|
199 HiLink erlangRecord Normal
|
|
200 else
|
|
201 HiLink erlangAtom String
|
|
202 HiLink erlangLocalFuncCall Normal
|
|
203 HiLink erlangLocalFuncRef Normal
|
|
204 HiLink erlangGlobalFuncCall Normal
|
|
205 HiLink erlangGlobalFuncRef Normal
|
|
206 HiLink erlangVariable Identifier
|
|
207 HiLink erlangMacro Macro
|
|
208 HiLink erlangRecord Structure
|
|
209 endif
|
|
210
|
|
211 " Bitstrings
|
|
212 if !s:old_style
|
|
213 HiLink erlangBitType Type
|
|
214 endif
|
|
215
|
|
216 " Constants and Directives
|
|
217 if s:old_style
|
|
218 HiLink erlangAttribute Type
|
|
219 HiLink erlangMacroDef Type
|
|
220 HiLink erlangUnknownAttribute Normal
|
|
221 HiLink erlangInclude Type
|
|
222 HiLink erlangRecordDef Type
|
|
223 HiLink erlangDefine Type
|
|
224 HiLink erlangPreCondit Type
|
|
225 HiLink erlangType Type
|
|
226 else
|
|
227 HiLink erlangAttribute Keyword
|
|
228 HiLink erlangMacroDef Macro
|
|
229 HiLink erlangUnknownAttribute Normal
|
|
230 HiLink erlangInclude Include
|
|
231 HiLink erlangRecordDef Keyword
|
|
232 HiLink erlangDefine Define
|
|
233 HiLink erlangPreCondit PreCondit
|
|
234 HiLink erlangType Type
|
|
235 endif
|
|
236
|
|
237 " Keywords
|
|
238 HiLink erlangKeyword Keyword
|
|
239
|
|
240 " Build-in-functions (BIFs)
|
4437
|
241 HiLink erlangBIF Function
|
|
242
|
4780
|
243 if s:old_style
|
|
244 HiLink erlangBoolean Statement
|
|
245 HiLink erlangExtra Statement
|
|
246 HiLink erlangSignal Statement
|
|
247 else
|
|
248 HiLink erlangBoolean Boolean
|
|
249 HiLink erlangExtra Statement
|
|
250 HiLink erlangSignal Statement
|
|
251 endif
|
4437
|
252
|
|
253 delcommand HiLink
|
7
|
254 endif
|
4437
|
255
|
|
256 let b:current_syntax = "erlang"
|
|
257
|
|
258 " vim: sw=2 et
|