register-groups-case
The snippet can be accessed without any authentication.
Authored by
Luís Oliveira
Inspired by ACL's excl:re-case
.
register-groups-case.lisp 663 B
(defmacro register-groups-case (string &body clauses)
(alexandria:once-only (string)
(alexandria:with-unique-names (register-groups-case-block)
(labels ((emit-clauses (clauses)
(when clauses
(destructuring-bind (regex bindings &body body)
(first clauses)
(cons `(ppcre:register-groups-bind ,bindings
(,regex ,string)
(return-from ,register-groups-case-block
(progn ,@body)))
(emit-clauses (rest clauses)))))))
`(block ,register-groups-case-block
,@(emit-clauses clauses))))))
#+example
(register-groups-case "foo"
("bar" (a)
(list a))
("f(.)(.)" (o1 o2)
(list o1 o2)))
Please register or sign in to comment