This repository has been archived by the owner on Dec 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor constructor pattern parser/compiler
- Loading branch information
Tomohiro Matsuyama
committed
Nov 17, 2012
1 parent
5fb0dc6
commit 24af190
Showing
7 changed files
with
484 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
(in-package :optima.contrib) | ||
|
||
(defstruct (ppcre-pattern (:include optima::constructor-pattern) | ||
(:constructor make-ppcre-pattern (regex &rest subpatterns))) | ||
regex) | ||
|
||
(defmethod optima::destructor-equal ((x ppcre-pattern) (y ppcre-pattern)) | ||
(equal (ppcre-pattern-regex x) (ppcre-pattern-regex y))) | ||
|
||
(defmethod optima::destructor-predicate-form ((pattern ppcre-pattern) var) | ||
(values `(nth-value 1 (ppcre:scan-to-strings ,(ppcre-pattern-regex pattern) ,var)) t)) | ||
|
||
(defmethod optima::destructor-forms ((pattern ppcre-pattern) var) | ||
(loop for i from 0 below (optima::constructor-pattern-arity pattern) | ||
collect `(optima::%svref ,var ,i))) | ||
|
||
(defmethod optima::parse-constructor-pattern ((name (eql 'ppcre)) &rest args) | ||
(destructuring-bind (re . patterns) args | ||
(optima::make-constructor-pattern | ||
:specifier `(ppcre ,@args) | ||
:signature `(ppcre ,re) | ||
:arguments (mapcar #'optima::parse-pattern patterns) | ||
:predicate (lambda (var) (values `(nth-value 1 (ppcre:scan-to-strings ,re ,var)) t)) | ||
:accessor (lambda (var i) `(svref ,var ,i))))) | ||
(apply #'make-ppcre-pattern (first args) | ||
(mapcar #'optima::parse-pattern (rest args)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.