Ruby highlighter should support multi-line strings #25

jfarmer opened this Issue Mar 31, 2012 · 3 comments


None yet
2 participants

jfarmer commented Mar 31, 2012

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


str = "This
a valid string."

str = 'So
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.


ccampbell commented Mar 31, 2012

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 commented Apr 1, 2012

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

quoted comment and string


jfarmer commented Apr 1, 2012

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?


#someone's comment
test = 'blah blah
blah de blah'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment