sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 587 forks source link

[Ruby] Modulo of negative number (e.g. "15%-4") incorrectly highlighted as start of percent string #1166

Open Nnnes opened 7 years ago

Nnnes commented 7 years ago
%-string content- # good highlighting; equivalent to "string content"
15 % -4 - 6 == -7 # good highlighting
15"4 " 6==-7      # good highlighting (despite broken syntax)
15%-4 - 6==-7     # bad highlighting; highlighted in the same way as the above line

The highlighting appears incorrectly in GitHub the same way that it does in Sublime Text. A true fix is likely not feasible:

int = 15

def str(arg)
  "string: #{arg}"
end

puts int %-4 #-
puts str %-4 #-

is interpreted the same as

int = 15

def str(arg)
  "string: #{arg}"
end

puts int % -4
puts str("4 #")

so both output

-1
string: 4 #
FichteFoll commented 7 years ago

Since

puts int %-4 #-
puts str %-4 #-

uses exactly the same syntax, you won't be able to get highlighting with ST's engine that is 100% correct, but it can at least try to guess whether the content of a percent string would consist of only a (negative) number and consider it to be the modulo operator instead.

But why, Ruby, why?

(I confirmed this btw.)