Ruby 1.9.3 introduced an alternative way to define symbol keys in hashes: key:
rather than :key =>
.
Scintilla's Ruby lexer does not recognize a here doc when it follows this new syntax. For example, this here doc is not recognized, and the lexer picks up syntax from inside it and screws up the rest of the file:
hash = {
text: <<-TEXT
There could be something in here that breaks
Ruby syntax highlighting, like:
<html></html>
TEXT
}
But this one is properly recognized (notice the change from text:
to :text =>
)
hash = {
:text => <<-TEXT
There could be something in here that breaks
Ruby syntax highlighting, like:
<html></html>
TEXT
}
If it helps at all, I narrowed the cause of the issue down to the if
block at line 506 of lexers/LexRuby.cxx:
// Skip next batch of white-space
firstWordPosn = skipWhitespace(firstWordPosn, lt2StartPos, styler);
if (firstWordPosn != lt2StartPos) {
// Have [[^ws[identifier]ws[*something_else*]ws<<
return definitely_not_a_here_doc;
}
I have unfortunately no clue whether this is correct (I don't know Ruby :)), but it fixes the example. It treats
foo:
as a symbol, and allows a symbol before an heredoc.Feel free to use, or not, depending on whether it makes sense (I can also provide a proper changeset export). I might also give it another shot if I get a easier description than "foo: is a symbol if inside a hash definition"; which is clear but requires to trach hash declarations, which is non trivial.
Committed as [0f07ab].
Related
Commit: [0f07ab]
Close, but it still doesn't work in the case that the symbol is not the first thing on the line, as in cases like these:
(again, replacing
inline:
with:inline =>
results in correct behavior)(for reference, render is being passed a hash with a single key '
inline
', and the curly braces around the hash are implied)I expect these might be very difficult to properly recognize due to Ruby's very flexible syntax, but if all else fails, I think it would be preferable to recognize heredocs too often than not often enough. An unrecognized heredoc can throw off the highlighting of the rest of the file, and it's more likely that someone would use one of the above syntaxes than use something that looks like a heredoc but isn't.
OK, that's because the extra symbol makes
sureThisIsNotHeredoc()
refuse it. Fixed in the first attached patch.This actually is caused by another issue in
sureThisIsNotHeredoc()
, which doesn't recognize lines with combined or nested expressions. Should be fixed in the second attached patch.Recognizing a HereDoc where there is none is almost certain to break highlighting of the rest of the file. Either way is bad, but if we really want to play and weight which one is worse, I'd say it's recognizing non-existent HereDocs, because with most other cases one can at the very least hack around a misdetection by adding a comment containing the proper tremination sequence, but that's not possible with a HereDoc. It's ugly, but well.
Committed as [a1538d] and [38fd92] with minor reformatting.
Related
Commit: [38fd92]
Commit: [a1538d]