3 ms·
And usually not at compile time.
by 1ris 10y ago
And usually not at compile time.
- deleted 10y ago[deleted]
- junke 10y agoHere is an example of an "unusual" case where the compiler can detect errors in statically known regexes. This fails at compilation with Opening paren has no matching closing paren. at position 0 in string "(ab" (defun scan-ab (s) (ppcre:scan "(ab" s)) By the way, here is the alternative syntax: (defun scan-ab (s) (ppcre:scan '(:register "ab") s)) The alternative syntax allows to embed string regexes: (defun wrap-regex (regex) (typecase regex (string `(:regex ,regex)) (t regex))) This is useful for combining regexes: (defun exactly-some (&rest choices) (let ((choices (mapcar #'wrap-regex choices))) `(:sequence :start-anchor ,@(if (rest choices) `((:alternation ,@choices)) choices) :end-anchor))) (exactly-some "t.*") (:SEQUENCE :START-ANCHOR (:REGEX "t.*") :END-ANCHOR) (exactly-some "t.*" "a.a" ':whitespace-char-class) (:SEQUENCE :START-ANCHOR (:ALTERNATION (:REGEX "t.*") (:REGEX "a.a") :WHITESPACE-CHAR-CLASS) :END-ANCHOR)