codekingpro/portable-devtools
114k
1" Vim syntax file2" 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: 2025-Nov-127" License: Vim license8" URL: https://github.com/vim-erlang/vim-erlang-runtime9 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 new12" highlighting style and some code was taken from the Erlang syntax script13" that is part of vimerl [3], created by Oscar Hellström [4] and improved by14" 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/vimerl19" [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 = 127 28" quit when a syntax file was already loaded29if exists("b:current_syntax")30 finish31endif32 33if !exists('g:main_syntax')34 " This is an Erlang source file, and this is the main execution of35 " 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 of39 " syntax/erlang.vim. For example:40 "41 " 1. The main execution of syntax/erlang.vim included syntax/markdown.vim42 " because "g:erlang_use_markdown_for_docs == 1".43 "44 " 2. syntax/markdown.vim included syntax/erlang.vim because45 " "g:markdown_fenced_languages == ['erlang']". This is the inner46 " 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 the50 " variables of the outer erlang.vim execution, we finish executing the inner51 " 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 be55 " acceptable. It won't highlight Markdown inside Erlang inside Markdown56 " inside Erlang.57 finish58endif59 60let s:cpo_save = &cpo61set cpo&vim62 63" "g:erlang_old_style_highlight": Whether to use old style highlighting.64"65" * "g:erlang_old_style_highlight == 0" (default): Use new style66" 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 in73" docstrings.74"75" * "g:erlang_use_markdown_for_docs == 1": Enable Markdown highlighting in76" docstrings.77"78" * "g:erlang_use_markdown_for_docs == 0" (default): Disable Markdown79" highlighting in docstrings.80"81" If "g:main_syntax" is not 'erlang', this is not an Erlang source file but82" for example a Markdown file, and syntax/markdown.vim is including83" syntax/erlang.vim. To avoid infinite recursion with Markdown and Erlang84" 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_docs87else88 let s:use_markdown = 089endif90 91" "g:erlang_docstring_default_highlight": How to highlight the text inside92" 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 plugin97" 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 highlight101" group, for example "String", the plugin highlights the plain text inside102" Markdown with the specified highlight group. See ":highlight" for the103" available groups. You may also set it to an empty string to disable any104" specific highlighting.105"106" If "g:erlang_use_markdown_for_docs == 0":107"108" * "g:erlang_docstring_default_highlight == 'Comment'" (default): the plugin109" does not highlight the contents of the docstring as markdown, but110" continues to display them in the style of comments.111"112" * If you set g:erlang_docstring_default_highlight to the name of highlight113" group, for example "String", the plugin highlights the plain text inside114" Markdown with the specified highlight group. See ":highlight" for the115" available groups. You may also set it to an empty string to disable any116" specific highlighting.117"118" Configuration examples:119"120" " Highlight docstrings as Markdown.121" let g:erlang_use_markdown_for_docs = 1122" 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 = 1127" let g:erlang_docstring_default_highlight = 'String'128"129" " Highlight docstrings as strings.130" let g:erlang_use_markdown_for_docs = 0131" let g:erlang_docstring_default_highlight = 'String'132"133" " Highlight docstrings as comments (default).134" let g:erlang_use_markdown_for_docs = 0135" let g:erlang_docstring_default_highlight = 'Comment'136if exists("g:erlang_docstring_default_highlight")137 let s:docstring_default_highlight = g:erlang_docstring_default_highlight138else139 let s:docstring_default_highlight = 'Comment'140endif141 142" Case sensitive143syn case match144 145setlocal iskeyword+=$,@-@146 147" Comments148syn match erlangComment '%.*$' contains=erlangCommentAnnotation,erlangTodo149syn match erlangCommentAnnotation ' \@<=@\%(clear\|docfile\|end\|headerfile\|todo\|TODO\|type\|author\|copyright\|doc\|reference\|see\|since\|title\|version\|deprecated\|hidden\|param\|private\|equiv\|spec\|throws\)' contained150syn match erlangCommentAnnotation /`[^']*'/ contained151syn keyword erlangTodo TODO FIXME XXX contained152 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, characters159syn region erlangString start=/"/ end=/"/ contains=erlangStringModifier160syn region erlangStringTripleQuoted matchgroup=String start=/"""/ end=/\%(^\s*\)\@<="""/ keepend161 162" Documentation163syn region erlangDocString start=/^-\%(module\)\=doc\s*\~\="/ end=/"\.$/ contains=@erlangDocStringCluster keepend164syn region erlangDocString start=/^-\%(module\)\=doc\s*<<"/ end=/">>\.$/ contains=@erlangDocStringCluster keepend165syn region erlangDocString start=/^-\%(module\)\=doc\s*\~\="""/ end=/\%(^\s*\)\@<="""\.$/ contains=@erlangDocStringCluster keepend166syn region erlangDocString start=/^-\%(module\)\=doc\s*<<"""/ end=/\%(^\s*\)\@<=""">>\.$/ contains=@erlangDocStringCluster keepend167syn cluster erlangDocStringCluster contains=erlangInnerDocAttribute,erlangDocStringDelimiter168syn region erlangDocStringDelimiter matchgroup=erlangString start=/"/ end=/"/ contains=@erlangDocStringContained contained169syn region erlangDocStringDelimiter matchgroup=erlangString start=/"""/ end=/"""/ contains=@erlangDocStringContained contained170 171if s:use_markdown172 syn cluster erlangDocStringContained contains=@markdown173endif174 175syn region erlangQuotedAtom start=/'/ end=/'/ contains=erlangQuotedAtomModifier176syn match erlangStringModifier '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\|\~\%([ni~]\|\%(-\=\d\+\|\*\)\=\.\=\%(\*\|\d\+\)\=\%(\..\)\=[tl]*[cfegswpWPBX#bx+]\)' contained177syn match erlangQuotedAtomModifier '\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)' contained178syn match erlangModifier '\$\%([^\\]\|\\\%(\o\{1,3}\|x\x\x\|x{\x\+}\|\^.\|.\)\)'179 180" Operators, separators181syn match erlangOperator '==\|=:=\|/=\|=/=\|<\|=<\|>\|>=\|=>\|:=\|?=\|++\|--\|=\|!\|<-\|+\|-\|\*\|\/'182syn match erlangEqualsBinary '=<<\%(<\)\@!'183syn keyword erlangOperator div rem or xor bor bxor bsl bsr and band not bnot andalso orelse184syn match erlangBracket '{\|}\|\[\|]\||\|||'185syn match erlangPipe '|'186syn match erlangRightArrow '->'187 188" Atoms, function calls (order is important)189syn match erlangAtom '\<\l[[:alnum:]_@]*' contains=erlangBoolean190syn keyword erlangBoolean true false contained191syn match erlangLocalFuncCall '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*(\)\@=' contains=erlangBIF192syn match erlangLocalFuncRef '\<\a[[:alnum:]_@]*\>\%(\%(\s\|\n\|%.*\n\)*/\)\@='193syn 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,erlangVariable194syn 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,erlangVariable195 196" Variables, macros, records, maps197syn match erlangVariable '\<[A-Z][[:alnum:]_@]*'198syn match erlangAnonymousVariable '\<_[[:alnum:]_@]*'199syn match erlangMacro '??\=[[:alnum:]_@]\+'200syn match erlangMacro '\%(-define(\)\@<=[[:alnum:]_@]\+'201syn region erlangQuotedMacro start=/??\=\s*'/ end=/'/ contains=erlangQuotedAtomModifier202syn match erlangMap '#'203syn match erlangRecord '#\s*\l[[:alnum:]_@]*'204syn region erlangQuotedRecord start=/#\s*'/ end=/'/ contains=erlangQuotedAtomModifier205 206" Shebang (this line has to be after the ErlangMap)207syn match erlangShebang '^#!.*'208 209" Bitstrings210syn 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=erlangComment211 212" Constants and Directives213syn match erlangUnknownAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\l[[:alnum:]_@]*' contains=erlangComment214syn 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=erlangComment215syn match erlangDocAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(moduledoc\|doc\)\>' contains=erlangComment,erlangDocString216syn match erlangInnerDocAttribute '^\s*-\%(\s\|\n\|%.*\n\)*\%(moduledoc\|doc\)\>' contained217syn match erlangInclude '^\s*-\%(\s\|\n\|%.*\n\)*\%(include\|include_lib\)\>' contains=erlangComment218syn match erlangRecordDef '^\s*-\%(\s\|\n\|%.*\n\)*record\>' contains=erlangComment219syn match erlangDefine '^\s*-\%(\s\|\n\|%.*\n\)*\%(define\|undef\)\>' contains=erlangComment220syn match erlangPreCondit '^\s*-\%(\s\|\n\|%.*\n\)*\%(ifdef\|ifndef\|else\|if\|elif\|endif\)\>' contains=erlangComment221syn match erlangType '^\s*-\%(\s\|\n\|%.*\n\)*\%(spec\|type\|opaque\|nominal\|callback\)\>' contains=erlangComment222 223" Keywords224syn keyword erlangKeyword after begin case catch cond end fun if let of else225syn keyword erlangKeyword receive when try maybe226 227" Build-in-functions (BIFs)228syn keyword erlangBIF abs alive apply atom_to_binary atom_to_list contained229syn keyword erlangBIF binary_part binary_to_atom contained230syn keyword erlangBIF binary_to_existing_atom binary_to_float contained231syn keyword erlangBIF binary_to_integer bitstring_to_list contained232syn keyword erlangBIF binary_to_list binary_to_term bit_size contained233syn keyword erlangBIF byte_size check_old_code check_process_code contained234syn keyword erlangBIF concat_binary date delete_module demonitor contained235syn keyword erlangBIF disconnect_node element erase error exit contained236syn keyword erlangBIF float float_to_binary float_to_list contained237syn keyword erlangBIF garbage_collect get get_keys group_leader contained238syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained239syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained240syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained241syn keyword erlangBIF is_float is_function is_integer is_list is_map is_map_key contained242syn keyword erlangBIF is_number is_pid is_port is_process_alive contained243syn keyword erlangBIF is_record is_reference is_tuple length link contained244syn keyword erlangBIF list_to_atom list_to_binary contained245syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained246syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained247syn keyword erlangBIF list_to_tuple load_module make_ref map_size max contained248syn keyword erlangBIF min module_loaded monitor monitor_node node contained249syn keyword erlangBIF nodes now open_port pid_to_list port_close contained250syn keyword erlangBIF port_command port_connect pre_loaded contained251syn keyword erlangBIF process_flag process_flag process_info contained252syn keyword erlangBIF process purge_module put register registered contained253syn keyword erlangBIF round self setelement size spawn spawn_link contained254syn keyword erlangBIF spawn_monitor spawn_opt split_binary contained255syn keyword erlangBIF statistics term_to_binary throw time tl contained256syn keyword erlangBIF trunc tuple_size tuple_to_list unlink contained257syn keyword erlangBIF unregister whereis contained258 259" Sync at the beginning of functions: if this is not used, multiline string260" are not always recognized, and the indentation script cannot use the261" "searchpair" (because it would not always skip strings and comments when262" looking for keywords and opening parens/brackets).263syn sync match erlangSync grouphere NONE "^[a-z]\s*("264let b:erlang_syntax_synced = 1265 266" Define the default highlighting. See ":help group-name" for the groups and267" their colors.268 269if s:use_markdown270 " Add markdown syntax elements for docstrings (actually, for all271 " triple-quoted strings).272 unlet! b:current_syntax273 274 syn include @markdown syntax/markdown.vim275 let b:current_syntax = "erlang"276 277 " markdown-erlang.vim includes html.vim, which includes css.vim, which adds278 " the dash character (-) to the list of syntax keywords, which causes279 " `-VarName` not to be highlighted as a variable in the Erlang code.280 "281 " Here we override that.282 syntax iskeyword @,48-57,192-255,$,_283endif284 285" Comments286hi def link erlangComment Comment287hi def link erlangCommentAnnotation Special288hi def link erlangTodo Todo289hi def link erlangShebang Comment290 291" Numbers292hi def link erlangNumberInteger Number293hi def link erlangNumberFloat Float294 295" Strings, atoms, characters296hi def link erlangString String297hi def link erlangStringTripleQuoted String298 299" Triple quoted strings300if s:docstring_default_highlight != ''301 execute 'hi def link erlangDocStringDelimiter '. s:docstring_default_highlight302endif303 304if s:old_style305hi def link erlangQuotedAtom Type306else307hi def link erlangQuotedAtom String308endif309 310hi def link erlangStringModifier Special311hi def link erlangQuotedAtomModifier Special312hi def link erlangModifier Special313 314" Operators, separators315hi def link erlangOperator Operator316hi def link erlangEqualsBinary ErrorMsg317hi def link erlangRightArrow Operator318if s:old_style319hi def link erlangBracket Normal320hi def link erlangPipe Normal321else322hi def link erlangBracket Delimiter323hi def link erlangPipe Delimiter324endif325 326" Atoms, functions, variables, macros327if s:old_style328hi def link erlangAtom Normal329hi def link erlangLocalFuncCall Normal330hi def link erlangLocalFuncRef Normal331hi def link erlangGlobalFuncCall Function332hi def link erlangGlobalFuncRef Function333hi def link erlangVariable Normal334hi def link erlangAnonymousVariable erlangVariable335hi def link erlangMacro Normal336hi def link erlangQuotedMacro Normal337hi def link erlangRecord Normal338hi def link erlangQuotedRecord Normal339hi def link erlangMap Normal340else341hi def link erlangAtom String342hi def link erlangLocalFuncCall Normal343hi def link erlangLocalFuncRef Normal344hi def link erlangGlobalFuncCall Normal345hi def link erlangGlobalFuncRef Normal346hi def link erlangVariable Identifier347hi def link erlangAnonymousVariable erlangVariable348hi def link erlangMacro Macro349hi def link erlangQuotedMacro Macro350hi def link erlangRecord Structure351hi def link erlangQuotedRecord Structure352hi def link erlangMap Structure353endif354 355" Bitstrings356if !s:old_style357hi def link erlangBitType Type358endif359 360" Constants and Directives361if s:old_style362hi def link erlangAttribute Type363hi def link erlangMacroDef Type364hi def link erlangUnknownAttribute Normal365hi def link erlangInclude Type366hi def link erlangRecordDef Type367hi def link erlangDefine Type368hi def link erlangPreCondit Type369hi def link erlangType Type370else371hi def link erlangAttribute Keyword372hi def link erlangDocAttribute Keyword373hi def link erlangInnerDocAttribute Keyword374hi def link erlangMacroDef Macro375hi def link erlangUnknownAttribute Normal376hi def link erlangInclude Include377hi def link erlangRecordDef Keyword378hi def link erlangDefine Define379hi def link erlangPreCondit PreCondit380hi def link erlangType Type381endif382 383" Keywords384hi def link erlangKeyword Keyword385 386" Build-in-functions (BIFs)387hi def link erlangBIF Function388 389if s:old_style390hi def link erlangBoolean Statement391hi def link erlangExtra Statement392hi def link erlangSignal Statement393else394hi def link erlangBoolean Boolean395hi def link erlangExtra Statement396hi def link erlangSignal Statement397endif398 399let b:current_syntax = "erlang"400 401if g:main_syntax ==# 'erlang'402 unlet g:main_syntax403endif404 405let &cpo = s:cpo_save406unlet s:cpo_save407 408" vim: sw=2 et409 