rainbow icon indicating copy to clipboard operation
rainbow copied to clipboard

Ruby highlighter should support multi-line strings

Open jfarmer opened this issue 12 years ago • 3 comments

Ruby supports multi-line strings, for both single and double-quoted strings.

e.g.,

str = "This
is
a valid string."

str = 'So
is
this string.'

Any implementation should deal with the following edge case:

# This comment contains a single quote: '

str = 'This
string \'should\' be
highlighted, including the escaped quotes'

The way rainbow's parser works is by generating all possible matches for a regex and discarding those that intersect another regex. In this case, the regex to match a multi-line string will most likely start by picking up the single quote in the comment.

This has nothing to do with comments, per se. It would also trip up if, say, there were a single quote in a double-quoted string immediately preceding a single-quoted string.

jfarmer avatar Mar 31 '12 23:03 jfarmer

This actually applies for other languages as well, but Ruby doesn't inherit from the generic patterns right now. Originally I was processing comments first. This allowed multiline strings to work pretty well, but I changed the order to fix #2.

I've been working on adding tests so that I will feel more comfortable making changes without having to worry about breaking other things. If you open up tests/index.html in a browser you can see. In fact it would be great to have some for Ruby as well.

ccampbell avatar Mar 31 '12 23:03 ccampbell

Actually this seems to work in the generic patterns perhaps not intentionally ha.

quoted comment and string

ccampbell avatar Apr 01 '12 00:04 ccampbell

Hmm. I'll see if I can use that to make it work for Ruby. What if you put the multi-line string immediately after the comment?

e.g.,

#someone's comment
test = 'blah blah
blah de blah'

jfarmer avatar Apr 01 '12 00:04 jfarmer