blob: f68d7f4dac115e70d4ba5cda0f3f291afee01903 [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>
4" Info: $Id$
5" URL: http://vim-ruby.rubyforge.org
6" Anon CVS: See above site
7" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar6b730e12005-09-16 21:47:57 +00008" ----------------------------------------------------------------------------
9"
Bram Moolenaar071d4272004-06-13 20:20:40 +000010" Previous Maintainer: Mirko Nasato
Bram Moolenaar071d4272004-06-13 20:20:40 +000011" Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN)
Bram Moolenaar6b730e12005-09-16 21:47:57 +000012" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000014if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000015 finish
16endif
17
Bram Moolenaar6b730e12005-09-16 21:47:57 +000018if has("folding") && exists("ruby_fold")
19 setlocal foldmethod=syntax
20endif
21
22if exists("ruby_space_errors")
23 if !exists("ruby_no_trail_space_error")
24 syn match rubySpaceError display excludenl "\s\+$"
25 endif
26 if !exists("ruby_no_tab_space_error")
27 syn match rubySpaceError display " \+\t"me=e-1
28 endif
29endif
30
Bram Moolenaar9964e462007-05-05 17:54:07 +000031" Operators
32if exists("ruby_operators")
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000033 syn match rubyOperator "\%([~!^&|*/%+-]\|\%(class\s*\)\@<!<<\|<=>\|<=\|\%(<\|\<class\s\+\u\w*\s*\)\@<!<[^<]\@=\|===\|==\|=\~\|>>\|>=\|=\@<!>\|\*\*\|\.\.\.\|\.\.\|::\)"
34 syn match rubyPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)"
35 syn region rubyBracketOperator matchgroup=rubyOperator start="\%([_[:lower:]]\w*[?!=]\=\|[})]\)\@<=\[\s*" end="\s*]" contains=TOP
Bram Moolenaar9964e462007-05-05 17:54:07 +000036endif
37
Bram Moolenaar071d4272004-06-13 20:20:40 +000038" Expression Substitution and Backslash Notation
Bram Moolenaar9964e462007-05-05 17:54:07 +000039syn match rubyEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display
40syn match rubyEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display
41
42syn region rubyInterpolation matchgroup=rubyInterpolationDelimiter start="#{" end="}" contained contains=TOP
43syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" display contained contains=rubyInterpolationDelimiter,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable,rubyPredefinedVariable
44syn match rubyInterpolationDelimiter "#\ze\%(\$\|@@\=\)\w\+" display contained
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000045syn match rubyInterpolation "#\$\%(-\w\|\W\)" display contained contains=rubyInterpolationDelimiter,rubyPredefinedVariable,rubyInvalidVariable
46syn match rubyInterpolationDelimiter "#\ze\$\%(-\w\|\W\)" display contained
Bram Moolenaar9964e462007-05-05 17:54:07 +000047syn region rubyNoInterpolation start="\\#{" end="}" contained
48syn match rubyNoInterpolation "\\#{" display contained
49syn match rubyNoInterpolation "\\#\%(\$\|@@\=\)\w\+" display contained
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000050syn match rubyNoInterpolation "\\#\$\W" display contained
Bram Moolenaar6b730e12005-09-16 21:47:57 +000051
52syn match rubyDelimEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE
53
54syn region rubyNestedParentheses start="(" end=")" skip="\\\\\|\\)" transparent contained contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape
55syn region rubyNestedCurlyBraces start="{" end="}" skip="\\\\\|\\}" transparent contained contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape
56syn region rubyNestedAngleBrackets start="<" end=">" skip="\\\\\|\\>" transparent contained contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000057if exists("ruby_operators")
58 syn region rubyNestedSquareBrackets start="\[" end="\]" skip="\\\\\|\\\]" transparent contained contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape
59else
60 syn region rubyNestedSquareBrackets start="\[" end="\]" skip="\\\\\|\\\]" transparent containedin=rubyArrayLiteral contained contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape
61endif
Bram Moolenaar6b730e12005-09-16 21:47:57 +000062
63syn cluster rubyStringSpecial contains=rubyInterpolation,rubyNoInterpolation,rubyEscape
64syn cluster rubyExtendedStringSpecial contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66" Numbers and ASCII Codes
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000067syn match rubyASCIICode "\%(\w\|[]})\"'/]\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)"
Bram Moolenaar6b730e12005-09-16 21:47:57 +000068syn match rubyInteger "\<0[xX]\x\+\%(_\x\+\)*\>" display
69syn match rubyInteger "\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)\>" display
70syn match rubyInteger "\<0[oO]\=\o\+\%(_\o\+\)*\>" display
71syn match rubyInteger "\<0[bB][01]\+\%(_[01]\+\)*\>" display
72syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*\>" display
73syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)\>" display
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar6b730e12005-09-16 21:47:57 +000075" Identifiers
76syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
77syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Bram Moolenaar9964e462007-05-05 17:54:07 +000079syn match rubyConstant "\%(\%([.@$]\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\%(\>\|::\)\@=\%(\s*(\)\@!"
Bram Moolenaar6b730e12005-09-16 21:47:57 +000080syn match rubyClassVariable "@@\h\w*" display
81syn match rubyInstanceVariable "@\h\w*" display
82syn match rubyGlobalVariable "$\%(\h\w*\|-.\)"
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000083syn match rubySymbol "[]})\"':]\@<!:\%(\^\|\~\|<<\|<=>\|<=\|<\|===\|==\|=\~\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)"
84syn match rubySymbol "[]})\"':]\@<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)"
85syn match rubySymbol "[]})\"':]\@<!:\%(\$\|@@\=\)\=\h\w*"
86syn match rubySymbol "[]})\"':]\@<!:\h\w*[?!=]\="
87syn region rubySymbol start="[]})\"':]\@<!:\"" end="\"" skip="\\\\\|\\\""
88syn region rubySymbol start="[]})\"':]\@<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaarc1762cc2007-05-10 16:56:30 +000090syn match rubyBlockParameter "\h\w*" contained
91syn region rubyBlockParameterList start="\%(\%(\<do\>\|{\)\s*\)\@<=|" end="|" oneline display contains=rubyBlockParameter
92
93syn match rubyInvalidVariable "$[^ A-Za-z-]"
Bram Moolenaar6b730e12005-09-16 21:47:57 +000094syn match rubyPredefinedVariable #$[!$&"'*+,./0:;<=>?@\`~1-9]#
Bram Moolenaar1e015462005-09-25 22:16:38 +000095syn match rubyPredefinedVariable "$_\>" display
96syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display
97syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display
98syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display
Bram Moolenaar6b730e12005-09-16 21:47:57 +000099syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!"
100syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\|RUBY_PLATFORM\|RUBY_RELEASE_DATE\)\>\%(\s*(\)\@!"
101syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(RUBY_VERSION\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!"
102"Obsolete Global Constants
103"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(PLATFORM\|RELEASE_DATE\|VERSION\)\>"
104"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(NotImplementError\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
106" Normal Regular Expression
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000107syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[>]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold
108syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\<\%(split\|scan\|gsub\|sub\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000109
110" Normal String and Shell Command Output
Bram Moolenaar9964e462007-05-05 17:54:07 +0000111syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold
112syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" fold
113syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000114
115" Generalized Regular Expression
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000116syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
117syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
118syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
119syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
120syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000121
122" Generalized Single Quoted String, Symbol and Array of Strings
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000123syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
124syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape
125syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape
126syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape
127syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape
128syn region rubySymbol start="%[s]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
129syn region rubySymbol start="%[s]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape
130syn region rubySymbol start="%[s]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape
131syn region rubySymbol start="%[s]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape
132syn region rubySymbol start="%[s](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000133
134" Generalized Double Quoted String and Array of Strings and Shell Command Output
135" Note: %= is not matched here as the beginning of a double quoted string
136syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
137syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
138syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
139syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
140syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
141syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
143" Here Document
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000144syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<-\=\zs\%(\h\w*\)+ end=+$+ oneline contains=TOP
145syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<-\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=TOP
146syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<-\=\zs'\%([^']*\)'+ end=+$+ oneline contains=TOP
147syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<-\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=TOP
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000149syn region rubyString start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<\z(\h\w*\)\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
150syn region rubyString start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<"\z([^"]*\)"\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
151syn region rubyString start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<'\z([^']*\)'\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart fold keepend
152syn region rubyString start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@<!<<`\z([^`]*\)`\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000153
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000154syn region rubyString start=+\%(\%(class\s*\|\%([]}).]\|::\)\)\_s*\|\w\)\@<!<<-\z(\h\w*\)\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
155syn region rubyString start=+\%(\%(class\s*\|\%([]}).]\|::\)\)\_s*\|\w\)\@<!<<-"\z([^"]*\)"\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
156syn region rubyString start=+\%(\%(class\s*\|\%([]}).]\|::\)\)\_s*\|\w\)\@<!<<-'\z([^']*\)'\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart fold keepend
157syn region rubyString start=+\%(\%(class\s*\|\%([]}).]\|::\)\)\_s*\|\w\)\@<!<<-`\z([^`]*\)`\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000158
159if exists('main_syntax') && main_syntax == 'eruby'
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000160 let b:ruby_no_expensive = 1
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000161end
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
Bram Moolenaar9964e462007-05-05 17:54:07 +0000163syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable nextgroup=rubyAliasDeclaration2 skipwhite
164syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable
165syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
166syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyConstant
167syn match rubyModuleDeclaration "[^[:space:];#]\+" contained contains=rubyConstant
168syn match rubyFunction "\<[_[:alpha:]][_[:alnum:]]*[?!=]\=[[:alnum:].:?!=]\@!" contained containedin=rubyMethodDeclaration
169syn match rubyFunction "\%(\s\|^\)\@<=[_[:alpha:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2
170syn match rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|==\|=\~\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000171
172" Expensive Mode - match 'end' with the appropriate opening keyword for syntax
173" based folding and special highlighting of module/class/method definitions
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000174if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000175 syn match rubyDefine "\<alias\>" nextgroup=rubyAliasDeclaration skipwhite skipnl
176 syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
177 syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
178 syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
179 syn region rubyBlock start="\<def\>" matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=TOP fold
180 syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=TOP fold
181 syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=TOP fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000183 " modifiers
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000184 syn match rubyConditionalModifier "\<\%(if\|unless\)\>" display
185 syn match rubyRepeatModifier "\<\%(while\|until\)\>" display
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186
Bram Moolenaar9964e462007-05-05 17:54:07 +0000187 syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=TOP fold
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000188 " curly bracket block or hash literal
189 syn region rubyCurlyBlock start="{" end="}" contains=TOP fold
190 syn region rubyArrayLiteral matchgroup=rubyArrayDelimiter start="\%(\w\|[\]})]\)\@<!\[" end="]" contains=TOP fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000192 " statements without 'do'
193 syn region rubyBlockExpression matchgroup=rubyControl start="\<begin\>" end="\<end\>" contains=TOP fold
194 syn region rubyCaseExpression matchgroup=rubyConditional start="\<case\>" end="\<end\>" contains=TOP fold
195 syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!?]\)\s*\)\@<=\%(if\|unless\)\>" end="\<end\>" contains=TOP fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000196
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000197 syn keyword rubyConditional then else when contained containedin=rubyCaseExpression
198 syn keyword rubyConditional then else elsif contained containedin=rubyConditionalExpression
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000200 " statements with optional 'do'
201 syn region rubyOptionalDoLine matchgroup=rubyRepeat start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyOptionalDo end="\%(\<do\>\)" end="\ze\%(;\|$\)" oneline contains=TOP
202 syn region rubyRepeatExpression start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=TOP nextgroup=rubyOptionalDoLine fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203
204 if !exists("ruby_minlines")
205 let ruby_minlines = 50
206 endif
207 exec "syn sync minlines=" . ruby_minlines
208
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000209else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000210 syn match rubyControl "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
211 syn match rubyControl "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
212 syn match rubyControl "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
213 syn keyword rubyControl case begin do for if unless while until else elsif then when end
214 syn keyword rubyKeyword alias
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000215endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
217" Keywords
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000218" Note: the following keywords have already been defined:
219" begin case class def do end for if module unless until while
Bram Moolenaar9964e462007-05-05 17:54:07 +0000220syn keyword rubyControl and break ensure in next not or redo rescue retry return
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000221syn match rubyOperator "\<defined?" display
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222syn keyword rubyKeyword super undef yield
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000223syn keyword rubyBoolean true false
224syn keyword rubyPseudoVariable nil self __FILE__ __LINE__
225syn keyword rubyBeginEnd BEGIN END
226
227" Special Methods
228if !exists("ruby_no_special_methods")
229 syn keyword rubyAccess public protected private
230 syn keyword rubyAttribute attr attr_accessor attr_reader attr_writer
Bram Moolenaar1e015462005-09-25 22:16:38 +0000231 syn match rubyControl "\<\%(exit!\|\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>\)"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000232 syn keyword rubyEval eval class_eval instance_eval module_eval
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000233 syn keyword rubyException raise fail catch throw
234 syn keyword rubyInclude autoload extend include load require
235 syn keyword rubyKeyword callcc caller lambda proc
236endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237
238" Comments and Documentation
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000239syn match rubySharpBang "\%^#!.*" display
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000240syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE XXX contained
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000241syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell
Bram Moolenaar9964e462007-05-05 17:54:07 +0000242if !exists("ruby_no_comment_fold")
243 syn region rubyMultilineComment start="\%(\%(^\s*#.*\n\)\@<!\%(^\s*#.*\n\)\)\%(\(^\s*#.*\n\)\{1,}\)\@=" end="\%(^\s*#.*\n\)\@<=\%(^\s*#.*\n\)\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000244 syn region rubyDocumentation start="^=begin\ze\%(\s.*\)\=$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell fold
Bram Moolenaar9964e462007-05-05 17:54:07 +0000245else
246 syn region rubyDocumentation start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell
247endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000249" Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver
250syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(alias\|and\|begin\|break\|case\|class\|def\|defined\|do\|else\)\>" transparent contains=NONE
251syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(elsif\|end\|ensure\|false\|for\|if\|in\|module\|next\|nil\)\>" transparent contains=NONE
252syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(not\|or\|redo\|rescue\|retry\|return\|self\|super\|then\|true\)\>" transparent contains=NONE
253syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(undef\|unless\|until\|when\|while\|yield\|BEGIN\|END\|__FILE__\|__LINE__\)\>" transparent contains=NONE
254
255syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(abort\|at_exit\|attr\|attr_accessor\|attr_reader\)\>" transparent contains=NONE
256syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(attr_writer\|autoload\|callcc\|catch\|caller\)\>" transparent contains=NONE
257syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(eval\|class_eval\|instance_eval\|module_eval\|exit\)\>" transparent contains=NONE
258syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(extend\|fail\|fork\|include\|lambda\)\>" transparent contains=NONE
259syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(load\|loop\|private\|proc\|protected\)\>" transparent contains=NONE
260syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(public\|require\|raise\|throw\|trap\)\>" transparent contains=NONE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261
262" __END__ Directive
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000263syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000265hi def link rubyClass rubyDefine
266hi def link rubyModule rubyDefine
267hi def link rubyDefine Define
268hi def link rubyFunction Function
269hi def link rubyConditional Conditional
270hi def link rubyConditionalModifier rubyConditional
271hi def link rubyRepeat Repeat
272hi def link rubyRepeatModifier rubyRepeat
273hi def link rubyOptionalDo rubyRepeat
274hi def link rubyControl Statement
275hi def link rubyInclude Include
276hi def link rubyInteger Number
277hi def link rubyASCIICode Character
278hi def link rubyFloat Float
279hi def link rubyBoolean Boolean
280hi def link rubyException Exception
281if !exists("ruby_no_identifiers")
282 hi def link rubyIdentifier Identifier
283else
284 hi def link rubyIdentifier NONE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285endif
Bram Moolenaarc1762cc2007-05-10 16:56:30 +0000286hi def link rubyClassVariable rubyIdentifier
287hi def link rubyConstant Type
288hi def link rubyGlobalVariable rubyIdentifier
289hi def link rubyBlockParameter rubyIdentifier
290hi def link rubyInstanceVariable rubyIdentifier
291hi def link rubyPredefinedIdentifier rubyIdentifier
292hi def link rubyPredefinedConstant rubyPredefinedIdentifier
293hi def link rubyPredefinedVariable rubyPredefinedIdentifier
294hi def link rubySymbol Constant
295hi def link rubyKeyword Keyword
296hi def link rubyOperator Operator
297hi def link rubyPseudoOperator rubyOperator
298hi def link rubyBeginEnd Statement
299hi def link rubyAccess Statement
300hi def link rubyAttribute Statement
301hi def link rubyEval Statement
302hi def link rubyPseudoVariable Constant
303
304hi def link rubyComment Comment
305hi def link rubyData Comment
306hi def link rubyDataDirective Delimiter
307hi def link rubyDocumentation Comment
308hi def link rubyEscape Special
309hi def link rubyInterpolationDelimiter Delimiter
310hi def link rubyNoInterpolation rubyString
311hi def link rubySharpBang PreProc
312hi def link rubyRegexpDelimiter rubyStringDelimiter
313hi def link rubyStringDelimiter Delimiter
314hi def link rubyRegexp rubyString
315hi def link rubyString String
316hi def link rubyTodo Todo
317
318hi def link rubyInvalidVariable Error
319hi def link rubyError Error
320hi def link rubySpaceError rubyError
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321
322let b:current_syntax = "ruby"
323
Bram Moolenaara7241f52008-06-24 20:39:31 +0000324" vim: nowrap sw=2 sts=2 ts=8 noet :