Subject: bug#7735: A questing mark at the end of a string in ruby-mode

From: Stefan Monnier <[email-masked]>
Date: Mon, 24 Jan 2011 14:49:35 -0500

> A question mark at the end of a string makes ruby-mode believe the
> string does not end there.

Indeed, when I switched to syntax-propertize-rules code, I didn't notice
that one of the regexps use backrefs, which aren't supported by
syntax-propertize-rules.
I've just installed the patch below which should fix it,

        Stefan

=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el	2011-01-16 02:21:30 +0000
+++ lisp/progmodes/ruby-mode.el	2011-01-24 19:47:16 +0000
@@ -1121,14 +1121,13 @@
          (syntax-propertize-rules
           ;; #{ }, #$hoge, #@foo are not comments
           ("\\(#\\)[{$@]" (1 "."))
-          ;; the last $', $", $` in the respective string is not variable
-          ;; the last ?', ?", ?` in the respective string is not ascii code
-          ("\\(^\\|[\[ \t\n<+\(,=]\\)\\(['\"`]\\)\\(\\\\.\\|\\2\\|[^'\"`\n\\\\]\\)*?\\\\?[?$]\\(\\2\\)"
-           (2 "\"")
-           (4 "\""))
           ;; $' $" $` .... are variables
           ;; ?' ?" ?` are ascii codes
-          ("\\(^\\|[^\\\\]\\)\\(\\\\\\\\\\)*[?$]\\([#\"'`]\\)" (3 "."))
+          ("\\([?$]\\)[#\"'`]"
+           (1 (unless (save-excursion
+                        ;; Not within a string.
+                        (nth 3 (syntax-ppss (match-beginning 0))))
+                (string-to-syntax "\\"))))
           ;; regexps
           ("\\(^\\|[=(,~?:;<>]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)"
            (4 "\"/")