Skip to content

Commit cc7a38a

Browse files
committed
Add highlighting support for some missing regex features
Adds basic support for Unicode properties; it doesn't test the property names. Also adds character class set intersection and \K, \R and \X.
1 parent ea7f998 commit cc7a38a

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

syntax/ruby.vim

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,29 @@ syn region rubyNestedAngleBrackets start="<" skip="\\\\\|\\>" matchgroup=ruby
107107
syn region rubyNestedSquareBrackets start="\[" skip="\\\\\|\\\]" matchgroup=rubyString end="\]" transparent contained
108108

109109
" Regular Expression Metacharacters {{{1
110-
" These are mostly Oniguruma ready
111-
syn region rubyRegexpComment matchgroup=rubyRegexpSpecial start="(?#" skip="\\\\\|\\)" end=")" contained
112-
syn region rubyRegexpParens matchgroup=rubyRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\\\\|\\)" end=")" contained transparent contains=@rubyRegexpSpecial
113-
syn region rubyRegexpBrackets matchgroup=rubyRegexpCharClass start="\[\^\=" skip="\\\\\|\\\]" end="\]" contained transparent contains=rubyStringEscape,rubyRegexpEscape,rubyRegexpCharClass oneline
114-
syn match rubyRegexpCharClass "\\[DdHhSsWw]" contained display
115-
syn match rubyRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained
116-
syn match rubyRegexpEscape "\\[].*?+^$|\\/(){}[]" contained
117-
syn match rubyRegexpQuantifier "[*?+][?+]\=" contained display
118-
syn match rubyRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display
119-
syn match rubyRegexpAnchor "[$^]\|\\[ABbGZz]" contained display
120-
syn match rubyRegexpDot "\." contained display
121-
syn match rubyRegexpSpecial "|" contained display
122-
syn match rubyRegexpSpecial "\\[1-9]\d\=\d\@!" contained display
123-
syn match rubyRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display
124-
syn match rubyRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display
125-
syn match rubyRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display
126-
syn match rubyRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display
110+
syn region rubyRegexpComment matchgroup=rubyRegexpSpecial start="(?#" skip="\\\\\|\\)" end=")" contained
111+
syn region rubyRegexpParens matchgroup=rubyRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\\\\|\\)" end=")" contained transparent contains=@rubyRegexpSpecial
112+
syn region rubyRegexpBrackets matchgroup=rubyRegexpCharClass start="\[\^\=" skip="\\\\\|\\\]" end="\]" contained transparent contains=rubyRegexpBrackets,rubyStringEscape,rubyRegexpEscape,rubyRegexpCharClass,rubyRegexpIntersection oneline
113+
syn match rubyRegexpCharClass "\\[DdHhRSsWw]" contained display
114+
syn match rubyRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained
115+
syn match rubyRegexpCharClass "\\[pP]{^\=.\{-}}" contained display
116+
syn match rubyRegexpEscape "\\[].*?+^$|\\/(){}[]" contained " see commit e477f10
117+
syn match rubyRegexpQuantifier "[*?+][?+]\=" contained display
118+
syn match rubyRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display
119+
syn match rubyRegexpAnchor "[$^]\|\\[ABbGZz]" contained display
120+
syn match rubyRegexpDot "\.\|\\X" contained display
121+
syn match rubyRegexpIntersection "&&" contained display
122+
syn match rubyRegexpSpecial "\\K" contained display
123+
syn match rubyRegexpSpecial "|" contained display
124+
syn match rubyRegexpSpecial "\\[1-9]\d\=\d\@!" contained display
125+
syn match rubyRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display
126+
syn match rubyRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display
127+
syn match rubyRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display
128+
syn match rubyRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display
127129

128130
syn cluster rubyStringSpecial contains=rubyInterpolation,rubyStringEscape
129131
syn cluster rubyExtendedStringSpecial contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets
130-
syn cluster rubyRegexpSpecial contains=rubyInterpolation,rubyStringEscape,rubyRegexpSpecial,rubyRegexpEscape,rubyRegexpBrackets,rubyRegexpCharClass,rubyRegexpDot,rubyRegexpQuantifier,rubyRegexpAnchor,rubyRegexpParens,rubyRegexpComment
132+
syn cluster rubyRegexpSpecial contains=rubyInterpolation,rubyStringEscape,rubyRegexpSpecial,rubyRegexpEscape,rubyRegexpBrackets,rubyRegexpCharClass,rubyRegexpDot,rubyRegexpQuantifier,rubyRegexpAnchor,rubyRegexpParens,rubyRegexpComment,rubyRegexpIntersection
131133

132134
" Numbers {{{1
133135
syn match rubyInteger "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<0[xX]\x\+\%(_\x\+\)*r\=i\=\>" display
@@ -455,6 +457,7 @@ hi def link rubyRegexpQuantifier rubyRegexpSpecial
455457
hi def link rubyRegexpAnchor rubyRegexpSpecial
456458
hi def link rubyRegexpDot rubyRegexpCharClass
457459
hi def link rubyRegexpCharClass rubyRegexpSpecial
460+
hi def link rubyRegexpIntersection rubyRegexpSpecial
458461
hi def link rubyRegexpSpecial Special
459462
hi def link rubyRegexpComment Comment
460463
hi def link rubyRegexp rubyString

0 commit comments

Comments
 (0)