Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
Bram Moolenaar | c6249bb | 2006-04-15 20:25:09 +0000 | [diff] [blame] | 2 | " 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 Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 8 | " ---------------------------------------------------------------------------- |
| 9 | " |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | " Previous Maintainer: Mirko Nasato |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 11 | " Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN) |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 12 | " ---------------------------------------------------------------------------- |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 13 | |
| 14 | " For version 5.x: Clear all syntax items |
| 15 | " For version 6.x: Quit when a syntax file was already loaded |
| 16 | if version < 600 |
| 17 | syntax clear |
| 18 | elseif exists("b:current_syntax") |
| 19 | finish |
| 20 | endif |
| 21 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 22 | if has("folding") && exists("ruby_fold") |
| 23 | setlocal foldmethod=syntax |
| 24 | endif |
| 25 | |
| 26 | if exists("ruby_space_errors") |
| 27 | if !exists("ruby_no_trail_space_error") |
| 28 | syn match rubySpaceError display excludenl "\s\+$" |
| 29 | endif |
| 30 | if !exists("ruby_no_tab_space_error") |
| 31 | syn match rubySpaceError display " \+\t"me=e-1 |
| 32 | endif |
| 33 | endif |
| 34 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 35 | " Operators |
| 36 | if exists("ruby_operators") |
| 37 | syn match rubyOperator "\%(\^\|\~\|\%(class\s*\)\@<!<<\|<=>\|<=\|\%(<\|\<class\s\+\u\w*\s*\)\@<!<[^<]\@=\|===\|==\|=\~\|>>\|>=\|>\||\|-\|/\|\*\*\|\*\|&\|%\|+\)" |
| 38 | syn match rubyPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&\|&=\|&&=\|||\||=\|||=\|%=\|+=\|!\~\|!=\)" |
| 39 | syn region rubyBracketOperator matchgroup=rubyOperator start="\%([_[:lower:]]\w*[?!=]\=\|}\)\@<=\[\s*" end="\s*]" |
| 40 | endif |
| 41 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | " Expression Substitution and Backslash Notation |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 43 | syn match rubyEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display |
| 44 | syn match rubyEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display |
| 45 | |
| 46 | syn region rubyInterpolation matchgroup=rubyInterpolationDelimiter start="#{" end="}" contained contains=TOP |
| 47 | syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" display contained contains=rubyInterpolationDelimiter,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable,rubyPredefinedVariable |
| 48 | syn match rubyInterpolationDelimiter "#\ze\%(\$\|@@\=\)\w\+" display contained |
| 49 | syn region rubyNoInterpolation start="\\#{" end="}" contained |
| 50 | syn match rubyNoInterpolation "\\#{" display contained |
| 51 | syn match rubyNoInterpolation "\\#\%(\$\|@@\=\)\w\+" display contained |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 52 | |
| 53 | syn match rubyDelimEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE |
| 54 | |
| 55 | syn region rubyNestedParentheses start="(" end=")" skip="\\\\\|\\)" transparent contained contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape |
| 56 | syn region rubyNestedCurlyBraces start="{" end="}" skip="\\\\\|\\}" transparent contained contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape |
| 57 | syn region rubyNestedAngleBrackets start="<" end=">" skip="\\\\\|\\>" transparent contained contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape |
| 58 | syn region rubyNestedSquareBrackets start="\[" end="\]" skip="\\\\\|\\\]" transparent contained contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape |
| 59 | |
| 60 | syn cluster rubyStringSpecial contains=rubyInterpolation,rubyNoInterpolation,rubyEscape |
| 61 | syn cluster rubyExtendedStringSpecial contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | |
| 63 | " Numbers and ASCII Codes |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 64 | syn match rubyASCIICode "\w\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)" |
| 65 | syn match rubyInteger "\<0[xX]\x\+\%(_\x\+\)*\>" display |
| 66 | syn match rubyInteger "\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)\>" display |
| 67 | syn match rubyInteger "\<0[oO]\=\o\+\%(_\o\+\)*\>" display |
| 68 | syn match rubyInteger "\<0[bB][01]\+\%(_[01]\+\)*\>" display |
| 69 | syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*\>" display |
| 70 | syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)\>" display |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 71 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 72 | " Identifiers |
| 73 | syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent |
| 74 | syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 75 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 76 | syn match rubyConstant "\%(\%([.@$]\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\%(\>\|::\)\@=\%(\s*(\)\@!" |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 77 | syn match rubyClassVariable "@@\h\w*" display |
| 78 | syn match rubyInstanceVariable "@\h\w*" display |
| 79 | syn match rubyGlobalVariable "$\%(\h\w*\|-.\)" |
| 80 | syn match rubySymbol ":\@<!:\%(\^\|\~\|<<\|<=>\|<=\|<\|===\|==\|=\~\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)" |
| 81 | syn match rubySymbol ":\@<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)" |
| 82 | syn match rubySymbol ":\@<!:\%(\$\|@@\=\)\=\h\w*[?!=]\=" |
| 83 | syn region rubySymbol start=":\@<!:\"" end="\"" skip="\\\\\|\\\"" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 84 | syn region rubySymbol start=":\@<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold |
| 85 | if exists("ruby_operators") |
| 86 | syn match rubyBlockParameter "\%(\%(\%(\<do\>\|{\)\s*\)|\s*\)\@<=[( ,a-zA-Z0-9_*)]\+\%(\s*|\)\@=" display |
| 87 | else |
| 88 | syn match rubyBlockParameter "\%(\%(\<do\>\|{\)\s*\)\@<=|\s*\zs[( ,a-zA-Z0-9_*)]\+\ze\s*|" display |
| 89 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 90 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 91 | syn match rubyPredefinedVariable #$[!$&"'*+,./0:;<=>?@\`~1-9]# |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 92 | syn match rubyPredefinedVariable "$_\>" display |
| 93 | syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display |
| 94 | syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display |
| 95 | syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 96 | syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!" |
| 97 | syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\|RUBY_PLATFORM\|RUBY_RELEASE_DATE\)\>\%(\s*(\)\@!" |
| 98 | syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(RUBY_VERSION\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!" |
| 99 | "Obsolete Global Constants |
| 100 | "syn match rubyPredefinedConstant "\%(::\)\=\zs\%(PLATFORM\|RELEASE_DATE\|VERSION\)\>" |
| 101 | "syn match rubyPredefinedConstant "\%(::\)\=\zs\%(NotImplementError\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 102 | |
| 103 | " Normal Regular Expression |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 104 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\)\|[;\~=!|&(,[>]\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold |
| 105 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\<\%(split\|scan\|gsub\|sub\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial fold |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 106 | |
| 107 | " Normal String and Shell Command Output |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 108 | syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold |
| 109 | syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" fold |
| 110 | syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 111 | |
| 112 | " Generalized Regular Expression |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 113 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomx]*" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold |
| 114 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomx]*" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold |
| 115 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomx]*" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold |
| 116 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomx]*" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold |
| 117 | syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomx]*" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 118 | |
| 119 | " Generalized Single Quoted String, Symbol and Array of Strings |
| 120 | syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold |
| 121 | syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape |
| 122 | syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape |
| 123 | syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape |
| 124 | syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape |
| 125 | |
| 126 | " Generalized Double Quoted String and Array of Strings and Shell Command Output |
| 127 | " Note: %= is not matched here as the beginning of a double quoted string |
| 128 | syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold |
| 129 | syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold |
| 130 | syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold |
| 131 | syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold |
| 132 | syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold |
| 133 | syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | |
| 135 | " Here Document |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 136 | syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs\%(\h\w*\)+ end=+$+ oneline contains=TOP |
| 137 | syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=TOP |
| 138 | syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs'\%([^']*\)'+ end=+$+ oneline contains=TOP |
| 139 | syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=TOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 140 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 141 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<\z(\h\w*\)\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend |
| 142 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<"\z([^"]*\)"\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend |
| 143 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<'\z([^']*\)'\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart fold keepend |
| 144 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<`\z([^`]*\)`\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 145 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 146 | syn 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 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-"\z([^"]*\)"\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend |
| 148 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-'\z([^']*\)'\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart fold keepend |
| 149 | syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-`\z([^`]*\)`\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial fold keepend |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 150 | |
| 151 | if exists('main_syntax') && main_syntax == 'eruby' |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 152 | let b:ruby_no_expensive = 1 |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 153 | end |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 154 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 155 | syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable nextgroup=rubyAliasDeclaration2 skipwhite |
| 156 | syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained contains=rubySymbol,rubyGlobalVariable,rubyPredefinedVariable |
| 157 | syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable |
| 158 | syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyConstant |
| 159 | syn match rubyModuleDeclaration "[^[:space:];#]\+" contained contains=rubyConstant |
| 160 | syn match rubyFunction "\<[_[:alpha:]][_[:alnum:]]*[?!=]\=[[:alnum:].:?!=]\@!" contained containedin=rubyMethodDeclaration |
| 161 | syn match rubyFunction "\%(\s\|^\)\@<=[_[:alpha:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2 |
| 162 | syn match rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|==\|=\~\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 163 | " Expensive Mode - colorize *end* according to opening statement |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 164 | if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 165 | syn match rubyDefine "\<alias\>" nextgroup=rubyAliasDeclaration skipwhite skipnl |
| 166 | syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl |
| 167 | syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl |
| 168 | syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl |
| 169 | syn region rubyBlock start="\<def\>" matchgroup=rubyDefine end="\%(\<def\_s\+\)\@<!\<end\>" contains=TOP fold |
| 170 | syn region rubyBlock start="\<class\>" matchgroup=rubyClass end="\<end\>" contains=TOP fold |
| 171 | syn region rubyBlock start="\<module\>" matchgroup=rubyModule end="\<end\>" contains=TOP fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 173 | " modifiers |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 174 | syn match rubyConditional "\<\%(if\|unless\)\>" display |
| 175 | syn match rubyRepeat "\<\%(while\|until\)\>" display |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | |
| 177 | " *do* requiring *end* |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 178 | syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=TOP fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 179 | |
| 180 | " *{* requiring *}* |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 181 | syn region rubyCurlyBlock start="{" end="}" contains=TOP fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 182 | |
| 183 | " statements without *do* |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 184 | syn region rubyNoDoBlock matchgroup=rubyControl start="\<begin\>" end="\<end\>" contains=TOP fold |
| 185 | syn region rubyCaseBlock matchgroup=rubyConditional start="\<case\>" end="\<end\>" contains=TOP fold |
| 186 | syn region rubyConditionalBlock matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\%(if\|unless\)\>" end="\<end\>" contains=TOP fold |
| 187 | syn keyword rubyConditional then else when contained containedin=rubyCaseBlock |
| 188 | syn keyword rubyConditional then else elsif contained containedin=rubyConditionalBlock |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 189 | |
| 190 | " statement with optional *do* |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 191 | syn region rubyOptDoLine matchgroup=rubyRepeat start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=TOP |
| 192 | syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat end="\<end\>" contains=TOP nextgroup=rubyOptDoLine fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 193 | |
| 194 | if !exists("ruby_minlines") |
| 195 | let ruby_minlines = 50 |
| 196 | endif |
| 197 | exec "syn sync minlines=" . ruby_minlines |
| 198 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 199 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 200 | syn match rubyControl "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl |
| 201 | syn match rubyControl "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl |
| 202 | syn match rubyControl "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl |
| 203 | syn keyword rubyControl case begin do for if unless while until else elsif then when end |
| 204 | syn keyword rubyKeyword alias |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 205 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 206 | |
| 207 | " Keywords |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 208 | " Note: the following keywords have already been defined: |
| 209 | " begin case class def do end for if module unless until while |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 210 | syn keyword rubyControl and break ensure in next not or redo rescue retry return |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 211 | syn match rubyOperator "\<defined?" display |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 212 | syn keyword rubyKeyword super undef yield |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 213 | syn keyword rubyBoolean true false |
| 214 | syn keyword rubyPseudoVariable nil self __FILE__ __LINE__ |
| 215 | syn keyword rubyBeginEnd BEGIN END |
| 216 | |
| 217 | " Special Methods |
| 218 | if !exists("ruby_no_special_methods") |
| 219 | syn keyword rubyAccess public protected private |
| 220 | syn keyword rubyAttribute attr attr_accessor attr_reader attr_writer |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 221 | syn match rubyControl "\<\%(exit!\|\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>\)" |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 222 | syn keyword rubyEval eval class_eval instance_eval module_eval |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 223 | syn keyword rubyException raise fail catch throw |
| 224 | syn keyword rubyInclude autoload extend include load require |
| 225 | syn keyword rubyKeyword callcc caller lambda proc |
| 226 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 227 | |
| 228 | " Comments and Documentation |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 229 | syn match rubySharpBang "\%^#!.*" display |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 230 | syn keyword rubyTodo FIXME NOTE TODO XXX contained |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 231 | syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 232 | if !exists("ruby_no_comment_fold") |
| 233 | syn region rubyMultilineComment start="\%(\%(^\s*#.*\n\)\@<!\%(^\s*#.*\n\)\)\%(\(^\s*#.*\n\)\{1,}\)\@=" end="\%(^\s*#.*\n\)\@<=\%(^\s*#.*\n\)\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend |
| 234 | syn region rubyDocumentation start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell fold |
| 235 | else |
| 236 | syn region rubyDocumentation start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell |
| 237 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 239 | " Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver |
| 240 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(alias\|and\|begin\|break\|case\|class\|def\|defined\|do\|else\)\>" transparent contains=NONE |
| 241 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(elsif\|end\|ensure\|false\|for\|if\|in\|module\|next\|nil\)\>" transparent contains=NONE |
| 242 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(not\|or\|redo\|rescue\|retry\|return\|self\|super\|then\|true\)\>" transparent contains=NONE |
| 243 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(undef\|unless\|until\|when\|while\|yield\|BEGIN\|END\|__FILE__\|__LINE__\)\>" transparent contains=NONE |
| 244 | |
| 245 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(abort\|at_exit\|attr\|attr_accessor\|attr_reader\)\>" transparent contains=NONE |
| 246 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(attr_writer\|autoload\|callcc\|catch\|caller\)\>" transparent contains=NONE |
| 247 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(eval\|class_eval\|instance_eval\|module_eval\|exit\)\>" transparent contains=NONE |
| 248 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(extend\|fail\|fork\|include\|lambda\)\>" transparent contains=NONE |
| 249 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(load\|loop\|private\|proc\|protected\)\>" transparent contains=NONE |
| 250 | syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(public\|require\|raise\|throw\|trap\)\>" transparent contains=NONE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 251 | |
| 252 | " __END__ Directive |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 253 | syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 254 | |
| 255 | " Define the default highlighting. |
| 256 | " For version 5.7 and earlier: only when not done already |
| 257 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 258 | if version >= 508 || !exists("did_ruby_syntax_inits") |
| 259 | if version < 508 |
| 260 | let did_ruby_syntax_inits = 1 |
| 261 | command -nargs=+ HiLink hi link <args> |
| 262 | else |
| 263 | command -nargs=+ HiLink hi def link <args> |
| 264 | endif |
| 265 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 266 | HiLink rubyClass rubyDefine |
| 267 | HiLink rubyModule rubyDefine |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 268 | HiLink rubyDefine Define |
| 269 | HiLink rubyFunction Function |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 270 | HiLink rubyConditional Conditional |
| 271 | HiLink rubyRepeat Repeat |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 272 | HiLink rubyControl Statement |
| 273 | HiLink rubyInclude Include |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 274 | HiLink rubyInteger Number |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 275 | HiLink rubyASCIICode Character |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 276 | HiLink rubyFloat Float |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 277 | HiLink rubyBoolean Boolean |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 278 | HiLink rubyException Exception |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 279 | if !exists("ruby_no_identifiers") |
| 280 | HiLink rubyIdentifier Identifier |
| 281 | else |
| 282 | HiLink rubyIdentifier NONE |
| 283 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 284 | HiLink rubyClassVariable rubyIdentifier |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 285 | HiLink rubyConstant Type |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 286 | HiLink rubyGlobalVariable rubyIdentifier |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 287 | HiLink rubyBlockParameter rubyIdentifier |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 288 | HiLink rubyInstanceVariable rubyIdentifier |
| 289 | HiLink rubyPredefinedIdentifier rubyIdentifier |
| 290 | HiLink rubyPredefinedConstant rubyPredefinedIdentifier |
| 291 | HiLink rubyPredefinedVariable rubyPredefinedIdentifier |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 292 | HiLink rubySymbol Constant |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 293 | HiLink rubyKeyword Keyword |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 294 | HiLink rubyOperator Operator |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 295 | HiLink rubyPseudoOperator rubyOperator |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 296 | HiLink rubyBeginEnd Statement |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 297 | HiLink rubyAccess Statement |
| 298 | HiLink rubyAttribute Statement |
| 299 | HiLink rubyEval Statement |
| 300 | HiLink rubyPseudoVariable Constant |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 301 | |
| 302 | HiLink rubyComment Comment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 303 | HiLink rubyData Comment |
| 304 | HiLink rubyDataDirective Delimiter |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 305 | HiLink rubyDocumentation Comment |
| 306 | HiLink rubyEscape Special |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 307 | HiLink rubyInterpolationDelimiter Delimiter |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 308 | HiLink rubyNoInterpolation rubyString |
| 309 | HiLink rubySharpBang PreProc |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 310 | HiLink rubyRegexpDelimiter rubyStringDelimiter |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 311 | HiLink rubyStringDelimiter Delimiter |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 312 | HiLink rubyRegexp rubyString |
Bram Moolenaar | 6b730e1 | 2005-09-16 21:47:57 +0000 | [diff] [blame] | 313 | HiLink rubyString String |
| 314 | HiLink rubyTodo Todo |
| 315 | |
| 316 | HiLink rubyError Error |
| 317 | HiLink rubySpaceError rubyError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 318 | |
| 319 | delcommand HiLink |
| 320 | endif |
| 321 | |
| 322 | let b:current_syntax = "ruby" |
| 323 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 324 | " vim: nowrap sw=2 sts=2 ts=8 noet ff=unix: |