3 " Maintainer: Mirko Nasato
4 " Last Change: 2001 May 10
5 " Location: http://altern.org/mn/ruby/ruby.vim
7 " See http://altern.org/mn/ruby/vim.html for documentation.
8 " Thanks to perl.vim authors, and to Reimer Behrends. :-)
10 " For version 5.x: Clear all syntax items
11 " For version 6.x: Quit when a syntax file was already loaded
14 elseif exists("b:current_syntax")
18 " Expression Substitution: and Backslash Notation
19 syn match rubyExprSubst "\\\\\|\(\(\\M-\\C-\|\\c\|\\C-\|\\M-\)\w\)\|\(\\\o\{3}\|\\x\x\{2}\|\\[tnrfbaes]\)" contained
20 syn match rubyExprSubst "#{[^}]*}" contained
21 syn match rubyExprSubst "#[$@]\w\+" contained
23 " Numbers: and ASCII Codes
24 syn match rubyNumber "\<\(0x\x\+\|0b[01]\+\|0\o\+\|0\.\d\+\|0\|[1-9][\.0-9_]*\)\>"
25 syn match rubyNumber "?\(\\M-\\C-\|\\c\|\\C-\|\\M-\)\=\(\\\o\{3}\|\\x\x\{2}\|\\\=\w\)"
27 " Special Identifiers: instance, global, symbol, iterator, predefined
28 if !exists("ruby_no_identifiers")
29 syn match rubyIdentifier "\<\u\w*"
30 syn match rubyIdentifier "@\h\w*"
31 syn match rubyIdentifier "$\h\w*"
32 syn match rubyIdentifier "\s:\h\w*"
33 syn match rubyIdentifier "|[ ,a-zA-Z0-9_*]\+|"
34 syn match rubyIdentifier "$[\\\"/:'&`+*.,;=~!?@$<>0-9]"
35 syn match rubyIdentifier "$-[0adFiIlpv]"
39 " BEGIN Autogenerated Stuff (Ruby script @ http://altern.org/mn/ruby/vimregions.rb)
41 " Generalized Regular Expression:
42 syn region rubyString matchgroup=rubyStringDelimit start="%r!" end="![iopx]*" skip="\\\\\|\\!" contains=rubyExprSubst
43 syn region rubyString matchgroup=rubyStringDelimit start="%r\"" end="\"[iopx]*" skip="\\\\\|\\\"" contains=rubyExprSubst
44 syn region rubyString matchgroup=rubyStringDelimit start="%r#" end="#[iopx]*" skip="\\\\\|\\#" contains=rubyExprSubst
45 syn region rubyString matchgroup=rubyStringDelimit start="%r\$" end="\$[iopx]*" skip="\\\\\|\\\$" contains=rubyExprSubst
46 syn region rubyString matchgroup=rubyStringDelimit start="%r%" end="%[iopx]*" skip="\\\\\|\\%" contains=rubyExprSubst
47 syn region rubyString matchgroup=rubyStringDelimit start="%r&" end="&[iopx]*" skip="\\\\\|\\&" contains=rubyExprSubst
48 syn region rubyString matchgroup=rubyStringDelimit start="%r'" end="'[iopx]*" skip="\\\\\|\\'" contains=rubyExprSubst
49 syn region rubyString matchgroup=rubyStringDelimit start="%r\*" end="\*[iopx]*" skip="\\\\\|\\\*" contains=rubyExprSubst
50 syn region rubyString matchgroup=rubyStringDelimit start="%r+" end="+[iopx]*" skip="\\\\\|\\+" contains=rubyExprSubst
51 syn region rubyString matchgroup=rubyStringDelimit start="%r-" end="-[iopx]*" skip="\\\\\|\\-" contains=rubyExprSubst
52 syn region rubyString matchgroup=rubyStringDelimit start="%r\." end="\.[iopx]*" skip="\\\\\|\\\." contains=rubyExprSubst
53 syn region rubyString matchgroup=rubyStringDelimit start="%r/" end="/[iopx]*" skip="\\\\\|\\/" contains=rubyExprSubst
54 syn region rubyString matchgroup=rubyStringDelimit start="%r:" end=":[iopx]*" skip="\\\\\|\\:" contains=rubyExprSubst
55 syn region rubyString matchgroup=rubyStringDelimit start="%r;" end=";[iopx]*" skip="\\\\\|\\;" contains=rubyExprSubst
56 syn region rubyString matchgroup=rubyStringDelimit start="%r=" end="=[iopx]*" skip="\\\\\|\\=" contains=rubyExprSubst
57 syn region rubyString matchgroup=rubyStringDelimit start="%r?" end="?[iopx]*" skip="\\\\\|\\?" contains=rubyExprSubst
58 syn region rubyString matchgroup=rubyStringDelimit start="%r@" end="@[iopx]*" skip="\\\\\|\\@" contains=rubyExprSubst
59 syn region rubyString matchgroup=rubyStringDelimit start="%r\\" end="\\[iopx]*" contains=rubyExprSubst
60 syn region rubyString matchgroup=rubyStringDelimit start="%r\^" end="\^[iopx]*" skip="\\\\\|\\\^" contains=rubyExprSubst
61 syn region rubyString matchgroup=rubyStringDelimit start="%r`" end="`[iopx]*" skip="\\\\\|\\`" contains=rubyExprSubst
62 syn region rubyString matchgroup=rubyStringDelimit start="%r|" end="|[iopx]*" skip="\\\\\|\\|" contains=rubyExprSubst
63 syn region rubyString matchgroup=rubyStringDelimit start="%r\~" end="\~[iopx]*" skip="\\\\\|\\\~" contains=rubyExprSubst
64 syn region rubyString matchgroup=rubyStringDelimit start="%r{" end="}[iopx]*" skip="\\\\\|\\}" contains=rubyExprSubst
65 syn region rubyString matchgroup=rubyStringDelimit start="%r<" end=">[iopx]*" skip="\\\\\|\\>" contains=rubyExprSubst
66 syn region rubyString matchgroup=rubyStringDelimit start="%r\[" end="\][iopx]*" skip="\\\\\|\\\]" contains=rubyExprSubst
67 syn region rubyString matchgroup=rubyStringDelimit start="%r(" end=")[iopx]*" skip="\\\\\|\\)" contains=rubyExprSubst
69 " Generalized Single Quoted String and Array of Strings:
70 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]!" end="!" skip="\\\\\|\\!"
71 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\"" end="\"" skip="\\\\\|\\\""
72 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]#" end="#" skip="\\\\\|\\#"
73 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\$" end="\$" skip="\\\\\|\\\$"
74 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]%" end="%" skip="\\\\\|\\%"
75 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]&" end="&" skip="\\\\\|\\&"
76 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]'" end="'" skip="\\\\\|\\'"
77 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\*" end="\*" skip="\\\\\|\\\*"
78 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]+" end="+" skip="\\\\\|\\+"
79 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]-" end="-" skip="\\\\\|\\-"
80 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\." end="\." skip="\\\\\|\\\."
81 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]/" end="/" skip="\\\\\|\\/"
82 syn region rubyString matchgroup=rubyStringDelimit start="%[wq];" end=";" skip="\\\\\|\\;"
83 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]=" end="=" skip="\\\\\|\\="
84 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]?" end="?" skip="\\\\\|\\?"
85 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]@" end="@" skip="\\\\\|\\@"
86 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\\" end="\\"
87 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\^" end="\^" skip="\\\\\|\\\^"
88 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]`" end="`" skip="\\\\\|\\`"
89 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]|" end="|" skip="\\\\\|\\|"
90 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\~" end="\~" skip="\\\\\|\\\~"
91 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]{" end="}" skip="\\\\\|\\}"
92 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]<" end=">" skip="\\\\\|\\>"
93 syn region rubyString matchgroup=rubyStringDelimit start="%[wq]\[" end="\]" skip="\\\\\|\\\]"
94 syn region rubyString matchgroup=rubyStringDelimit start="%[wq](" end=")" skip="\\\\\|\\)"
96 " Generalized Double Quoted String and Shell Command Output:
97 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=!" end="!" skip="\\\\\|\\!" contains=rubyExprSubst
98 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\"" end="\"" skip="\\\\\|\\\"" contains=rubyExprSubst
99 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=#" end="#" skip="\\\\\|\\#" contains=rubyExprSubst
100 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\$" end="\$" skip="\\\\\|\\\$" contains=rubyExprSubst
101 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=%" end="%" skip="\\\\\|\\%" contains=rubyExprSubst
102 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=&" end="&" skip="\\\\\|\\&" contains=rubyExprSubst
103 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\='" end="'" skip="\\\\\|\\'" contains=rubyExprSubst
104 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\*" end="\*" skip="\\\\\|\\\*" contains=rubyExprSubst
105 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=+" end="+" skip="\\\\\|\\+" contains=rubyExprSubst
106 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=-" end="-" skip="\\\\\|\\-" contains=rubyExprSubst
107 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\." end="\." skip="\\\\\|\\\." contains=rubyExprSubst
108 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=/" end="/" skip="\\\\\|\\/" contains=rubyExprSubst
109 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=:" end=":" skip="\\\\\|\\:" contains=rubyExprSubst
110 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=;" end=";" skip="\\\\\|\\;" contains=rubyExprSubst
111 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\==" end="=" skip="\\\\\|\\=" contains=rubyExprSubst
112 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=?" end="?" skip="\\\\\|\\?" contains=rubyExprSubst
113 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=@" end="@" skip="\\\\\|\\@" contains=rubyExprSubst
114 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\\" end="\\" contains=rubyExprSubst
115 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\^" end="\^" skip="\\\\\|\\\^" contains=rubyExprSubst
116 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=`" end="`" skip="\\\\\|\\`" contains=rubyExprSubst
117 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=|" end="|" skip="\\\\\|\\|" contains=rubyExprSubst
118 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\~" end="\~" skip="\\\\\|\\\~" contains=rubyExprSubst
119 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\={" end="}" skip="\\\\\|\\}" contains=rubyExprSubst
120 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=<" end=">" skip="\\\\\|\\>" contains=rubyExprSubst
121 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=\[" end="\]" skip="\\\\\|\\\]" contains=rubyExprSubst
122 syn region rubyString matchgroup=rubyStringDelimit start="%[Qx]\=(" end=")" skip="\\\\\|\\)" contains=rubyExprSubst
124 " Normal String and Shell Command Output:
125 syn region rubyString matchgroup=rubyStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=rubyExprSubst
126 syn region rubyString matchgroup=rubyStringDelimit start="'" end="'" skip="\\\\\|\\'"
127 syn region rubyString matchgroup=rubyStringDelimit start="`" end="`" skip="\\\\\|\\`" contains=rubyExprSubst
129 " END Autogenerated Stuff
132 " Normal Regular Expression:
133 syn region rubyString matchgroup=rubyStringDelimit start="\<if\s*/"lc=2 start="[\~=!|&(,]\s*/"lc=1 end="/[iopx]*" skip="\\\\\|\\/" contains=rubyExprSubst
136 syn region rubyString matchgroup=rubyStringDelimit start=+<<-\(\u\{3,}\|'\u\{3,}'\|"\u\{3,}"\|`\u\{3,}`\)+hs=s+2 end=+^\s*\u\{3,}$+
137 syn region rubyString matchgroup=rubyStringDelimit start=+<<-\(EOF\|'EOF'\|"EOF"\|`EOF`\)+hs=s+2 end=+^\s*EOF$+ contains=rubyExprSubst
138 syn region rubyString matchgroup=rubyStringDelimit start=+<<-\(EOS\|'EOS'\|"EOS"\|`EOS`\)+hs=s+2 end=+^\s*EOS$+ contains=rubyExprSubst
139 syn region rubyString matchgroup=rubyStringDelimit start=+<<\(\u\{3,}\|'\u\{3,}'\|"\u\{3,}"\|`\u\{3,}`\)+hs=s+2 end=+^\u\{3,}$+
140 syn region rubyString matchgroup=rubyStringDelimit start=+<<\(EOF\|'EOF'\|"EOF"\|`EOF`\)+hs=s+2 end=+^EOF$+ contains=rubyExprSubst
141 syn region rubyString matchgroup=rubyStringDelimit start=+<<\(EOS\|'EOS'\|"EOS"\|`EOS`\)+hs=s+2 end=+^EOS$+ contains=rubyExprSubst
143 " Expensive Mode: colorize *end* according to opening statement
144 if !exists("ruby_no_expensive")
145 syn region rubyFunction matchgroup=rubyDefine start="^\s*def\s" matchgroup=NONE end="[?!]\|\>" skip="\.\|\(::\)" oneline
146 syn region rubyClassOrModule matchgroup=rubyDefine start="^\s*\(class\|module\)\s" end="<\|$\|;"he=e-1 oneline
147 syn region rubyBlock start="^\s*def\s\+"rs=s matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyFunction
148 syn region rubyBlock start="^\s*\(class\|module\)\>"rs=s matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo nextgroup=rubyClassOrModule
149 " modifiers + redundant *do*
150 syn match rubyControl "\<\(if\|unless\|while\|until\|do\)\>"
151 " *do* requiring *end*
152 syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo
153 " statements without *do*
154 syn region rubyNoDoBlock matchgroup=rubyControl start="\<\(case\|begin\)\>" start="^\s*\(if\|unless\)\>" start=";\s*\(if\|unless\)\>"hs=s+1 end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo
155 " statement with optional *do*
156 syn region rubyOptDoBlock matchgroup=rubyControl start="\<for\>" start="^\s*\(while\|until\)\>" start=";\s*\(while\|until\)\>"hs=s+1 end="\<end\>" contains=ALLBUT,rubyExprSubst,rubyTodo,rubyDoBlock
158 if !exists("ruby_minlines")
159 let ruby_minlines = 50
161 exec "syn sync minlines=" . ruby_minlines
164 syn region rubyFunction matchgroup=rubyControl start="^\s*def\s" matchgroup=NONE end="[?!]\|\>" skip="\.\|\(::\)" oneline
165 syn region rubyClassOrModule matchgroup=rubyControl start="^\s*\(class\|module\)\s" end="<\|$\|;"he=e-1 oneline
166 syn keyword rubyControl case begin do for if unless while until end
170 syn keyword rubyControl then else elsif when ensure rescue
171 syn keyword rubyControl and or not in yield lambda proc loop
172 syn keyword rubyControl break redo retry next return
173 syn match rubyInclude "^\s*include\>"
174 syn keyword rubyInclude require
175 syn keyword rubyTodo TODO FIXME XXX contained
176 syn keyword rubyBoolean true false self nil
177 syn keyword rubyException raise fail catch throw
179 " Comments: and Documentation
180 syn match rubyComment "#.*" contains=rubyTodo
181 syn match rubySharpBang "#!.*"
182 syn region rubyDocumentation start="^=begin" end="^=end.*$" contains=rubyTodo
184 " Define the default highlighting.
185 " For version 5.7 and earlier: only when not done already
186 " For version 5.8 and later: only when an item doesn't have highlighting yet
187 if version >= 508 || !exists("did_ruby_syntax_inits")
189 let did_ruby_syntax_inits = 1
190 command -nargs=+ HiLink hi link <args>
192 command -nargs=+ HiLink hi def link <args>
195 HiLink rubyDefine Define
196 HiLink rubyFunction Function
197 HiLink rubyControl Statement
198 HiLink rubyInclude Include
199 HiLink rubyNumber Number
200 HiLink rubyBoolean Boolean
201 HiLink rubyException Exception
202 HiLink rubyClassOrModule Type
203 HiLink rubyIdentifier Special
204 HiLink rubySharpBang PreProc
206 HiLink rubyString String
207 HiLink rubyStringDelimit Delimiter
208 HiLink rubyExprSubst Special
210 HiLink rubyComment Comment
211 HiLink rubyDocumentation Comment
217 let b:current_syntax = "ruby"