Sublime Forum

[BUG] Ruby RegEx syntax highlighting

#1

If there is only one “word” in front of a RegEx string in Ruby, it will botch up the syntax highlighting if there is an escaped quote in the RegEx.

For example:

When /^\"(^\"]+)\"$/

Everything after the first escaped quote won’t highlight correctly. For some reason, this is fixed if there is a double escaped ending quote, like this:

When /^\"\\"$/

This case probably doesn’t happen often in coding, but it is perfectly valid code. The “When …” syntax above is often used in the Ruby gem Cucumber. Also, I could see it happening when a RegEx is passed to a function as an argument:

foo /^\"bar\"$/

Putting the argument in parentheses fixes the highlighting, but the former is still valid syntax.

0 Likes

#2

I’m still seeing this. Particularly annoying in Cucumber steps. I tried to find out how to edit syntax highlighting but did not have any luck… Anyone know if this is possible?

0 Likes

#3

Still seeing this in the latest Sublime Text 2 (#2111). Any chance of a fix?

0 Likes

#4

same in build 2132… any ideas?

0 Likes

#5

same in build 2139
hope it will be fixed!

0 Likes

#6

Still present. If you try to check for some tags it will also break the highlighting ( FIXED [Bug] Syntax Highlighting of Regular Expressions are … ).

0 Likes

#7

Edit: Seems to be fixed.

0 Likes

#8

Another issue on syntax highlighting is

s.assert_match /label for=\"test\"/, some_variable

but is does work without the leading session-variable (s in this case).

This works:

assert_match /label for=\"test\"/, some_variable

The same happens in the post above:

assert_match /window.location . /, s.response.body

works, while

s.assert_match /window.location . /, s.response.body

does not.

Edit:
This does also break the following syntax highlighting:

assert_no_match /foo,/, str

Edit2:
And another:

Multiline comments are not recognized as those if there is a single line comment before.
For example:

# TODO: fix sublime syntax highlighting
=begin
this text is a comment so it should be handled as those
=end
0 Likes

#9

(5 years later) this is still happening

See attached screenshot.

From line 9 onward it looks like there’s an unmatched quote, but there’s not.

Sublime Version 3.0, Build 3143

0 Likes

#10

It certainly looks like the first slash is being misinterpreted as a division operator. I don’t know enough about the Ruby syntax to say exactly how it should know the difference. You should post an issue on the core packages issue tracker.

0 Likes