xref: /vim-8.2.3635/runtime/syntax/erlang.vim (revision 577fadfc)
1" Vim syntax file
2" Language:     Erlang (http://www.erlang.org)
3" Maintainer:   Csaba Hoch <[email protected]>
4" Contributor:  Adam Rutkowski <[email protected]>
5" Last Update:  2017-Mar-05
6" License:      Vim license
7" URL:          https://github.com/vim-erlang/vim-erlang-runtime
8
9" Acknowledgements: This script was originally created by Kresimir Marzic [1].
10" The script was then revamped by Csaba Hoch [2]. During the revamp, the new
11" highlighting style and some code was taken from the Erlang syntax script
12" that is part of vimerl [3], created by Oscar Hellström [4] and improved by
13" Ricardo Catalinas Jiménez [5].
14
15" [1]: Kreąimir Marľić (Kresimir Marzic) <[email protected]>
16" [2]: Csaba Hoch <[email protected]>
17" [3]: https://github.com/jimenezrick/vimerl
18" [4]: Oscar Hellström <[email protected]> (http://oscar.hellstrom.st)
19" [5]: Ricardo Catalinas Jiménez <[email protected]>
20
21" Customization:
22"
23" To use the old highlighting style, add this to your .vimrc:
24"
25"     let g:erlang_old_style_highlight = 1
26"
27" To highlight further module attributes, add them to
28" ~/.vim/after/syntax/erlang.vim:
29"
30"     syn keyword erlangAttribute myattr1 myattr2 contained
31
32" quit when a syntax file was already loaded
33if exists("b:current_syntax")
34    finish
35endif
36
37let s:cpo_save = &cpo
38set cpo&vim
39
40" Case sensitive
41syn case match
42
43setlocal iskeyword+=$,@-@
44
45" Comments
46syn match erlangComment           '%.*$' contains=erlangCommentAnnotation,erlangTodo
47syn match erlangCommentAnnotation ' \@<=@\%(clear\|docfile\|end\|headerfile\|todo\|TODO\|type\|author\|copyright\|doc\|reference\|see\|since\|title\|version\|deprecated\|hidden\|private\|equiv\|spec\|throws\)' contained
48syn match erlangCommentAnnotation /`[^']*'/ contained
49syn keyword erlangTodo            TODO FIXME XXX contained
50
51" Numbers (minimum base is 2, maximum is 36.)
52syn match erlangNumberInteger '\<\d\+\>'
53syn match erlangNumberInteger '\<\%([2-9]\|[12]\d\|3[0-6]\)\+#[[:alnum:]]\+\>'
54syn match erlangNumberFloat   '\<\d\+\.\d\+\%([eE][+-]\=\d\+\)\=\>'
55
56" Strings, atoms, characters
57syn region erlangString            start=/"/ end=/"/ contains=erlangStringModifier
58syn region erlangQuotedAtom        start=/'/ end=/'/ contains=erlangQuotedAtomModifier
59syn match erlangStringModifier     '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\|\~\%([ni~]\|\%(-\=\d\+\|\*\)\=\.\=\%(\*\|\d\+\)\=\%(\..\)\=[tl]*[cfegswpWPBX#bx+]\)' contained
60syn match erlangQuotedAtomModifier '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
61syn match erlangModifier           '\$\%([^\\]\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\)'
62
63" Operators, separators
64syn match erlangOperator   '==\|=:=\|/=\|=/=\|<\|=<\|>\|>=\|=>\|:=\|++\|--\|=\|!\|<-\|+\|-\|\*\|\/'
65syn keyword erlangOperator div rem or xor bor bxor bsl bsr and band not bnot andalso orelse
66syn match erlangBracket    '{\|}\|\[\|]\||\|||'
67syn match erlangPipe       '|'
68syn match erlangRightArrow '->'
69
70" Atoms, function calls (order is important)
71syn match erlangAtom           '\<\l[[:alnum:]_@]*' contains=erlangBoolean
72syn keyword erlangBoolean      true false contained
73syn match erlangLocalFuncCall  '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangBIF
74syn match erlangLocalFuncRef   '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@='
75syn 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,erlangVariable
76syn 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,erlangVariable
77
78" Variables, macros, records, maps
79syn match erlangVariable '\<[A-Z_][[:alnum:]_@]*'
80syn match erlangMacro    '??\=[[:alnum:]_@]\+'
81syn match erlangMacro    '\%(-define(\)\@<=[[:alnum:]_@]\+'
82syn match erlangMap      '#'
83syn match erlangRecord   '#\s*\l[[:alnum:]_@]*'
84syn region erlangQuotedRecord        start=/#\s*'/ end=/'/ contains=erlangQuotedAtomModifier
85
86" Shebang (this line has to be after the ErlangMap)
87syn match erlangShebang  '^#!.*'
88
89" Bitstrings
90syn 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
91
92" Constants and Directives
93syn match erlangUnknownAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\l[[:alnum:]_@]*' contains=erlangComment
94syn match erlangAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(behaviou\=r\|compile\|export\(_type\)\=\|file\|import\|module\|author\|copyright\|doc\|vsn\|on_load\)\>' contains=erlangComment
95syn match erlangInclude   '^\s*-\%(\s\|\n\|%.*\n\)*\%(include\|include_lib\)\>' contains=erlangComment
96syn match erlangRecordDef '^\s*-\%(\s\|\n\|%.*\n\)*record\>' contains=erlangComment
97syn match erlangDefine    '^\s*-\%(\s\|\n\|%.*\n\)*\%(define\|undef\)\>' contains=erlangComment
98syn match erlangPreCondit '^\s*-\%(\s\|\n\|%.*\n\)*\%(ifdef\|ifndef\|else\|endif\)\>' contains=erlangComment
99syn match erlangType      '^\s*-\%(\s\|\n\|%.*\n\)*\%(spec\|type\|opaque\|callback\)\>' contains=erlangComment
100
101" Keywords
102syn keyword erlangKeyword after begin case catch cond end fun if let of
103syn keyword erlangKeyword receive when try
104
105" Build-in-functions (BIFs)
106syn keyword erlangBIF abs alive apply atom_to_binary atom_to_list contained
107syn keyword erlangBIF binary_part binary_to_atom contained
108syn keyword erlangBIF binary_to_existing_atom binary_to_float contained
109syn keyword erlangBIF binary_to_integer bitstring_to_list contained
110syn keyword erlangBIF binary_to_list binary_to_term bit_size contained
111syn keyword erlangBIF byte_size check_old_code check_process_code contained
112syn keyword erlangBIF concat_binary date delete_module demonitor contained
113syn keyword erlangBIF disconnect_node element erase error exit contained
114syn keyword erlangBIF float float_to_binary float_to_list contained
115syn keyword erlangBIF garbage_collect get get_keys group_leader contained
116syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained
117syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained
118syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained
119syn keyword erlangBIF is_float is_function is_integer is_list contained
120syn keyword erlangBIF is_number is_pid is_port is_process_alive contained
121syn keyword erlangBIF is_record is_reference is_tuple length link contained
122syn keyword erlangBIF list_to_atom list_to_binary contained
123syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained
124syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained
125syn keyword erlangBIF list_to_tuple load_module make_ref max min contained
126syn keyword erlangBIF module_loaded monitor monitor_node node contained
127syn keyword erlangBIF nodes now open_port pid_to_list port_close contained
128syn keyword erlangBIF port_command port_connect pre_loaded contained
129syn keyword erlangBIF process_flag process_flag process_info contained
130syn keyword erlangBIF process purge_module put register registered contained
131syn keyword erlangBIF round self setelement size spawn spawn_link contained
132syn keyword erlangBIF spawn_monitor spawn_opt split_binary contained
133syn keyword erlangBIF statistics term_to_binary throw time tl contained
134syn keyword erlangBIF trunc tuple_size tuple_to_list unlink contained
135syn keyword erlangBIF unregister whereis contained
136
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).
141syn sync match erlangSync grouphere NONE "^[a-z]\s*("
142let b:erlang_syntax_synced = 1
143
144" Define the default highlighting. See ":help group-name" for the groups and
145" their colors.
146
147let s:old_style = (exists("g:erlang_old_style_highlight") &&
148                  \g:erlang_old_style_highlight == 1)
149
150
151" Comments
152hi def link erlangComment Comment
153hi def link erlangCommentAnnotation Special
154hi def link erlangTodo Todo
155hi def link erlangShebang Comment
156
157" Numbers
158hi def link erlangNumberInteger Number
159hi def link erlangNumberFloat Float
160
161" Strings, atoms, characters
162hi def link erlangString String
163
164if s:old_style
165hi def link erlangQuotedAtom Type
166else
167hi def link erlangQuotedAtom String
168endif
169
170hi def link erlangStringModifier Special
171hi def link erlangQuotedAtomModifier Special
172hi def link erlangModifier Special
173
174" Operators, separators
175hi def link erlangOperator Operator
176hi def link erlangRightArrow Operator
177if s:old_style
178hi def link erlangBracket Normal
179hi def link erlangPipe Normal
180else
181hi def link erlangBracket Delimiter
182hi def link erlangPipe Delimiter
183endif
184
185" Atoms, functions, variables, macros
186if s:old_style
187hi def link erlangAtom Normal
188hi def link erlangLocalFuncCall Normal
189hi def link erlangLocalFuncRef Normal
190hi def link erlangGlobalFuncCall Function
191hi def link erlangGlobalFuncRef Function
192hi def link erlangVariable Normal
193hi def link erlangMacro Normal
194hi def link erlangRecord Normal
195hi def link erlangQuotedRecord Normal
196hi def link erlangMap Normal
197else
198hi def link erlangAtom String
199hi def link erlangLocalFuncCall Normal
200hi def link erlangLocalFuncRef Normal
201hi def link erlangGlobalFuncCall Normal
202hi def link erlangGlobalFuncRef Normal
203hi def link erlangVariable Identifier
204hi def link erlangMacro Macro
205hi def link erlangRecord Structure
206hi def link erlangQuotedRecord Structure
207hi def link erlangMap Structure
208endif
209
210" Bitstrings
211if !s:old_style
212hi def link erlangBitType Type
213endif
214
215" Constants and Directives
216if s:old_style
217hi def link erlangAttribute Type
218hi def link erlangMacroDef Type
219hi def link erlangUnknownAttribute Normal
220hi def link erlangInclude Type
221hi def link erlangRecordDef Type
222hi def link erlangDefine Type
223hi def link erlangPreCondit Type
224hi def link erlangType Type
225else
226hi def link erlangAttribute Keyword
227hi def link erlangMacroDef Macro
228hi def link erlangUnknownAttribute Normal
229hi def link erlangInclude Include
230hi def link erlangRecordDef Keyword
231hi def link erlangDefine Define
232hi def link erlangPreCondit PreCondit
233hi def link erlangType Type
234endif
235
236" Keywords
237hi def link erlangKeyword Keyword
238
239" Build-in-functions (BIFs)
240hi def link erlangBIF Function
241
242if s:old_style
243hi def link erlangBoolean Statement
244hi def link erlangExtra Statement
245hi def link erlangSignal Statement
246else
247hi def link erlangBoolean Boolean
248hi def link erlangExtra Statement
249hi def link erlangSignal Statement
250endif
251
252
253let b:current_syntax = "erlang"
254
255let &cpo = s:cpo_save
256unlet s:cpo_save
257
258" vim: sw=2 et
259