Original issue: https://github.com/geany/geany/issues/2038
Geany wrongly colors sequences starting with a percentage sign (%).
Program that illustrates some issues:
n = 1337;
w = r = 5
x = n%w + 1; # "%w " is recognised as the beginning of an array of words, like %w[ ... ]
y = n%r ; # "%r " is recognised as the beginning of a regular expression
string = %= this is a string = ; # this one is correctly colored
n %= w; # this is the most important issue, the expression is equivalent to n = n % w; but it's recognised like the previous line
print x%r # %r is also recognised like a beginning of regex, but in this case, the %= of the previous line is still not terminated (no equal sign encoutered).
Can you explain the rule used by Ruby to treat these occurrences of '%' as not quote prefixes?
Yes, it's the modulo operator, like in other programming languages, not sure on the grammar rules used by Ruby to distinguish between when it's a quote prefix and when it's an operator, but it seems like:
(the + is just a delimiter, [ ] or ( ) can be used, or & &, = =, and many others)
Without an easy way to work out what each '%' means, I'll leave this to others more involved with Ruby.
[bugs:#1255] is a related bug for '%' in Ruby.
Related
Bugs:
#1255Here (
parse_percentfunction) is how%is parsedhttps://github.com/ruby/ruby/blob/master/parse.y#L9299
I think
%=is fixed:fix others is complex.