comparison lisp/progmodes/python.el @ 58487:d0581f1eef46

(python-font-lock-syntactic-keywords): Check for escapes in the regexp. (python-quote-syntax): Don't do it here.
author Richard M. Stallman <rms@gnu.org>
date Thu, 25 Nov 2004 02:54:58 +0000
parents 86ead4686506
children 2761697b0e2f
comparison
equal deleted inserted replaced
58486:f9f5c9ddd813 58487:d0581f1eef46
101 (1 font-lock-keyword-face) (2 font-lock-function-name-face)))) 101 (1 font-lock-keyword-face) (2 font-lock-function-name-face))))
102 102
103 (defconst python-font-lock-syntactic-keywords 103 (defconst python-font-lock-syntactic-keywords
104 ;; Make outer chars of matching triple-quote sequences into generic 104 ;; Make outer chars of matching triple-quote sequences into generic
105 ;; string delimiters. Fixme: Is there a better way? 105 ;; string delimiters. Fixme: Is there a better way?
106 `((,(rx (and (group (optional (any "uUrR"))) ; prefix gets syntax property 106 `((,(rx (and (or buffer-start (not (syntax escape))) ; avoid escaped
107 ; leading quote
108 (group (optional (any "uUrR"))) ; prefix gets syntax property
107 (optional (any "rR")) ; possible second prefix 109 (optional (any "rR")) ; possible second prefix
108 (group (syntax string-quote)) ; maybe gets property 110 (group (syntax string-quote)) ; maybe gets property
109 (backref 2) ; per first quote 111 (backref 2) ; per first quote
110 (group (backref 2)))) ; maybe gets property 112 (group (backref 2)))) ; maybe gets property
111 (1 (python-quote-syntax 1)) 113 (1 (python-quote-syntax 1))
128 130
129 ;; Test cases: 131 ;; Test cases:
130 ;; ur"""ar""" x='"' # """ 132 ;; ur"""ar""" x='"' # """
131 ;; x = ''' """ ' a 133 ;; x = ''' """ ' a
132 ;; ''' 134 ;; '''
133 ;; x '"""' x 135 ;; x '"""' x """ \"""" x
134 (save-excursion 136 (save-excursion
135 (goto-char (match-beginning 0)) 137 (goto-char (match-beginning 0))
136 (unless (eq ?\\ (char-before)) 138 (cond
137 (cond 139 ;; Consider property for the last char if in a fenced string.
138 ;; Consider property for the last char if in a fenced string. 140 ((= n 3)
139 ((= n 3) 141 (let ((syntax (syntax-ppss)))
140 (let ((syntax (syntax-ppss))) 142 (when (eq t (nth 3 syntax)) ; after unclosed fence
141 (when (eq t (nth 3 syntax)) ; after unclosed fence 143 (goto-char (nth 8 syntax)) ; fence position
142 (goto-char (nth 8 syntax)) ; fence position 144 ;; Skip any prefix.
143 ;; Skip any prefix. 145 (if (memq (char-after) '(?u ?U ?R ?r))
144 (if (memq (char-after) '(?u ?U ?R ?r)) 146 (skip-chars-forward "uUrR"))
145 (skip-chars-forward "uUrR")) 147 ;; Is it a matching sequence?
146 ;; Is it a matching sequence? 148 (if (eq (char-after) (char-after (match-beginning 2)))
147 (if (eq (char-after) (char-after (match-beginning 2))) 149 (eval-when-compile (string-to-syntax "|"))))))
148 (eval-when-compile (string-to-syntax "|")))))) 150 ;; Consider property for initial char, accounting for prefixes.
149 ;; Consider property for initial char, accounting for prefixes. 151 ((or (and (= n 2) ; not prefix
150 ((or (and (= n 2) ; not prefix 152 (= (match-beginning 1) (match-end 1))) ; prefix is null
151 (= (match-beginning 1) (match-end 1))) ; prefix is null 153 (and (= n 1) ; prefix
152 (and (= n 1) ; prefix 154 (/= (match-beginning 1) (match-end 1)))) ; non-empty
153 (/= (match-beginning 1) (match-end 1)))) ; non-empty 155 (unless (eq 'string (syntax-ppss-context (syntax-ppss)))
154 (unless (eq 'string (syntax-ppss-context (syntax-ppss))) 156 (eval-when-compile (string-to-syntax "|"))))
155 (eval-when-compile (string-to-syntax "|"))))) 157 ;; Otherwise (we're in a non-matching string) the property is
156 ;; Otherwise (we're in a non-matching string) the property is 158 ;; nil, which is OK.
157 ;; nil, which is OK. 159 )))
158 )))
159 160
160 ;; This isn't currently in `font-lock-defaults' as probably not worth 161 ;; This isn't currently in `font-lock-defaults' as probably not worth
161 ;; it -- we basically only mess with a few normally-symbol characters. 162 ;; it -- we basically only mess with a few normally-symbol characters.
162 163
163 ;; (defun python-font-lock-syntactic-face-function (state) 164 ;; (defun python-font-lock-syntactic-face-function (state)