xref: /vim-8.2.3635/runtime/syntax/ruby.vim (revision 9964e468)
1071d4279SBram Moolenaar" Vim syntax file
2071d4279SBram Moolenaar" Language:		Ruby
3c6249bb2SBram Moolenaar" Maintainer:		Doug Kearns <[email protected]>
46b730e11SBram Moolenaar" Info:			$Id$
5a5792f58SBram Moolenaar" URL:			http://vim-ruby.rubyforge.org
66b730e11SBram Moolenaar" Anon CVS:		See above site
7c6249bb2SBram Moolenaar" Release Coordinator:	Doug Kearns <[email protected]>
86b730e11SBram Moolenaar" ----------------------------------------------------------------------------
96b730e11SBram Moolenaar"
10071d4279SBram Moolenaar" Previous Maintainer:	Mirko Nasato
11071d4279SBram Moolenaar" Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN)
126b730e11SBram Moolenaar" ----------------------------------------------------------------------------
13071d4279SBram Moolenaar
14071d4279SBram Moolenaar" For version 5.x: Clear all syntax items
15071d4279SBram Moolenaar" For version 6.x: Quit when a syntax file was already loaded
16071d4279SBram Moolenaarif version < 600
17071d4279SBram Moolenaar  syntax clear
18071d4279SBram Moolenaarelseif exists("b:current_syntax")
19071d4279SBram Moolenaar  finish
20071d4279SBram Moolenaarendif
21071d4279SBram Moolenaar
226b730e11SBram Moolenaarif has("folding") && exists("ruby_fold")
236b730e11SBram Moolenaar  setlocal foldmethod=syntax
246b730e11SBram Moolenaarendif
256b730e11SBram Moolenaar
266b730e11SBram Moolenaarif exists("ruby_space_errors")
276b730e11SBram Moolenaar  if !exists("ruby_no_trail_space_error")
286b730e11SBram Moolenaar    syn match rubySpaceError display excludenl "\s\+$"
296b730e11SBram Moolenaar  endif
306b730e11SBram Moolenaar  if !exists("ruby_no_tab_space_error")
316b730e11SBram Moolenaar    syn match rubySpaceError display " \+\t"me=e-1
326b730e11SBram Moolenaar  endif
336b730e11SBram Moolenaarendif
346b730e11SBram Moolenaar
35*9964e468SBram Moolenaar" Operators
36*9964e468SBram Moolenaarif exists("ruby_operators")
37*9964e468SBram Moolenaar  syn match  rubyOperator	 "\%(\^\|\~\|\%(class\s*\)\@<!<<\|<=>\|<=\|\%(<\|\<class\s\+\u\w*\s*\)\@<!<[^<]\@=\|===\|==\|=\~\|>>\|>=\|>\||\|-\|/\|\*\*\|\*\|&\|%\|+\)"
38*9964e468SBram Moolenaar  syn match  rubyPseudoOperator  "\%(-=\|/=\|\*\*=\|\*=\|&&\|&=\|&&=\|||\||=\|||=\|%=\|+=\|!\~\|!=\)"
39*9964e468SBram Moolenaar  syn region rubyBracketOperator matchgroup=rubyOperator start="\%([_[:lower:]]\w*[?!=]\=\|}\)\@<=\[\s*" end="\s*]"
40*9964e468SBram Moolenaarendif
41*9964e468SBram Moolenaar
42071d4279SBram Moolenaar" Expression Substitution and Backslash Notation
436b730e11SBram Moolenaarsyn match rubyEscape	"\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}"							 contained display
446b730e11SBram Moolenaarsyn match rubyEscape	"\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display
45*9964e468SBram Moolenaar
46*9964e468SBram Moolenaarsyn region rubyInterpolation	      matchgroup=rubyInterpolationDelimiter start="#{" end="}" contained contains=TOP
47*9964e468SBram Moolenaarsyn match  rubyInterpolation	      "#\%(\$\|@@\=\)\w\+"    display contained  contains=rubyInterpolationDelimiter,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable,rubyPredefinedVariable
48*9964e468SBram Moolenaarsyn match  rubyInterpolationDelimiter "#\ze\%(\$\|@@\=\)\w\+" display contained
49*9964e468SBram Moolenaarsyn region rubyNoInterpolation	      start="\\#{" end="}"    contained
50*9964e468SBram Moolenaarsyn match  rubyNoInterpolation	      "\\#{"		      display contained
51*9964e468SBram Moolenaarsyn match  rubyNoInterpolation	      "\\#\%(\$\|@@\=\)\w\+"  display contained
526b730e11SBram Moolenaar
536b730e11SBram Moolenaarsyn match rubyDelimEscape	"\\[(<{\[)>}\]]" transparent display contained contains=NONE
546b730e11SBram Moolenaar
556b730e11SBram Moolenaarsyn region rubyNestedParentheses	start="("	end=")"		skip="\\\\\|\\)"	transparent contained contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape
566b730e11SBram Moolenaarsyn region rubyNestedCurlyBraces	start="{"	end="}"		skip="\\\\\|\\}"	transparent contained contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape
576b730e11SBram Moolenaarsyn region rubyNestedAngleBrackets	start="<"	end=">"		skip="\\\\\|\\>"	transparent contained contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape
586b730e11SBram Moolenaarsyn region rubyNestedSquareBrackets	start="\["	end="\]"	skip="\\\\\|\\\]"	transparent contained contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape
596b730e11SBram Moolenaar
606b730e11SBram Moolenaarsyn cluster rubyStringSpecial		contains=rubyInterpolation,rubyNoInterpolation,rubyEscape
616b730e11SBram Moolenaarsyn cluster rubyExtendedStringSpecial	contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets
62071d4279SBram Moolenaar
63071d4279SBram Moolenaar" Numbers and ASCII Codes
646b730e11SBram Moolenaarsyn match rubyASCIICode	"\w\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)"
656b730e11SBram Moolenaarsyn match rubyInteger	"\<0[xX]\x\+\%(_\x\+\)*\>"								display
666b730e11SBram Moolenaarsyn match rubyInteger	"\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)\>"						display
676b730e11SBram Moolenaarsyn match rubyInteger	"\<0[oO]\=\o\+\%(_\o\+\)*\>"								display
686b730e11SBram Moolenaarsyn match rubyInteger	"\<0[bB][01]\+\%(_[01]\+\)*\>"								display
696b730e11SBram Moolenaarsyn match rubyFloat	"\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*\>"					display
706b730e11SBram Moolenaarsyn match rubyFloat	"\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)\>"	display
71071d4279SBram Moolenaar
726b730e11SBram Moolenaar" Identifiers
736b730e11SBram Moolenaarsyn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
746b730e11SBram Moolenaarsyn match rubyBlockArgument	    "&[_[:lower:]][_[:alnum:]]"		 contains=NONE display transparent
75071d4279SBram Moolenaar
76*9964e468SBram Moolenaarsyn match  rubyConstant			"\%(\%([.@$]\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\%(\>\|::\)\@=\%(\s*(\)\@!"
776b730e11SBram Moolenaarsyn match  rubyClassVariable		"@@\h\w*" display
786b730e11SBram Moolenaarsyn match  rubyInstanceVariable		"@\h\w*"  display
796b730e11SBram Moolenaarsyn match  rubyGlobalVariable		"$\%(\h\w*\|-.\)"
806b730e11SBram Moolenaarsyn match  rubySymbol			":\@<!:\%(\^\|\~\|<<\|<=>\|<=\|<\|===\|==\|=\~\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)"
816b730e11SBram Moolenaarsyn match  rubySymbol			":\@<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)"
826b730e11SBram Moolenaarsyn match  rubySymbol			":\@<!:\%(\$\|@@\=\)\=\h\w*[?!=]\="
836b730e11SBram Moolenaarsyn region rubySymbol			start=":\@<!:\"" end="\"" skip="\\\\\|\\\""
84*9964e468SBram Moolenaarsyn region rubySymbol			start=":\@<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold
85*9964e468SBram Moolenaarif exists("ruby_operators")
86*9964e468SBram Moolenaar  syn match  rubyBlockParameter		"\%(\%(\%(\<do\>\|{\)\s*\)|\s*\)\@<=[( ,a-zA-Z0-9_*)]\+\%(\s*|\)\@=" display
87*9964e468SBram Moolenaarelse
886b730e11SBram Moolenaar  syn match  rubyBlockParameter		"\%(\%(\<do\>\|{\)\s*\)\@<=|\s*\zs[( ,a-zA-Z0-9_*)]\+\ze\s*|" display
89*9964e468SBram Moolenaarendif
90071d4279SBram Moolenaar
916b730e11SBram Moolenaarsyn match rubyPredefinedVariable #$[!$&"'*+,./0:;<=>?@\`~1-9]#
926b730e11SBram Moolenaarsyn match rubyPredefinedVariable "$_\>"											   display
936b730e11SBram Moolenaarsyn match rubyPredefinedVariable "$-[0FIKadilpvw]\>"									   display
946b730e11SBram Moolenaarsyn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>"					   display
951e015460SBram Moolenaarsyn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display
966b730e11SBram Moolenaarsyn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!"
976b730e11SBram Moolenaarsyn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\|RUBY_PLATFORM\|RUBY_RELEASE_DATE\)\>\%(\s*(\)\@!"
986b730e11SBram Moolenaarsyn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(RUBY_VERSION\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!"
99071d4279SBram Moolenaar"Obsolete Global Constants
1006b730e11SBram Moolenaar"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(PLATFORM\|RELEASE_DATE\|VERSION\)\>"
1016b730e11SBram Moolenaar"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(NotImplementError\)\>"
102071d4279SBram Moolenaar
103071d4279SBram Moolenaar" Normal Regular Expression
104*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\)\|[;\~=!|&(,[>]\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold
105*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\<\%(split\|scan\|gsub\|sub\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold
1066b730e11SBram Moolenaar
1076b730e11SBram Moolenaar" Normal String and Shell Command Output
108*9964e468SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold
109*9964e468SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="'"	end="'"  skip="\\\\\|\\'"			       fold
110*9964e468SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="`"	end="`"  skip="\\\\\|\\`"  contains=@rubyStringSpecial fold
1116b730e11SBram Moolenaar
1126b730e11SBram Moolenaar" Generalized Regular Expression
113*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)"	end="\z1[iomx]*" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
114*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{"				end="}[iomx]*"	 skip="\\\\\|\\}"   contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
115*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<"				end=">[iomx]*"	 skip="\\\\\|\\>"   contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
116*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\["				end="\][iomx]*"	 skip="\\\\\|\\\]"  contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
117*9964e468SBram Moolenaarsyn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r("				end=")[iomx]*"	 skip="\\\\\|\\)"   contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold
1186b730e11SBram Moolenaar
1196b730e11SBram Moolenaar" Generalized Single Quoted String, Symbol and Array of Strings
1206b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
1216b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]{"				    end="}"   skip="\\\\\|\\}"	 fold	contains=rubyNestedCurlyBraces,rubyDelimEscape
1226b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]<"				    end=">"   skip="\\\\\|\\>"	 fold	contains=rubyNestedAngleBrackets,rubyDelimEscape
1236b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\["				    end="\]"  skip="\\\\\|\\\]"	 fold	contains=rubyNestedSquareBrackets,rubyDelimEscape
1246b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]("				    end=")"   skip="\\\\\|\\)"	 fold	contains=rubyNestedParentheses,rubyDelimEscape
1256b730e11SBram Moolenaar
1266b730e11SBram Moolenaar" Generalized Double Quoted String and Array of Strings and Shell Command Output
1276b730e11SBram Moolenaar" Note: %= is not matched here as the beginning of a double quoted string
1286b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)"	    end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
1296b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
1306b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={"				    end="}"   skip="\\\\\|\\}"	 contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
1316b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<"				    end=">"   skip="\\\\\|\\>"	 contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
1326b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\["				    end="\]"  skip="\\\\\|\\\]"	 contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
1336b730e11SBram Moolenaarsyn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=("				    end=")"   skip="\\\\\|\\)"	 contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold
134071d4279SBram Moolenaar
135071d4279SBram Moolenaar" Here Document
1366b730e11SBram Moolenaarsyn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs\%(\h\w*\)+   end=+$+ oneline contains=TOP
1376b730e11SBram Moolenaarsyn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=TOP
1386b730e11SBram Moolenaarsyn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs'\%([^']*\)'+ end=+$+ oneline contains=TOP
1396b730e11SBram Moolenaarsyn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=TOP
140071d4279SBram Moolenaar
141*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<\z(\h\w*\)\ze+hs=s+2    matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
142*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<"\z([^"]*\)"\ze+hs=s+2  matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
143*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<'\z([^']*\)'\ze+hs=s+2  matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart		      fold keepend
144*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<`\z([^`]*\)`\ze+hs=s+2  matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
1456b730e11SBram Moolenaar
146*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\z(\h\w*\)\ze+hs=s+3    matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
147*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-"\z([^"]*\)"\ze+hs=s+3  matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
148*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-'\z([^']*\)'\ze+hs=s+3  matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart		     fold keepend
149*9964e468SBram Moolenaarsyn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-`\z([^`]*\)`\ze+hs=s+3  matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend
1506b730e11SBram Moolenaar
1516b730e11SBram Moolenaarif exists('main_syntax') && main_syntax == 'eruby'
152d5cdbeb8SBram Moolenaar  let b:ruby_no_expensive = 1
1536b730e11SBram Moolenaarend
154071d4279SBram Moolenaar
155*9964e468SBram Moolenaarsyn match  rubyAliasDeclaration    "[^[:space:];#.()]\+"  contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable nextgroup=rubyAliasDeclaration2 skipwhite
156*9964e468SBram Moolenaarsyn match  rubyAliasDeclaration2   "[^[:space:];#.()]\+"  contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable
157*9964e468SBram Moolenaarsyn match  rubyMethodDeclaration   "[^[:space:];#(]\+"	  contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
158*9964e468SBram Moolenaarsyn match  rubyClassDeclaration    "[^[:space:];#<]\+"	  contained contains=rubyConstant
159*9964e468SBram Moolenaarsyn match  rubyModuleDeclaration   "[^[:space:];#]\+"	  contained contains=rubyConstant
160*9964e468SBram Moolenaarsyn match  rubyFunction "\<[_[:alpha:]][_[:alnum:]]*[?!=]\=[[:alnum:].:?!=]\@!" contained containedin=rubyMethodDeclaration
161*9964e468SBram Moolenaarsyn match  rubyFunction "\%(\s\|^\)\@<=[_[:alpha:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2
162*9964e468SBram Moolenaarsyn match  rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|==\|=\~\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration
163071d4279SBram Moolenaar" Expensive Mode - colorize *end* according to opening statement
164d5cdbeb8SBram Moolenaarif !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
165*9964e468SBram Moolenaar  syn match  rubyDefine "\<alias\>"		nextgroup=rubyAliasDeclaration	skipwhite skipnl
166*9964e468SBram Moolenaar  syn match  rubyDefine "\<def\>"		nextgroup=rubyMethodDeclaration skipwhite skipnl
167*9964e468SBram Moolenaar  syn match  rubyClass	"\<class\>"		nextgroup=rubyClassDeclaration	skipwhite skipnl
168*9964e468SBram Moolenaar  syn match  rubyModule "\<module\>"		nextgroup=rubyModuleDeclaration skipwhite skipnl
169*9964e468SBram Moolenaar  syn region rubyBlock start="\<def\>"		matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=TOP fold
170*9964e468SBram Moolenaar  syn region rubyBlock start="\<class\>"	matchgroup=rubyClass  end="\<end\>" contains=TOP fold
171*9964e468SBram Moolenaar  syn region rubyBlock start="\<module\>"	matchgroup=rubyModule end="\<end\>" contains=TOP fold
172071d4279SBram Moolenaar
1736b730e11SBram Moolenaar  " modifiers
174*9964e468SBram Moolenaar  syn match  rubyConditional "\<\%(if\|unless\)\>"   display
175*9964e468SBram Moolenaar  syn match  rubyRepeat	     "\<\%(while\|until\)\>" display
176071d4279SBram Moolenaar
177071d4279SBram Moolenaar  " *do* requiring *end*
178*9964e468SBram Moolenaar  syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=TOP fold
179071d4279SBram Moolenaar
180071d4279SBram Moolenaar  " *{* requiring *}*
181*9964e468SBram Moolenaar  syn region rubyCurlyBlock start="{" end="}" contains=TOP fold
182071d4279SBram Moolenaar
183071d4279SBram Moolenaar  " statements without *do*
184*9964e468SBram Moolenaar  syn region rubyNoDoBlock	  matchgroup=rubyControl     start="\<begin\>" end="\<end\>" contains=TOP fold
185*9964e468SBram Moolenaar  syn region rubyCaseBlock	  matchgroup=rubyConditional start="\<case\>"  end="\<end\>" contains=TOP fold
186*9964e468SBram Moolenaar  syn region rubyConditionalBlock matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\%(if\|unless\)\>" end="\<end\>" contains=TOP fold
187*9964e468SBram Moolenaar  syn keyword rubyConditional then else when  contained containedin=rubyCaseBlock
188*9964e468SBram Moolenaar  syn keyword rubyConditional then else elsif contained containedin=rubyConditionalBlock
189071d4279SBram Moolenaar
190071d4279SBram Moolenaar  " statement with optional *do*
191*9964e468SBram Moolenaar  syn region rubyOptDoLine matchgroup=rubyRepeat start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=TOP
192*9964e468SBram Moolenaar  syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=TOP nextgroup=rubyOptDoLine fold
193071d4279SBram Moolenaar
194071d4279SBram Moolenaar  if !exists("ruby_minlines")
195071d4279SBram Moolenaar    let ruby_minlines = 50
196071d4279SBram Moolenaar  endif
197071d4279SBram Moolenaar  exec "syn sync minlines=" . ruby_minlines
198071d4279SBram Moolenaar
1996b730e11SBram Moolenaarelse
200*9964e468SBram Moolenaar  syn match   rubyControl "\<def\>"	nextgroup=rubyMethodDeclaration skipwhite skipnl
201*9964e468SBram Moolenaar  syn match   rubyControl "\<class\>"	nextgroup=rubyClassDeclaration	skipwhite skipnl
202*9964e468SBram Moolenaar  syn match   rubyControl "\<module\>"	nextgroup=rubyModuleDeclaration skipwhite skipnl
203*9964e468SBram Moolenaar  syn keyword rubyControl case begin do for if unless while until else elsif then when end
204*9964e468SBram Moolenaar  syn keyword rubyKeyword alias
2056b730e11SBram Moolenaarendif
206071d4279SBram Moolenaar
207071d4279SBram Moolenaar" Keywords
2086b730e11SBram Moolenaar" Note: the following keywords have already been defined:
2096b730e11SBram Moolenaar" begin case class def do end for if module unless until while
210*9964e468SBram Moolenaarsyn keyword rubyControl		and break ensure in next not or redo rescue retry return
2116b730e11SBram Moolenaarsyn match   rubyOperator	"\<defined?" display
212*9964e468SBram Moolenaarsyn keyword rubyKeyword		super undef yield
2136b730e11SBram Moolenaarsyn keyword rubyBoolean		true false
2146b730e11SBram Moolenaarsyn keyword rubyPseudoVariable	nil self __FILE__ __LINE__
215071d4279SBram Moolenaarsyn keyword rubyBeginEnd	BEGIN END
216071d4279SBram Moolenaar
2176b730e11SBram Moolenaar" Special Methods
2186b730e11SBram Moolenaarif !exists("ruby_no_special_methods")
2196b730e11SBram Moolenaar  syn keyword rubyAccess    public protected private
2206b730e11SBram Moolenaar  syn keyword rubyAttribute attr attr_accessor attr_reader attr_writer
2211e015460SBram Moolenaar  syn match   rubyControl   "\<\%(exit!\|\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>\)"
2226b730e11SBram Moolenaar  syn keyword rubyEval	    eval class_eval instance_eval module_eval
2236b730e11SBram Moolenaar  syn keyword rubyException raise fail catch throw
2246b730e11SBram Moolenaar  syn keyword rubyInclude   autoload extend include load require
2256b730e11SBram Moolenaar  syn keyword rubyKeyword   callcc caller lambda proc
226071d4279SBram Moolenaarendif
227071d4279SBram Moolenaar
2286b730e11SBram Moolenaar" Comments and Documentation
2296b730e11SBram Moolenaarsyn match   rubySharpBang     "\%^#!.*" display
2306b730e11SBram Moolenaarsyn keyword rubyTodo	      FIXME NOTE TODO XXX contained
2316b730e11SBram Moolenaarsyn match   rubyComment       "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell
232*9964e468SBram Moolenaarif !exists("ruby_no_comment_fold")
233*9964e468SBram Moolenaar  syn region rubyMultilineComment start="\%(\%(^\s*#.*\n\)\@<!\%(^\s*#.*\n\)\)\%(\(^\s*#.*\n\)\{1,}\)\@=" end="\%(^\s*#.*\n\)\@<=\%(^\s*#.*\n\)\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend
234*9964e468SBram Moolenaar  syn region rubyDocumentation	  start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell fold
235*9964e468SBram Moolenaarelse
236*9964e468SBram Moolenaar  syn region rubyDocumentation	  start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell
237*9964e468SBram Moolenaarendif
2386b730e11SBram Moolenaar
2396b730e11SBram Moolenaar" Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver
2406b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(alias\|and\|begin\|break\|case\|class\|def\|defined\|do\|else\)\>"			transparent contains=NONE
2416b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(elsif\|end\|ensure\|false\|for\|if\|in\|module\|next\|nil\)\>"			transparent contains=NONE
2426b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(not\|or\|redo\|rescue\|retry\|return\|self\|super\|then\|true\)\>"			transparent contains=NONE
2436b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(undef\|unless\|until\|when\|while\|yield\|BEGIN\|END\|__FILE__\|__LINE__\)\>"	transparent contains=NONE
2446b730e11SBram Moolenaar
2456b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(abort\|at_exit\|attr\|attr_accessor\|attr_reader\)\>"	transparent contains=NONE
2466b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(attr_writer\|autoload\|callcc\|catch\|caller\)\>"		transparent contains=NONE
2476b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(eval\|class_eval\|instance_eval\|module_eval\|exit\)\>"	transparent contains=NONE
2486b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(extend\|fail\|fork\|include\|lambda\)\>"			transparent contains=NONE
2496b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(load\|loop\|private\|proc\|protected\)\>"			transparent contains=NONE
2506b730e11SBram Moolenaarsyn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(public\|require\|raise\|throw\|trap\)\>"			transparent contains=NONE
251071d4279SBram Moolenaar
252071d4279SBram Moolenaar" __END__ Directive
2536b730e11SBram Moolenaarsyn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold
254071d4279SBram Moolenaar
255071d4279SBram Moolenaar" Define the default highlighting.
256071d4279SBram Moolenaar" For version 5.7 and earlier: only when not done already
257071d4279SBram Moolenaar" For version 5.8 and later: only when an item doesn't have highlighting yet
258071d4279SBram Moolenaarif version >= 508 || !exists("did_ruby_syntax_inits")
259071d4279SBram Moolenaar  if version < 508
260071d4279SBram Moolenaar    let did_ruby_syntax_inits = 1
261071d4279SBram Moolenaar    command -nargs=+ HiLink hi link <args>
262071d4279SBram Moolenaar  else
263071d4279SBram Moolenaar    command -nargs=+ HiLink hi def link <args>
264071d4279SBram Moolenaar  endif
265071d4279SBram Moolenaar
266*9964e468SBram Moolenaar  HiLink rubyClass			rubyDefine
267*9964e468SBram Moolenaar  HiLink rubyModule			rubyDefine
268071d4279SBram Moolenaar  HiLink rubyDefine			Define
269071d4279SBram Moolenaar  HiLink rubyFunction			Function
270*9964e468SBram Moolenaar  HiLink rubyConditional		Conditional
271*9964e468SBram Moolenaar  HiLink rubyRepeat			Repeat
272071d4279SBram Moolenaar  HiLink rubyControl			Statement
273071d4279SBram Moolenaar  HiLink rubyInclude			Include
2746b730e11SBram Moolenaar  HiLink rubyInteger			Number
275*9964e468SBram Moolenaar  HiLink rubyASCIICode			Character
2766b730e11SBram Moolenaar  HiLink rubyFloat			Float
277*9964e468SBram Moolenaar  HiLink rubyBoolean			Boolean
278071d4279SBram Moolenaar  HiLink rubyException			Exception
2796b730e11SBram Moolenaar  if !exists("ruby_no_identifiers")
280071d4279SBram Moolenaar    HiLink rubyIdentifier		Identifier
2816b730e11SBram Moolenaar  else
2826b730e11SBram Moolenaar    HiLink rubyIdentifier		NONE
2836b730e11SBram Moolenaar  endif
284071d4279SBram Moolenaar  HiLink rubyClassVariable		rubyIdentifier
285*9964e468SBram Moolenaar  HiLink rubyConstant			Type
286071d4279SBram Moolenaar  HiLink rubyGlobalVariable		rubyIdentifier
2876b730e11SBram Moolenaar  HiLink rubyBlockParameter		rubyIdentifier
288071d4279SBram Moolenaar  HiLink rubyInstanceVariable		rubyIdentifier
289071d4279SBram Moolenaar  HiLink rubyPredefinedIdentifier	rubyIdentifier
290071d4279SBram Moolenaar  HiLink rubyPredefinedConstant		rubyPredefinedIdentifier
291071d4279SBram Moolenaar  HiLink rubyPredefinedVariable		rubyPredefinedIdentifier
292*9964e468SBram Moolenaar  HiLink rubySymbol			Constant
293071d4279SBram Moolenaar  HiLink rubyKeyword			Keyword
2946b730e11SBram Moolenaar  HiLink rubyOperator			Operator
295*9964e468SBram Moolenaar  HiLink rubyPseudoOperator		rubyOperator
296071d4279SBram Moolenaar  HiLink rubyBeginEnd			Statement
2976b730e11SBram Moolenaar  HiLink rubyAccess			Statement
2986b730e11SBram Moolenaar  HiLink rubyAttribute			Statement
2996b730e11SBram Moolenaar  HiLink rubyEval			Statement
3006b730e11SBram Moolenaar  HiLink rubyPseudoVariable		Constant
301071d4279SBram Moolenaar
302071d4279SBram Moolenaar  HiLink rubyComment			Comment
303071d4279SBram Moolenaar  HiLink rubyData			Comment
304071d4279SBram Moolenaar  HiLink rubyDataDirective		Delimiter
3056b730e11SBram Moolenaar  HiLink rubyDocumentation		Comment
3066b730e11SBram Moolenaar  HiLink rubyEscape			Special
307*9964e468SBram Moolenaar  HiLink rubyInterpolationDelimiter	Delimiter
3086b730e11SBram Moolenaar  HiLink rubyNoInterpolation		rubyString
3096b730e11SBram Moolenaar  HiLink rubySharpBang			PreProc
310*9964e468SBram Moolenaar  HiLink rubyRegexpDelimiter		rubyStringDelimiter
3116b730e11SBram Moolenaar  HiLink rubyStringDelimiter		Delimiter
312*9964e468SBram Moolenaar  HiLink rubyRegexp			rubyString
3136b730e11SBram Moolenaar  HiLink rubyString			String
3146b730e11SBram Moolenaar  HiLink rubyTodo			Todo
3156b730e11SBram Moolenaar
3166b730e11SBram Moolenaar  HiLink rubyError			Error
3176b730e11SBram Moolenaar  HiLink rubySpaceError			rubyError
318071d4279SBram Moolenaar
319071d4279SBram Moolenaar  delcommand HiLink
320071d4279SBram Moolenaarendif
321071d4279SBram Moolenaar
322071d4279SBram Moolenaarlet b:current_syntax = "ruby"
323071d4279SBram Moolenaar
324*9964e468SBram Moolenaar" vim: nowrap sw=2 sts=2 ts=8 noet ff=unix:
325