Skip to content

Commit 763877d

Browse files
committed
Support %=...= percent string literals
This is special-cased so it doesn't match the modulo assignment operator.
1 parent 4c91c8e commit 763877d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

spec/syntax/operators_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
vim.command 'unlet g:ruby_operators'
99
end
1010

11+
specify "modulo-assignment operators" do
12+
assert_correct_highlighting(<<~'EOF', '%=', 'rubyAssignmentOperator')
13+
foo %= bar
14+
EOF
15+
end
16+
1117
specify "ternary operators" do
1218
str = <<~'EOF'
1319
foo = bar ? 4 : 2
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'spec_helper'
2+
3+
describe "Syntax highlighting" do
4+
specify "percent strings with a modulo-assignment operator look-alike delimiter" do
5+
assert_correct_highlighting(<<~'EOF', '%=', 'rubyPercentStringDelimiter')
6+
foo = %= bar =
7+
EOF
8+
end
9+
end

syntax/ruby.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%
290290
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" contains=rubyBackslashEscape,rubySpaceEscape,rubyParenthesisEscape,rubyNestedParentheses
291291

292292
" Generalized Double Quoted Strings, Array of Strings, Array of Symbols and Shell Command Output {{{1
293-
" Note: %= is not matched here as the beginning of a double quoted string
293+
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="\%(\%(\w\|[^\x00-\x7F]\|]\)\s*\)\@<!%=" end="=" skip="\\\\\|\\=" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
294294
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
295-
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
295+
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
296296
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces
297297
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets
298298
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets

0 commit comments

Comments
 (0)