robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:c6705b2: runtime(erlang): Optimize operators and bitstring types (#40278)c10a827289

master
18.2 KiB438 linesraw
1" Vim syntax file
2" Language:     Erlang (http://www.erlang.org)
3" Maintainer:   Csaba Hoch <csaba.hoch@gmail.com>
4" Contributor:  Adam Rutkowski <hq@mtod.org>
5"               Johannes Christ <jc@jchri.st>
6" Last Update:  2026-Jun-14
7" License:      Vim license
8" URL:          https://github.com/vim-erlang/vim-erlang-runtime
9
10" Acknowledgements: This script was originally created by Kresimir Marzic [1].
11" The script was then revamped by Csaba Hoch [2]. During the revamp, the new
12" highlighting style and some code was taken from the Erlang syntax script
13" that is part of vimerl [3], created by Oscar Hellström [4] and improved by
14" Ricardo Catalinas Jiménez [5].
15
16" [1]: Kreąimir Marľić (Kresimir Marzic) <kmarzic@fly.srk.fer.hr>
17" [2]: Csaba Hoch <csaba.hoch@gmail.com>
18" [3]: https://github.com/jimenezrick/vimerl
19" [4]: Oscar Hellström <oscar@oscarh.net> (http://oscar.hellstrom.st)
20" [5]: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
21
22" Customization:
23"
24" To use the old highlighting style, add this to your .vimrc:
25"
26"     let g:erlang_old_style_highlight = 1
27
28" quit when a syntax file was already loaded
29if exists("b:current_syntax")
30    finish
31endif
32
33if !exists('g:main_syntax')
34  " This is an Erlang source file, and this is the main execution of
35  " syntax/erlang.vim.
36  let g:main_syntax = 'erlang'
37elseif g:main_syntax == 'erlang'
38  " This is an Erlang source file, and this is an inner execution of
39  " syntax/erlang.vim. For example:
40  "
41  " 1.  The main execution of syntax/erlang.vim included syntax/markdown.vim
42  "     because "g:erlang_use_markdown_for_docs == 1".
43  "
44  " 2.  syntax/markdown.vim included syntax/erlang.vim because
45  "     "g:markdown_fenced_languages == ['erlang']". This is the inner
46  "     execution of syntax/erlang.vim.
47  "
48  " To avoid infinite recursion with Markdown and Erlang including each other,
49  " and to avoid the inner syntax/erlang.vim execution messing up the
50  " variables of the outer erlang.vim execution, we finish executing the inner
51  " erlang.vim.
52  "
53  " In the inner execution, we already have the Erlang syntax items included,
54  " so the highlighting of Erlang within Markdown within Erlang will be
55  " acceptable. It won't highlight Markdown inside Erlang inside Markdown
56  " inside Erlang.
57  finish
58endif
59
60let s:cpo_save = &cpo
61set cpo&vim
62
63" "g:erlang_old_style_highlight": Whether to use old style highlighting.
64"
65" *   "g:erlang_old_style_highlight == 0" (default): Use new style
66"     highlighting.
67"
68" *   "g:erlang_old_style_highlight == 1": Use old style highlighting.
69let s:old_style = (exists("g:erlang_old_style_highlight") &&
70                  \g:erlang_old_style_highlight == 1)
71
72" "g:erlang_use_markdown_for_docs": Whether to use Markdown highlighting in
73" docstrings.
74"
75" *   "g:erlang_use_markdown_for_docs == 1": Enable Markdown highlighting in
76"     docstrings.
77"
78" *   "g:erlang_use_markdown_for_docs == 0" (default): Disable Markdown
79"     highlighting in docstrings.
80"
81" If "g:main_syntax" is not 'erlang', this is not an Erlang source file but
82" for example a Markdown file, and syntax/markdown.vim is including
83" syntax/erlang.vim. To avoid infinite recursion with Markdown and Erlang
84" including each other, we disable sourcing syntax/markdown.vim in this case.
85if exists("g:erlang_use_markdown_for_docs") && g:main_syntax == 'erlang'
86  let s:use_markdown = g:erlang_use_markdown_for_docs
87else
88  let s:use_markdown = 0
89endif
90
91" "g:erlang_docstring_default_highlight": How to highlight the text inside
92" docstrings (except the text which is highlighted by Markdown).
93"
94" If "g:erlang_use_markdown_for_docs == 1":
95"
96" *   "g:erlang_docstring_default_highlight == 'Comment'" (default): the plugin
97"     highlights the plain text inside Markdown as Markdown normally does,
98"     with comment highlighting to regular text in the docstring.
99"
100" *   If you set g:erlang_docstring_default_highlight to the name of highlight
101"     group, for example "String", the plugin highlights the plain text inside
102"     Markdown with the specified highlight group. See ":highlight" for the
103"     available groups. You may also set it to an empty string to disable any
104"     specific highlighting.
105"
106" If "g:erlang_use_markdown_for_docs == 0":
107"
108" *   "g:erlang_docstring_default_highlight == 'Comment'" (default): the plugin
109"     does not highlight the contents of the docstring as markdown, but
110"     continues to display them in the style of comments.
111"
112" *   If you set g:erlang_docstring_default_highlight to the name of highlight
113"     group, for example "String", the plugin highlights the plain text inside
114"     Markdown with the specified highlight group. See ":highlight" for the
115"     available groups. You may also set it to an empty string to disable any
116"     specific highlighting.
117"
118" Configuration examples:
119"
120"    " Highlight docstrings as Markdown.
121"    let g:erlang_use_markdown_for_docs = 1
122"    let g:erlang_docstring_default_highlight = 'Comment'
123"
124"    " 1. Highlight Markdown elements in docstrings as Markdown.
125"    " 2. Highlight the plain text in docstrings as String.
126"    let g:erlang_use_markdown_for_docs = 1
127"    let g:erlang_docstring_default_highlight = 'String'
128"
129"    " Highlight docstrings as strings.
130"    let g:erlang_use_markdown_for_docs = 0
131"    let g:erlang_docstring_default_highlight = 'String'
132"
133"    " Highlight docstrings as comments (default).
134"    let g:erlang_use_markdown_for_docs = 0
135"    let g:erlang_docstring_default_highlight = 'Comment'
136if exists("g:erlang_docstring_default_highlight")
137  let s:docstring_default_highlight = g:erlang_docstring_default_highlight
138else
139  let s:docstring_default_highlight = 'Comment'
140endif
141
142" Case sensitive
143syn case match
144
145setlocal iskeyword+=$,@-@
146
147" Comments
148syn match erlangComment           '%.*$' contains=erlangCommentAnnotation,erlangTodo
149syn match erlangCommentAnnotation ' \@<=@\%(clear\|docfile\|end\|headerfile\|todo\|TODO\|type\|author\|copyright\|doc\|reference\|see\|since\|title\|version\|deprecated\|hidden\|param\|private\|equiv\|spec\|throws\)' contained
150syn match erlangCommentAnnotation /`[^']*'/ contained
151syn keyword erlangTodo            TODO FIXME XXX contained
152
153" Numbers (minimum base is 2, maximum is 36.)
154syn match erlangNumberInteger '\<\d\+\>'
155syn match erlangNumberInteger '\<\%([2-9]\|[12]\d\|3[0-6]\)\+#[[:alnum:]]\+\>'
156syn match erlangNumberFloat   '\<\d\+\.\d\+\%([eE][+-]\=\d\+\)\=\>'
157
158" Strings, atoms, characters
159syn region erlangString            start=/"/ end=/"/ contains=erlangStringModifier
160syn region erlangStringTripleQuoted matchgroup=String start=/"""/ end=/\%(^\s*\)\@<="""/ keepend
161
162" Documentation
163syn region erlangDocString          start=/^-\%(module\)\=doc\s*\~\="/ end=/"\.$/                  contains=@erlangDocStringCluster keepend
164syn region erlangDocString          start=/^-\%(module\)\=doc\s*<<"/ end=/">>\.$/                  contains=@erlangDocStringCluster keepend
165syn region erlangDocString          start=/^-\%(module\)\=doc\s*\~\="""/ end=/\%(^\s*\)\@<="""\.$/ contains=@erlangDocStringCluster keepend
166syn region erlangDocString          start=/^-\%(module\)\=doc\s*<<"""/ end=/\%(^\s*\)\@<=""">>\.$/ contains=@erlangDocStringCluster keepend
167syn cluster erlangDocStringCluster contains=erlangInnerDocAttribute,erlangDocStringDelimiter
168syn region erlangDocStringDelimiter matchgroup=erlangString start=/"/ end=/"/ contains=@erlangDocStringContained contained
169syn region erlangDocStringDelimiter matchgroup=erlangString start=/"""/ end=/"""/ contains=@erlangDocStringContained contained
170
171if s:use_markdown
172  syn cluster erlangDocStringContained contains=@markdown
173endif
174
175syn region erlangQuotedAtom        start=/'/ end=/'/ contains=erlangQuotedAtomModifier
176syn match erlangStringModifier     '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\|\~\%([ni~]\|\%(-\=\d\+\|\*\)\=\.\=\%(\*\|\d\+\)\=\%(\..\)\=[tl]*[cfegswpWPBX#bx+]\)' contained
177syn match erlangQuotedAtomModifier '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained
178syn match erlangModifier           '\$\%([^\\]\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\)'
179
180" Operators, separators
181syn match erlangOperator '='
182syn match erlangOperator '+'
183syn match erlangOperator '-'
184syn match erlangOperator '*'
185syn match erlangOperator '/'
186syn match erlangOperator '<'
187syn match erlangOperator '>'
188syn match erlangOperator '!'
189syn match erlangOperator '=<'
190syn match erlangOperator '>='
191syn match erlangOperator '=>'
192syn match erlangOperator '=='
193syn match erlangOperator '=:='
194syn match erlangOperator '/='
195syn match erlangOperator '=/='
196syn match erlangOperator ':='
197syn match erlangOperator '?='
198syn match erlangOperator '++'
199syn match erlangOperator '--'
200syn match erlangOperator '<-'
201
202" erlangEqualsBinary makes the syntax reflect how Erlang parses the following:
203"
204" A=<<<"binary">>
205"   Valid, same as: A =< <<"binary">>
206" A==<<"binary">>
207"   Valid, same as: A == <<"binary">>
208" A=<<"binary">>
209"   Invalid, parsed as: A =< <"binary">>. This is invalid because there are no
210"   "<<" before the binary, only "<".
211syn match erlangEqualsBinary '=<<\%(<\)\@!'
212
213syn keyword erlangOperator div rem or xor bor bxor bsl bsr and band not bnot andalso orelse
214syn match erlangBracket    '{\|}\|\[\|]\||\|||'
215syn match erlangPipe       '|'
216syn match erlangRightArrow '->'
217
218" Atoms, function calls (order is important)
219syn match erlangAtom           '\<\l[[:alnum:]_@]*' contains=erlangBoolean
220syn keyword erlangBoolean      true false contained
221syn match erlangLocalFuncCall  '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangBIF
222syn match erlangLocalFuncRef   '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@='
223syn 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
224syn 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
225
226" Variables, macros, records, maps
227syn match erlangVariable '\<[A-Z][[:alnum:]_@]*'
228syn match erlangAnonymousVariable '\<_[[:alnum:]_@]*'
229syn match erlangMacro    '??\=[[:alnum:]_@]\+'
230syn match erlangMacro    '\%(-define(\)\@<=[[:alnum:]_@]\+'
231syn region erlangQuotedMacro         start=/??\=\s*'/ end=/'/ contains=erlangQuotedAtomModifier
232syn match erlangMap      '#'
233syn match erlangRecord   '#\s*\l[[:alnum:]_@]*'
234syn region erlangQuotedRecord        start=/#\s*'/ end=/'/ contains=erlangQuotedAtomModifier
235
236" Shebang (this line has to be after the ErlangMap)
237syn match erlangShebang  '^#!.*'
238
239" Bitstrings
240syn match erlangBitType '\%#=1\%(\/\%(\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
241
242" Constants and Directives
243syn match erlangUnknownAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\l[[:alnum:]_@]*' contains=erlangComment
244syn match erlangAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(behaviou\=r\|compile\|dialyzer\|export\|export_type\|file\|import\|module\|author\|copyright\|vsn\|on_load\|optional_callbacks\|feature\|mode\)\>' contains=erlangComment
245syn match erlangDocAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(moduledoc\|doc\)\>' contains=erlangComment,erlangDocString
246syn match erlangInnerDocAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(moduledoc\|doc\)\>' contained
247syn match erlangInclude   '^\s*-\%(\s\|\n\|%.*\n\)*\%(include\|include_lib\)\>' contains=erlangComment
248syn match erlangRecordDef '^\s*-\%(\s\|\n\|%.*\n\)*record\>' contains=erlangComment
249syn match erlangDefine    '^\s*-\%(\s\|\n\|%.*\n\)*\%(define\|undef\)\>' contains=erlangComment
250syn match erlangPreCondit '^\s*-\%(\s\|\n\|%.*\n\)*\%(ifdef\|ifndef\|else\|if\|elif\|endif\)\>' contains=erlangComment
251syn match erlangType      '^\s*-\%(\s\|\n\|%.*\n\)*\%(spec\|type\|opaque\|nominal\|callback\)\>' contains=erlangComment
252
253" Keywords
254syn keyword erlangKeyword after begin case catch cond end fun if let of else
255syn keyword erlangKeyword receive when try maybe
256
257" Build-in-functions (BIFs)
258syn keyword erlangBIF abs alive apply atom_to_binary atom_to_list contained
259syn keyword erlangBIF binary_part binary_to_atom contained
260syn keyword erlangBIF binary_to_existing_atom binary_to_float contained
261syn keyword erlangBIF binary_to_integer bitstring_to_list contained
262syn keyword erlangBIF binary_to_list binary_to_term bit_size contained
263syn keyword erlangBIF byte_size check_old_code check_process_code contained
264syn keyword erlangBIF concat_binary date delete_module demonitor contained
265syn keyword erlangBIF disconnect_node element erase error exit contained
266syn keyword erlangBIF float float_to_binary float_to_list contained
267syn keyword erlangBIF garbage_collect get get_keys group_leader contained
268syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained
269syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained
270syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained
271syn keyword erlangBIF is_float is_function is_integer is_list is_map is_map_key contained
272syn keyword erlangBIF is_number is_pid is_port is_process_alive contained
273syn keyword erlangBIF is_record is_reference is_tuple length link contained
274syn keyword erlangBIF list_to_atom list_to_binary contained
275syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained
276syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained
277syn keyword erlangBIF list_to_tuple load_module make_ref map_size max contained
278syn keyword erlangBIF min module_loaded monitor monitor_node node contained
279syn keyword erlangBIF nodes now open_port pid_to_list port_close contained
280syn keyword erlangBIF port_command port_connect pre_loaded contained
281syn keyword erlangBIF process_flag process_flag process_info contained
282syn keyword erlangBIF process purge_module put register registered contained
283syn keyword erlangBIF round self setelement size spawn spawn_link contained
284syn keyword erlangBIF spawn_monitor spawn_opt split_binary contained
285syn keyword erlangBIF statistics term_to_binary throw time tl contained
286syn keyword erlangBIF trunc tuple_size tuple_to_list unlink contained
287syn keyword erlangBIF unregister whereis contained
288
289" Sync at the beginning of functions: if this is not used, multiline string
290" are not always recognized, and the indentation script cannot use the
291" "searchpair" (because it would not always skip strings and comments when
292" looking for keywords and opening parens/brackets).
293syn sync match erlangSync grouphere NONE "^[a-z]\s*("
294let b:erlang_syntax_synced = 1
295
296" Define the default highlighting. See ":help group-name" for the groups and
297" their colors.
298
299if s:use_markdown
300  " Add markdown syntax elements for docstrings (actually, for all
301  " triple-quoted strings).
302  unlet! b:current_syntax
303
304  syn include @markdown syntax/markdown.vim
305  let b:current_syntax = "erlang"
306
307  " markdown-erlang.vim includes html.vim, which includes css.vim, which adds
308  " the dash character (-) to the list of syntax keywords, which causes
309  " `-VarName` not to be highlighted as a variable in the Erlang code.
310  "
311  " Here we override that.
312  syntax iskeyword @,48-57,192-255,$,_
313endif
314
315" Comments
316hi def link erlangComment Comment
317hi def link erlangCommentAnnotation Special
318hi def link erlangTodo Todo
319hi def link erlangShebang Comment
320
321" Numbers
322hi def link erlangNumberInteger Number
323hi def link erlangNumberFloat Float
324
325" Strings, atoms, characters
326hi def link erlangString String
327hi def link erlangStringTripleQuoted String
328
329" Triple quoted strings
330if s:docstring_default_highlight != ''
331  execute 'hi def link erlangDocStringDelimiter '. s:docstring_default_highlight
332endif
333
334if s:old_style
335hi def link erlangQuotedAtom Type
336else
337hi def link erlangQuotedAtom String
338endif
339
340hi def link erlangStringModifier Special
341hi def link erlangQuotedAtomModifier Special
342hi def link erlangModifier Special
343
344" Operators, separators
345hi def link erlangOperator Operator
346hi def link erlangEqualsBinary ErrorMsg
347hi def link erlangRightArrow Operator
348if s:old_style
349hi def link erlangBracket Normal
350hi def link erlangPipe Normal
351else
352hi def link erlangBracket Delimiter
353hi def link erlangPipe Delimiter
354endif
355
356" Atoms, functions, variables, macros
357if s:old_style
358hi def link erlangAtom Normal
359hi def link erlangLocalFuncCall Normal
360hi def link erlangLocalFuncRef Normal
361hi def link erlangGlobalFuncCall Function
362hi def link erlangGlobalFuncRef Function
363hi def link erlangVariable Normal
364hi def link erlangAnonymousVariable erlangVariable
365hi def link erlangMacro Normal
366hi def link erlangQuotedMacro Normal
367hi def link erlangRecord Normal
368hi def link erlangQuotedRecord Normal
369hi def link erlangMap Normal
370else
371hi def link erlangAtom String
372hi def link erlangLocalFuncCall Normal
373hi def link erlangLocalFuncRef Normal
374hi def link erlangGlobalFuncCall Normal
375hi def link erlangGlobalFuncRef Normal
376hi def link erlangVariable Identifier
377hi def link erlangAnonymousVariable erlangVariable
378hi def link erlangMacro Macro
379hi def link erlangQuotedMacro Macro
380hi def link erlangRecord Structure
381hi def link erlangQuotedRecord Structure
382hi def link erlangMap Structure
383endif
384
385" Bitstrings
386if !s:old_style
387hi def link erlangBitType Type
388endif
389
390" Constants and Directives
391if s:old_style
392hi def link erlangAttribute Type
393hi def link erlangMacroDef Type
394hi def link erlangUnknownAttribute Normal
395hi def link erlangInclude Type
396hi def link erlangRecordDef Type
397hi def link erlangDefine Type
398hi def link erlangPreCondit Type
399hi def link erlangType Type
400else
401hi def link erlangAttribute Keyword
402hi def link erlangDocAttribute Keyword
403hi def link erlangInnerDocAttribute Keyword
404hi def link erlangMacroDef Macro
405hi def link erlangUnknownAttribute Normal
406hi def link erlangInclude Include
407hi def link erlangRecordDef Keyword
408hi def link erlangDefine Define
409hi def link erlangPreCondit PreCondit
410hi def link erlangType Type
411endif
412
413" Keywords
414hi def link erlangKeyword Keyword
415
416" Build-in-functions (BIFs)
417hi def link erlangBIF Function
418
419if s:old_style
420hi def link erlangBoolean Statement
421hi def link erlangExtra Statement
422hi def link erlangSignal Statement
423else
424hi def link erlangBoolean Boolean
425hi def link erlangExtra Statement
426hi def link erlangSignal Statement
427endif
428
429let b:current_syntax = "erlang"
430
431if g:main_syntax ==# 'erlang'
432  unlet g:main_syntax
433endif
434
435let &cpo = s:cpo_save
436unlet s:cpo_save
437
438" vim: sw=2 et