blob: ca7f51b1eaa2e47c58f448f5e54afb7aab1c6656 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002" Language: Ruby
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaarec7944a2013-06-12 21:29:15 +02004" URL: https://github.com/vim-ruby/vim-ruby
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar6b730e12005-09-16 21:47:57 +00006" ----------------------------------------------------------------------------
7"
Bram Moolenaar071d4272004-06-13 20:20:40 +00008" Previous Maintainer: Mirko Nasato
Bram Moolenaar071d4272004-06-13 20:20:40 +00009" Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN)
Bram Moolenaar6b730e12005-09-16 21:47:57 +000010" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020012" Prelude {{{1
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000013if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000014 finish
15endif
16
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020017" this file uses line continuations
18let s:cpo_sav = &cpo
19set cpo&vim
20
21" Folding Config {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +000022if has("folding") && exists("ruby_fold")
23 setlocal foldmethod=syntax
24endif
25
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020026let s:foldable_groups = split(
27 \ get(
28 \ b:,
29 \ 'ruby_foldable_groups',
30 \ get(g:, 'ruby_foldable_groups', 'ALL')
31 \ )
32 \ )
33
34function! s:foldable(...) abort
35 if index(s:foldable_groups, 'ALL') > -1
36 return 1
37 endif
38
39 for l:i in a:000
40 if index(s:foldable_groups, l:i) > -1
41 return 1
42 endif
43 endfor
44
45 return 0
46endfunction " }}}
47
Bram Moolenaar1d689522010-05-28 20:54:39 +020048syn cluster rubyNotTop contains=@rubyExtendedStringSpecial,@rubyRegexpSpecial,@rubyDeclaration,rubyConditional,rubyExceptional,rubyMethodExceptional,rubyTodo
Bram Moolenaarc236c162008-07-13 17:41:49 +000049
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020050" Whitespace Errors {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +000051if exists("ruby_space_errors")
52 if !exists("ruby_no_trail_space_error")
53 syn match rubySpaceError display excludenl "\s\+$"
54 endif
55 if !exists("ruby_no_tab_space_error")
56 syn match rubySpaceError display " \+\t"me=e-1
57 endif
58endif
59
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020060" Operators {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +000061if exists("ruby_operators")
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020062 syn match rubyOperator "[~!^|*/%+-]\|&\.\@!\|\%(class\s*\)\@<!<<\|<=>\|<=\|\%(<\|\<class\s\+\u\w*\s*\)\@<!<[^<]\@=\|===\|==\|=\~\|>>\|>=\|=\@1<!>\|\*\*\|\.\.\.\|\.\.\|::"
Bram Moolenaarec7944a2013-06-12 21:29:15 +020063 syn match rubyOperator "->\|-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!="
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020064 syn region rubyBracketOperator matchgroup=rubyOperator start="\%(\w[?!]\=\|[]})]\)\@2<=\[\s*" end="\s*]" contains=ALLBUT,@rubyNotTop
Bram Moolenaar9964e462007-05-05 17:54:07 +000065endif
66
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020067" Expression Substitution and Backslash Notation {{{1
Bram Moolenaar1d689522010-05-28 20:54:39 +020068syn match rubyStringEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display
69syn match rubyStringEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display
70syn match rubyQuoteEscape "\\[\\']" contained display
Bram Moolenaar9964e462007-05-05 17:54:07 +000071
Bram Moolenaarc236c162008-07-13 17:41:49 +000072syn region rubyInterpolation matchgroup=rubyInterpolationDelimiter start="#{" end="}" contained contains=ALLBUT,@rubyNotTop
Bram Moolenaar1d689522010-05-28 20:54:39 +020073syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" display contained contains=rubyInterpolationDelimiter,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable,rubyPredefinedVariable
Bram Moolenaar9964e462007-05-05 17:54:07 +000074syn match rubyInterpolationDelimiter "#\ze\%(\$\|@@\=\)\w\+" display contained
Bram Moolenaar1d689522010-05-28 20:54:39 +020075syn match rubyInterpolation "#\$\%(-\w\|\W\)" display contained contains=rubyInterpolationDelimiter,rubyPredefinedVariable,rubyInvalidVariable
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000076syn match rubyInterpolationDelimiter "#\ze\$\%(-\w\|\W\)" display contained
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020077syn region rubyNoInterpolation start="\\#{" end="}" contained
Bram Moolenaar9964e462007-05-05 17:54:07 +000078syn match rubyNoInterpolation "\\#{" display contained
79syn match rubyNoInterpolation "\\#\%(\$\|@@\=\)\w\+" display contained
Bram Moolenaar1d689522010-05-28 20:54:39 +020080syn match rubyNoInterpolation "\\#\$\W" display contained
Bram Moolenaar6b730e12005-09-16 21:47:57 +000081
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020082syn match rubyDelimiterEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE
Bram Moolenaar6b730e12005-09-16 21:47:57 +000083
Bram Moolenaar1d689522010-05-28 20:54:39 +020084syn region rubyNestedParentheses start="(" skip="\\\\\|\\)" matchgroup=rubyString end=")" transparent contained
85syn region rubyNestedCurlyBraces start="{" skip="\\\\\|\\}" matchgroup=rubyString end="}" transparent contained
86syn region rubyNestedAngleBrackets start="<" skip="\\\\\|\\>" matchgroup=rubyString end=">" transparent contained
87syn region rubyNestedSquareBrackets start="\[" skip="\\\\\|\\\]" matchgroup=rubyString end="\]" transparent contained
Bram Moolenaar6b730e12005-09-16 21:47:57 +000088
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020089" Regular Expression Metacharacters {{{1
Bram Moolenaarc236c162008-07-13 17:41:49 +000090" These are mostly Oniguruma ready
Bram Moolenaar1d689522010-05-28 20:54:39 +020091syn region rubyRegexpComment matchgroup=rubyRegexpSpecial start="(?#" skip="\\)" end=")" contained
92syn region rubyRegexpParens matchgroup=rubyRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\)" end=")" contained transparent contains=@rubyRegexpSpecial
93syn region rubyRegexpBrackets matchgroup=rubyRegexpCharClass start="\[\^\=" skip="\\\]" end="\]" contained transparent contains=rubyStringEscape,rubyRegexpEscape,rubyRegexpCharClass oneline
94syn match rubyRegexpCharClass "\\[DdHhSsWw]" contained display
95syn match rubyRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]" contained
96syn match rubyRegexpEscape "\\[].*?+^$|\\/(){}[]" contained
97syn match rubyRegexpQuantifier "[*?+][?+]\=" contained display
98syn match rubyRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display
99syn match rubyRegexpAnchor "[$^]\|\\[ABbGZz]" contained display
100syn match rubyRegexpDot "\." contained display
101syn match rubyRegexpSpecial "|" contained display
102syn match rubyRegexpSpecial "\\[1-9]\d\=\d\@!" contained display
Bram Moolenaarc236c162008-07-13 17:41:49 +0000103syn match rubyRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display
104syn match rubyRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display
105syn match rubyRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display
106syn match rubyRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display
107
Bram Moolenaar1d689522010-05-28 20:54:39 +0200108syn cluster rubyStringSpecial contains=rubyInterpolation,rubyNoInterpolation,rubyStringEscape
109syn cluster rubyExtendedStringSpecial contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets
110syn cluster rubyRegexpSpecial contains=rubyInterpolation,rubyNoInterpolation,rubyStringEscape,rubyRegexpSpecial,rubyRegexpEscape,rubyRegexpBrackets,rubyRegexpCharClass,rubyRegexpDot,rubyRegexpQuantifier,rubyRegexpAnchor,rubyRegexpParens,rubyRegexpComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200112" Numbers and ASCII Codes {{{1
113syn match rubyASCIICode "\%(\w\|[]})\"'/]\)\@1<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)"
114syn match rubyInteger "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<0[xX]\x\+\%(_\x\+\)*r\=i\=\>" display
115syn match rubyInteger "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)r\=i\=\>" display
116syn match rubyInteger "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<0[oO]\=\o\+\%(_\o\+\)*r\=i\=\>" display
117syn match rubyInteger "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<0[bB][01]\+\%(_[01]\+\)*r\=i\=\>" display
118syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*r\=i\=\>" display
119syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)r\=i\=\>" display
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200121" Identifiers {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000122syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
123syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200125syn match rubyConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\u\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@!"
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200126syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200127syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200128syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)"
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200129syn match rubySymbol "[]})\"':]\@1<!:\%(\^\|\~@\|\~\|<<\|<=>\|<=\|<\|===\|[=!]=\|[=!]\~\|!@\|!\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)"
130syn match rubySymbol "[]})\"':]\@1<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)"
131syn match rubySymbol "[]})\"':]\@1<!:\%(\$\|@@\=\)\=\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*"
132syn match rubySymbol "[]})\"':]\@1<!:\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\%([?!=]>\@!\)\="
133
134if s:foldable(':')
135 syn region rubySymbol start="[]})\"':]\@1<!:'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape fold
136 syn region rubySymbol start="[]})\"':]\@1<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold
137else
138 syn region rubySymbol start="[]})\"':]\@1<!:'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape
139 syn region rubySymbol start="[]})\"':]\@1<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial
140endif
141
142syn match rubyCapitalizedMethod "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\u\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)*\s*(\@="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200144syn match rubyBlockParameter "\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" contained
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200145syn region rubyBlockParameterList start="\%(\%(\<do\>\|{\)\_s*\)\@32<=|" end="|" oneline display contains=rubyBlockParameter
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000146
Bram Moolenaar1d689522010-05-28 20:54:39 +0200147syn match rubyInvalidVariable "$[^ A-Za-z_-]"
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200148syn match rubyPredefinedVariable #$[!$&"'*+,./0:;<=>?@\`~]#
149syn match rubyPredefinedVariable "$\d\+" display
Bram Moolenaar1e015462005-09-25 22:16:38 +0000150syn match rubyPredefinedVariable "$_\>" display
151syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display
152syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display
153syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200154syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\%(ARGF\|ARGV\|ENV\|DATA\|FALSE\|NIL\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!"
155syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\%(RUBY_\%(VERSION\|RELEASE_DATE\|PLATFORM\|PATCHLEVEL\|REVISION\|DESCRIPTION\|COPYRIGHT\|ENGINE\)\)\>\%(\s*(\)\@!"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200157" Normal Regular Expression {{{1
158if s:foldable('/')
159 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold
160 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold
161else
162 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial
163 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial
164endif
Bram Moolenaarc236c162008-07-13 17:41:49 +0000165
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200166" Generalized Regular Expression {{{1
167if s:foldable('%')
168 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial fold
169 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial fold
170 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape fold
171 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial fold
172 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial fold
173 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z(\s\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial fold
174else
175 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial
176 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial
177 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape
178 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial
179 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial
180 syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z(\s\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial
181endif
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000182
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200183" Normal String {{{1
184let s:spell_cluster = exists('ruby_spellcheck_strings') ? ',@Spell' : ''
185exe 'syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" ' .
186 \ (s:foldable('%') ? 'fold' : '') . ' contains=@rubyStringSpecial' . s:spell_cluster
187exe 'syn region rubyString matchgroup=rubyStringDelimiter start="''" end="''" skip="\\\\\|\\''" ' .
188 \ (s:foldable('%') ? 'fold' : '') . ' contains=rubyQuoteEscape' . s:spell_cluster
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000189
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200190" Shell Command Output {{{1
191if s:foldable('%')
192 syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold
193else
194 syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial
195endif
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000196
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200197" Generalized Single Quoted String, Symbol and Array of Strings {{{1
198if s:foldable('%')
199 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
200 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimiterEscape
201 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimiterEscape
202 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimiterEscape
203 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimiterEscape
204 syn region rubyString matchgroup=rubyStringDelimiter start="%q\z(\s\)" end="\z1" skip="\\\\\|\\\z1" fold
205 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
206 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimiterEscape
207 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimiterEscape
208 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimiterEscape
209 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimiterEscape
210 syn region rubyString matchgroup=rubyStringDelimiter start="%s\z(\s\)" end="\z1" skip="\\\\\|\\\z1" fold
211else
212 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1"
213 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimiterEscape
214 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimiterEscape
215 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimiterEscape
216 syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimiterEscape
217 syn region rubyString matchgroup=rubyStringDelimiter start="%q\z(\s\)" end="\z1" skip="\\\\\|\\\z1"
218 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1"
219 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimiterEscape
220 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimiterEscape
221 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimiterEscape
222 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimiterEscape
223 syn region rubyString matchgroup=rubyStringDelimiter start="%s\z(\s\)" end="\z1" skip="\\\\\|\\\z1"
224endif
225
226" Generalized Double Quoted String and Array of Strings and Shell Command Output {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000227" Note: %= is not matched here as the beginning of a double quoted string
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200228if s:foldable('%')
229 syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
230 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
231 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimiterEscape fold
232 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape fold
233 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimiterEscape fold
234 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimiterEscape fold
235 syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx]\z(\s\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
236else
237 syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
238 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
239 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimiterEscape
240 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape
241 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimiterEscape
242 syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimiterEscape
243 syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx]\z(\s\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
244endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200246" Array of Symbols {{{1
247if s:foldable('%')
248 " Array of Symbols
249 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
250 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimiterEscape
251 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimiterEscape
252 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimiterEscape
253 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimiterEscape
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200255 " Array of interpolated Symbols
256 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
257 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimiterEscape fold
258 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape fold
259 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimiterEscape fold
260 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimiterEscape fold
261else
262 " Array of Symbols
263 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1"
264 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimiterEscape
265 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimiterEscape
266 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimiterEscape
267 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimiterEscape
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000268
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200269 " Array of interpolated Symbols
270 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
271 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimiterEscape
272 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimiterEscape
273 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimiterEscape
274 syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimiterEscape
275endif
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000276
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200277" Here Document {{{1
278syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<[-~]\=\zs\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
279syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<[-~]\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
280syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<[-~]\=\zs'\%([^']*\)'+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
281syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<[-~]\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
282
283if s:foldable('<<')
284 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial fold keepend
285 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial fold keepend
286 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc fold keepend
287 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial fold keepend
288
289 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
290 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
291 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart fold keepend
292 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
293else
294 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial keepend
295 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial keepend
296 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc keepend
297 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]})"'.]\)\s\|\w\)\@<!<<`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,rubyHeredoc,@rubyStringSpecial keepend
298
299 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
300 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
301 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart keepend
302 syn region rubyString start=+\%(\%(class\|::\)\_s*\|\%([]}).]\)\s\|\w\)\@<!<<[-~]`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
303endif
304
305" eRuby Config {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000306if exists('main_syntax') && main_syntax == 'eruby'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000307 let b:ruby_no_expensive = 1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000308end
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200310" Module, Class, Method and Alias Declarations {{{1
Bram Moolenaar1d689522010-05-28 20:54:39 +0200311syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable nextgroup=rubyAliasDeclaration2 skipwhite
312syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable
313syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
314syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyConstant,rubyOperator
315syn match rubyModuleDeclaration "[^[:space:];#<]\+" contained contains=rubyConstant,rubyOperator
316syn match rubyFunction "\<[_[:alpha:]][_[:alnum:]]*[?!=]\=[[:alnum:]_.:?!=]\@!" contained containedin=rubyMethodDeclaration
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200317syn match rubyFunction "\%(\s\|^\)\@1<=[_[:alpha:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2
318syn match rubyFunction "\%([[:space:].]\|^\)\@2<=\%(\[\]=\=\|\*\*\|[-+!~]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|[=!]=\|[=!]\~\|!\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000319
Bram Moolenaar1d689522010-05-28 20:54:39 +0200320syn cluster rubyDeclaration contains=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration,rubyModuleDeclaration,rubyClassDeclaration,rubyFunction,rubyBlockParameter
321
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200322" Keywords {{{1
Bram Moolenaar1d689522010-05-28 20:54:39 +0200323" Note: the following keywords have already been defined:
324" begin case class def do end for if module unless until while
325syn match rubyControl "\<\%(and\|break\|in\|next\|not\|or\|redo\|rescue\|retry\|return\)\>[?!]\@!"
326syn match rubyOperator "\<defined?" display
327syn match rubyKeyword "\<\%(super\|yield\)\>[?!]\@!"
328syn match rubyBoolean "\<\%(true\|false\)\>[?!]\@!"
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200329syn match rubyPseudoVariable "\<\%(nil\|self\|__ENCODING__\|__dir__\|__FILE__\|__LINE__\|__callee__\|__method__\)\>[?!]\@!" " TODO: reorganise
Bram Moolenaar1d689522010-05-28 20:54:39 +0200330syn match rubyBeginEnd "\<\%(BEGIN\|END\)\>[?!]\@!"
Bram Moolenaarc236c162008-07-13 17:41:49 +0000331
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200332" Expensive Mode {{{1
333" Match 'end' with the appropriate opening keyword for syntax based folding
334" and special highlighting of module/class/method definitions
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000335if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
Bram Moolenaar1d689522010-05-28 20:54:39 +0200336 syn match rubyDefine "\<alias\>" nextgroup=rubyAliasDeclaration skipwhite skipnl
337 syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
338 syn match rubyDefine "\<undef\>" nextgroup=rubyFunction skipwhite skipnl
339 syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
340 syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
341
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200342 if s:foldable('def')
343 syn region rubyMethodBlock start="\<def\>" matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop fold
344 else
345 syn region rubyMethodBlock start="\<def\>" matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop
346 endif
347
348 if s:foldable('class')
349 syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=ALLBUT,@rubyNotTop fold
350 else
351 syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=ALLBUT,@rubyNotTop
352 endif
353
354 if s:foldable('module')
355 syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=ALLBUT,@rubyNotTop fold
356 else
357 syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=ALLBUT,@rubyNotTop
358 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000360 " modifiers
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200361 syn match rubyLineContinuation "\\$" nextgroup=rubyConditionalModifier,rubyRepeatModifier skipwhite skipnl
362 syn match rubyConditionalModifier "\<\%(if\|unless\)\>"
363 syn match rubyRepeatModifier "\<\%(while\|until\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200365 if s:foldable('do')
366 syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,@rubyNotTop fold
367 else
368 syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,@rubyNotTop
369 endif
370
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000371 " curly bracket block or hash literal
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200372 if s:foldable('{')
373 syn region rubyCurlyBlock matchgroup=rubyCurlyBlockDelimiter start="{" end="}" contains=ALLBUT,@rubyNotTop fold
374 else
375 syn region rubyCurlyBlock matchgroup=rubyCurlyBlockDelimiter start="{" end="}" contains=ALLBUT,@rubyNotTop
376 endif
377
378 if s:foldable('[')
379 syn region rubyArrayLiteral matchgroup=rubyArrayDelimiter start="\%(\w\|[\]})]\)\@<!\[" end="]" contains=ALLBUT,@rubyNotTop fold
380 else
381 syn region rubyArrayLiteral matchgroup=rubyArrayDelimiter start="\%(\w\|[\]})]\)\@<!\[" end="]" contains=ALLBUT,@rubyNotTop
382 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000383
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000384 " statements without 'do'
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200385 if s:foldable('begin')
386 syn region rubyBlockExpression matchgroup=rubyControl start="\<begin\>" end="\<end\>" contains=ALLBUT,@rubyNotTop fold
387 else
388 syn region rubyBlockExpression matchgroup=rubyControl start="\<begin\>" end="\<end\>" contains=ALLBUT,@rubyNotTop
389 endif
390
391 if s:foldable('case')
392 syn region rubyCaseExpression matchgroup=rubyConditional start="\<case\>" end="\<end\>" contains=ALLBUT,@rubyNotTop fold
393 else
394 syn region rubyCaseExpression matchgroup=rubyConditional start="\<case\>" end="\<end\>" contains=ALLBUT,@rubyNotTop
395 endif
396
397 if s:foldable('if')
398 syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![?!]\)\s*\)\@<=\%(if\|unless\)\>" end="\%(\%(\%(\.\@1<!\.\)\|::\)\s*\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop fold
399 else
400 syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![?!]\)\s*\)\@<=\%(if\|unless\)\>" end="\%(\%(\%(\.\@1<!\.\)\|::\)\s*\)\@<!\<end\>" contains=ALLBUT,@rubyNotTop
401 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402
Bram Moolenaar1d689522010-05-28 20:54:39 +0200403 syn match rubyConditional "\<\%(then\|else\|when\)\>[?!]\@!" contained containedin=rubyCaseExpression
Bram Moolenaarc236c162008-07-13 17:41:49 +0000404 syn match rubyConditional "\<\%(then\|else\|elsif\)\>[?!]\@!" contained containedin=rubyConditionalExpression
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405
Bram Moolenaar1d689522010-05-28 20:54:39 +0200406 syn match rubyExceptional "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyBlockExpression
407 syn match rubyMethodExceptional "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>[?!]\@!" contained containedin=rubyMethodBlock
408
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000409 " statements with optional 'do'
Bram Moolenaarc236c162008-07-13 17:41:49 +0000410 syn region rubyOptionalDoLine matchgroup=rubyRepeat start="\<for\>[?!]\@!" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyOptionalDo end="\%(\<do\>\)" end="\ze\%(;\|$\)" oneline contains=ALLBUT,@rubyNotTop
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200411
412 if s:foldable('for')
413 syn region rubyRepeatExpression start="\<for\>[?!]\@!" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=ALLBUT,@rubyNotTop nextgroup=rubyOptionalDoLine fold
414 else
415 syn region rubyRepeatExpression start="\<for\>[?!]\@!" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=ALLBUT,@rubyNotTop nextgroup=rubyOptionalDoLine
416 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417
418 if !exists("ruby_minlines")
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200419 let ruby_minlines = 500
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420 endif
421 exec "syn sync minlines=" . ruby_minlines
422
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000423else
Bram Moolenaar1d689522010-05-28 20:54:39 +0200424 syn match rubyControl "\<def\>[?!]\@!" nextgroup=rubyMethodDeclaration skipwhite skipnl
425 syn match rubyControl "\<class\>[?!]\@!" nextgroup=rubyClassDeclaration skipwhite skipnl
426 syn match rubyControl "\<module\>[?!]\@!" nextgroup=rubyModuleDeclaration skipwhite skipnl
427 syn match rubyControl "\<\%(case\|begin\|do\|for\|if\|unless\|while\|until\|else\|elsif\|ensure\|then\|when\|end\)\>[?!]\@!"
428 syn match rubyKeyword "\<\%(alias\|undef\)\>[?!]\@!"
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000429endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200431" Special Methods {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000432if !exists("ruby_no_special_methods")
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200433 syn keyword rubyAccess public protected private public_class_method private_class_method public_constant private_constant module_function
Bram Moolenaarc236c162008-07-13 17:41:49 +0000434 " attr is a common variable name
435 syn match rubyAttribute "\%(\%(^\|;\)\s*\)\@<=attr\>\(\s*[.=]\)\@!"
436 syn keyword rubyAttribute attr_accessor attr_reader attr_writer
437 syn match rubyControl "\<\%(exit!\|\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>[?!]\@!\)"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000438 syn keyword rubyEval eval class_eval instance_eval module_eval
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000439 syn keyword rubyException raise fail catch throw
Bram Moolenaarc236c162008-07-13 17:41:49 +0000440 " false positive with 'include?'
441 syn match rubyInclude "\<include\>[?!]\@!"
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200442 syn keyword rubyInclude autoload extend load prepend refine require require_relative using
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000443 syn keyword rubyKeyword callcc caller lambda proc
444endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200446" Comments and Documentation {{{1
Bram Moolenaar1d689522010-05-28 20:54:39 +0200447syn match rubySharpBang "\%^#!.*" display
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200448syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE HACK REVIEW XXX todo contained
Bram Moolenaar1d689522010-05-28 20:54:39 +0200449syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200450if !exists("ruby_no_comment_fold") && s:foldable('#')
451 syn region rubyMultilineComment start="^\s*#.*\n\%(^\s*#\)\@=" end="^\s*#.*\n\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200452 syn region rubyDocumentation start="^=begin\ze\%(\s.*\)\=$" end="^=end\%(\s.*\)\=$" contains=rubySpaceError,rubyTodo,@Spell fold
Bram Moolenaar9964e462007-05-05 17:54:07 +0000453else
454 syn region rubyDocumentation start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell
455endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200457" Keyword Nobbling {{{1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000458" Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200459syn match rubyKeywordAsMethod "\%(\%(\.\@1<!\.\)\|::\)\_s*\%([_[:lower:]][_[:alnum:]]*\|\<\%(BEGIN\|END\)\>\)" transparent contains=NONE
460syn match rubyKeywordAsMethod "\(defined?\|exit!\)\@!\<[_[:lower:]][_[:alnum:]]*[?!]" transparent contains=NONE
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000461
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200462" More Symbols {{{1
463syn match rubySymbol "\%([{(,]\_s*\)\zs\l\w*[!?]\=::\@!"he=e-1
464syn match rubySymbol "[]})\"':]\@1<!\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],]\@="he=e-1
465syn match rubySymbol "\%([{(,]\_s*\)\zs[[:space:],{]\l\w*[!?]\=::\@!"hs=s+1,he=e-1
466syn match rubySymbol "[[:space:],{(]\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],]\@="hs=s+1,he=e-1
Bram Moolenaarc236c162008-07-13 17:41:49 +0000467
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200468" __END__ Directive {{{1
469if s:foldable('__END__')
470 syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold
471else
472 syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$"
473endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000474
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200475" Default Highlighting {{{1
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000476hi def link rubyClass rubyDefine
477hi def link rubyModule rubyDefine
Bram Moolenaar1d689522010-05-28 20:54:39 +0200478hi def link rubyMethodExceptional rubyDefine
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000479hi def link rubyDefine Define
480hi def link rubyFunction Function
481hi def link rubyConditional Conditional
482hi def link rubyConditionalModifier rubyConditional
Bram Moolenaar1d689522010-05-28 20:54:39 +0200483hi def link rubyExceptional rubyConditional
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000484hi def link rubyRepeat Repeat
485hi def link rubyRepeatModifier rubyRepeat
486hi def link rubyOptionalDo rubyRepeat
487hi def link rubyControl Statement
488hi def link rubyInclude Include
489hi def link rubyInteger Number
490hi def link rubyASCIICode Character
491hi def link rubyFloat Float
492hi def link rubyBoolean Boolean
493hi def link rubyException Exception
494if !exists("ruby_no_identifiers")
495 hi def link rubyIdentifier Identifier
496else
497 hi def link rubyIdentifier NONE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498endif
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000499hi def link rubyClassVariable rubyIdentifier
500hi def link rubyConstant Type
501hi def link rubyGlobalVariable rubyIdentifier
502hi def link rubyBlockParameter rubyIdentifier
503hi def link rubyInstanceVariable rubyIdentifier
504hi def link rubyPredefinedIdentifier rubyIdentifier
505hi def link rubyPredefinedConstant rubyPredefinedIdentifier
506hi def link rubyPredefinedVariable rubyPredefinedIdentifier
507hi def link rubySymbol Constant
508hi def link rubyKeyword Keyword
509hi def link rubyOperator Operator
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000510hi def link rubyBeginEnd Statement
511hi def link rubyAccess Statement
512hi def link rubyAttribute Statement
513hi def link rubyEval Statement
514hi def link rubyPseudoVariable Constant
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200515hi def link rubyCapitalizedMethod rubyLocalVariableOrMethod
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000516
517hi def link rubyComment Comment
518hi def link rubyData Comment
519hi def link rubyDataDirective Delimiter
520hi def link rubyDocumentation Comment
Bram Moolenaarc236c162008-07-13 17:41:49 +0000521hi def link rubyTodo Todo
522
Bram Moolenaar1d689522010-05-28 20:54:39 +0200523hi def link rubyQuoteEscape rubyStringEscape
Bram Moolenaarc236c162008-07-13 17:41:49 +0000524hi def link rubyStringEscape Special
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000525hi def link rubyInterpolationDelimiter Delimiter
526hi def link rubyNoInterpolation rubyString
527hi def link rubySharpBang PreProc
528hi def link rubyRegexpDelimiter rubyStringDelimiter
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200529hi def link rubySymbolDelimiter rubySymbol
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000530hi def link rubyStringDelimiter Delimiter
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200531hi def link rubyHeredoc rubyString
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000532hi def link rubyString String
Bram Moolenaarc236c162008-07-13 17:41:49 +0000533hi def link rubyRegexpEscape rubyRegexpSpecial
534hi def link rubyRegexpQuantifier rubyRegexpSpecial
535hi def link rubyRegexpAnchor rubyRegexpSpecial
536hi def link rubyRegexpDot rubyRegexpCharClass
537hi def link rubyRegexpCharClass rubyRegexpSpecial
538hi def link rubyRegexpSpecial Special
539hi def link rubyRegexpComment Comment
540hi def link rubyRegexp rubyString
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000541
542hi def link rubyInvalidVariable Error
543hi def link rubyError Error
544hi def link rubySpaceError rubyError
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200546" Postscript {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547let b:current_syntax = "ruby"
548
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200549let &cpo = s:cpo_sav
550unlet! s:cpo_sav
551
552" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: