Hi Richard,
[...]
> The next hurdle is the following unusual syntax:
>
> r'some string or regexp'
[...]
I don't know python at all and I am not sure I clearly understand the
problem. Does it concern handling of "raw-strings" of the form
r"..."?
Maybe could you provide some code snippets?
To handle raw-strings I (quickly ;-) wrote the following
`semantic-flex-extensions' that seems to work:
(defconst wisent-python-raw-string-re "\\<[r]\""
"Regexp matching python raw string prefix.")
(defconst wisent-python-flex-extensions
(list (cons wisent-python-raw-string-re
'wisent-python-flex-raw-string))
"`semantic-flex-extensions' to recognize python raw strings.")
(defun wisent-python-flex-raw-string ()
"`semantic-flex' extension to handle python raw-strings.
Return a 'raw-string syntactic token."
(let* ((b (point))
(e (condition-case nil
(progn
(forward-char) ;; skip 'r'
(forward-sexp 1)
(point))
;; This case makes flex
;; robust to broken strings.
(error
(progn
(goto-char
(funcall
semantic-flex-unterminated-syntax-end-function
'string
start end))
(point))))))
(cons 'raw-string (cons b e))))
Then 'raw-string tokens can be easily handled by a specific
`wisent-flex' handler like this (untested):
;; %token <raw-string> RAW_STRING_LITERAL
;; %put raw-string handler 'wisent-python-raw-string-handler
;;
(defun wisent-python-raw-string-handler ()
"`wisent-flex' handler of 'raw-string syntactic tokens."
(let* ((stok (car wisent-flex-istream))
(wisent-flex-istream (cdr wisent-flex-istream)))
(cons 'RAW_STRING_LITERAL
(cons
;; Remove r" and " delimiters
(substring (semantic-flex-text stok) 2 -1)
(cdr stok)))))
I think it can be interesting to differentiate normal strings
(their value should be `read' to remove '\') and raw strings (their
value is the text between r" and the final ", and '\' aren't removed).
I hope I helped ;-)
Sincerely,
David,
|