+9

Ruby regular expressions syntax highlighting issue

Leo Gallucci 5 years ago • updated by Karl He 4 years ago 4

In the following example, ruby syntax highlighting breaks due to triple double quotes within the regexp:


Given /^the file "([^"]*)" doesn't exist$/ do |file|

  FileUtils.rm(file) if File.exists? file

end


Screenshot:


+1

I managed to fix this by editing Ruby.tmLanguage


https://gist.github.com/3921521

+1

That patch fixes it but introduces another problem, now when using it for division it'll cause the highlighting issue, e.g.: number = 5 / 4

I'm not familiar enough with how to modify these tmLanguage files to propose a better fix..

You are right, note i don't make as many divisions as i work with Regexps.


Are you using Sublimte Text 3 by now? maybe has already been fixed there.

I have not, although I don't have high hopes it would be fixed since the tmLanguage files are (I believe) originally from TextMate.

Thinking more about how to solve the issue I still haven't come up with a good solution, it's really hard to distinguish between the two use cases which can have practically identical syntax in many cases:


number = my_number / (another_number + "5".to_i) / 3

store_regex /foo "(bar)".* baz/i


Perhaps this is why it was left out of the grammar file in the first place when it was such an obvious omission