help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ruby-mode interpolated quotes error


From: Bob Proulx
Subject: Re: ruby-mode interpolated quotes error
Date: Fri, 2 May 2014 17:55:33 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Bob Proulx wrote:
> Andrew Pennebaker wrote:
> > Specifically, the initial double quote on line 46 should be colored yellow,
> > like the end double quote, and the single quoted string above.
> > 
> > Anyone else experience this?
> 
> The #{...} construct causes the character immediately preceding the
> '#' to be colored in the variable face color.

This motivated me to poke into the problem a little.  The problem
appears to be ruby-match-expression-expansion which is looking for any
character not a backslash before the #{...}.

 (defun ruby-match-expression-expansion (limit)
   (when (re-search-forward 
"[^\\]\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)"
 limit 'move)
     (or (ruby-in-ppss-context-p 'string)
         (ruby-match-expression-expansion limit))))

It is trying to avoid matching a sub-expression in this case.  Two
test cases would be:

  "abc#{def}ghi"
  "abc\#{def}ghi"

In the first #{def} is a subexpression.  In the second the # is
escaped and is not evaluated.

So what is needed is a way to match a # that is not preceded by a
backslash but not to include the non-backslash character in the
expression.  Or another method to accomplish the task.  I am only an
infrequent elisp hacker and am unfamiliar with the idioms needed to
avoid this problem.

Anyone else on the list know a good idiom to use?  It needs to match
but ignore the leading context.  (This is the opposite of the "trailing
context" match feature provided by lex.)

As a quick hack to alleviate your particular symptom, while creating a
more rare different one, you could remove the [^\\] part from the
front of the expression.  That would no longer match the non-backslash
in front of the #{...} construct and your case would work correctly.
It then would miscolor the new case "abc\#{def}ghi" which is not a
sub-expression due to the escape but would still be colored as if it
were.  That might be a less annoying problem.

Bob

--- ruby-mode.el.orig   2014-05-02 17:29:15.312413975 -0600
+++ ruby-mode.el        2014-05-02 17:27:31.935234984 -0600
@@ -1578,7 +1578,7 @@
   "Additional expressions to highlight in Ruby mode.")
 
 (defun ruby-match-expression-expansion (limit)
-  (when (re-search-forward 
"[^\\]\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)"
 limit 'move)
+  (when (re-search-forward 
"\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)"
 limit 'move)
     (or (ruby-in-ppss-context-p 'string)
         (ruby-match-expression-expansion limit))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]