Subject: bug#15874: 24.3.50; exit! not properly font-locked in ruby-mode

From: Stefan Monnier <[email-masked]>
Date: Thu, 05 Dec 2013 14:02:53 -0500

>> Maybe a good way to handle them is via syntax-propertize,
> Huh yes, that's an approach I haven't considered.

The advantage is that it would also fix the sexp-movement operations.

> But it seems more performance-intensive than the other options, at
> least as long as Emacs regexps don't support lookbehind.

I don't see why we'd need lookbehind.
We can use a regexp like "\\(?:\\sw\\|\\s_\\)\\([!?]\\)" and then place
the syntax-table property on the ? (or !) character.

> Say, why don't we have a "non-symbol" matcher?

I'd rather do something a bit more generic, then, like a \\S which can
take a set of syntaxes to exclude.  Or maybe extend the [:foo:]
character classes to allow [:sw:], [:s_:], etc... so we could do
[^[:sw:][:s_:]].

> I would think that in many cases the regexp engine performs
> unnecessary work when it sees "\\_<" or "\\_>" because we often know
> in advance that the character we've already matched, or will have to
> match next, is a symbol constituent. But the engine has to check.

It's not that big of a deal, tho.  I doubt this would ever appear as
a noticeable slowdown.  And with [^[:sw:][:s_:]] you'd have the extra
work of having to handle the EOB case, so you'd have
\(\'\|[^[:sw:][:s_:]]). 

>> then, especially if we can come up with a good regexp that
>> distinguishes "method name" from "local variable name"?
> Not really.  References to local variables, unlike instance and global ones,
> are indistinguishable from method calls if we judge only by name.

But you said that ! and ? are only allowed in method names.  So somehow
Ruby's parser/lexer distinguishes the two cases.  Would a reference to
a variable "foo?" simply always be parsed as "a reference to variable
foo?"  which would later trigger an error because there's no such
variable (because there can't be any such variable)?

        Stefan