comparison lisp/progmodes/python.el @ 111385:85a2b871f225

* lisp/progmodes/python.el (python-font-lock-syntactic-keywords): Fix handling of backslash escapes. (python-quote-syntax): Adjust accordingly.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 08 Nov 2010 13:56:10 -0500
parents fae81355c62c
children 132f2dfd549f d4d6fcc60f7b
comparison
equal deleted inserted replaced
111384:90d8fda00161 111385:85a2b871f225
168 168
169 (defconst python-font-lock-syntactic-keywords 169 (defconst python-font-lock-syntactic-keywords
170 ;; Make outer chars of matching triple-quote sequences into generic 170 ;; Make outer chars of matching triple-quote sequences into generic
171 ;; string delimiters. Fixme: Is there a better way? 171 ;; string delimiters. Fixme: Is there a better way?
172 ;; First avoid a sequence preceded by an odd number of backslashes. 172 ;; First avoid a sequence preceded by an odd number of backslashes.
173 `((,(rx (not (any ?\\)) 173 `((,(concat "\\(?:\\([RUru]\\)[Rr]?\\|^\\|[^\\]\\(?:\\\\.\\)*\\)" ;Prefix.
174 ?\\ (* (and ?\\ ?\\)) 174 "\\(?:\\('\\)'\\('\\)\\|\\(?2:\"\\)\"\\(?3:\"\\)\\)")
175 (group (syntax string-quote)) 175 (1 (python-quote-syntax 1) nil lax)
176 (backref 1)
177 (group (backref 1)))
178 (2 ,(string-to-syntax "\""))) ; dummy
179 (,(rx (group (optional (any "uUrR"))) ; prefix gets syntax property
180 (optional (any "rR")) ; possible second prefix
181 (group (syntax string-quote)) ; maybe gets property
182 (backref 2) ; per first quote
183 (group (backref 2))) ; maybe gets property
184 (1 (python-quote-syntax 1))
185 (2 (python-quote-syntax 2)) 176 (2 (python-quote-syntax 2))
186 (3 (python-quote-syntax 3))) 177 (3 (python-quote-syntax 3)))
187 ;; This doesn't really help. 178 ;; This doesn't really help.
188 ;;; (,(rx (and ?\\ (group ?\n))) (1 " ")) 179 ;;; (,(rx (and ?\\ (group ?\n))) (1 " "))
189 )) 180 ))
217 ;; Is it a matching sequence? 208 ;; Is it a matching sequence?
218 (if (eq (char-after) (char-after (match-beginning 2))) 209 (if (eq (char-after) (char-after (match-beginning 2)))
219 (eval-when-compile (string-to-syntax "|")))))) 210 (eval-when-compile (string-to-syntax "|"))))))
220 ;; Consider property for initial char, accounting for prefixes. 211 ;; Consider property for initial char, accounting for prefixes.
221 ((or (and (= n 2) ; leading quote (not prefix) 212 ((or (and (= n 2) ; leading quote (not prefix)
222 (= (match-beginning 1) (match-end 1))) ; prefix is null 213 (not (match-end 1))) ; prefix is null
223 (and (= n 1) ; prefix 214 (and (= n 1) ; prefix
224 (/= (match-beginning 1) (match-end 1)))) ; non-empty 215 (match-end 1))) ; non-empty
225 (let ((font-lock-syntactic-keywords nil)) 216 (let ((font-lock-syntactic-keywords nil))
226 (unless (eq 'string (syntax-ppss-context (syntax-ppss))) 217 (unless (eq 'string (syntax-ppss-context (syntax-ppss)))
227 (eval-when-compile (string-to-syntax "|"))))) 218 (eval-when-compile (string-to-syntax "|")))))
228 ;; Otherwise (we're in a non-matching string) the property is 219 ;; Otherwise (we're in a non-matching string) the property is
229 ;; nil, which is OK. 220 ;; nil, which is OK.