Skip to content
Snippets Groups Projects

register-groups-case

The snippet can be accessed without any authentication.
Authored by Luís Oliveira

Inspired by ACL's excl:re-case.

Edited
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)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment