Commits

llibra  committed 6517e86

Aly now uses fivepm for pattern matching instead of CL-PATTERN.

  • Participants
  • Parent commits e6bc0ed

Comments (0)

Files changed (5)

File README.markdown

 
 * [Alexandria](http://common-lisp.net/project/alexandria/)
 * [Anaphora](http://common-lisp.net/project/anaphora/)
-* [CL-PATTERN](https://github.com/arielnetworks/cl-pattern)
+* [fivepm](https://github.com/m2ym/fivepm)
 
 Install
 -------
   :version "0.1"
   :author "Manabu Takayama <learn.libra@gmail.com>"
   :licence "MIT License"
-  :depends-on (:alexandria :anaphora :cl-pattern)
+  :depends-on (:alexandria :anaphora :fivepm)
   :components ((:module "src"
                         :serial t
                         :components ((:file "packages")

File src/core.lisp

 (defmacro mlet* (bindings &body body)
   (match bindings
     (() `(progn ,@body))
-    (((var parser) . rest)
+    ((cons (list var parser) rest)
      `(mlet1 ,var ,parser (mlet* ,rest ,@body)))))
 
 (defun seq (&rest parsers)
          (unit x)))))
 
 (defmacro seq/bind (&rest parsers)
-  (match parsers
-    (() '(unit nil))
-    (((var <- parser))
-     (if (string= <- "<-") parser `(,var ,<- ,parser)))
-    ((parser) parser)
-    (((var <- parser) . rest)
-     (if (string= <- "<-")
-         `(mlet1 ,var ,parser (seq/bind ,@rest))
-         `(mlet1 _ (,var ,<- ,parser) (seq/bind ,@rest))))
-    ((parser . rest)
-     `(mlet1 _ ,parser (seq/bind ,@rest)))))
+  (flet ((<-p (<-) (string= <- "<-")))
+    (match parsers
+      (() '(unit nil))
+      ((guard (list (list _ <- parser)) (<-p <-)) parser)
+      ((list parser) parser)
+      ((guard (cons (list var <- parser) rest) (<-p <-))
+       `(mlet1 ,var ,parser (seq/bind ,@rest)))
+      ((cons parser rest)
+       `(mlet1 _ ,parser (seq/bind ,@rest))))))
 
 (defun satisfy (pred)
   (lambda (stream)

File src/packages.lisp

 (defpackage :aly.util
   (:use :cl)
   (:import-from :alexandria :with-gensyms)
-  (:import-from :cl-pattern :match)
+  (:import-from :5pm :match)
   (:export :defalias :result-match :intersperse))
 
 (defpackage :aly.stream
 (defpackage :aly.core
   (:use :cl :aly.util :aly.stream :aly.condition)
   (:import-from :alexandria :with-gensyms :flatten)
-  (:import-from :cl-pattern :match)
+  (:import-from :5pm :match :guard)
   (:export :success :failure :satisfy :unit :fail :bind :mlet1 :mlet* :seq :seq1
            :seqn :seq/bind :choice :try :expect :many :skip-many :eoi :parse))
 

File src/util.lisp

        ;; The list is allocated in the heap for tail call optimization.
        ;; But it will make this part slow.
        ;(declare (dynamic-extent ,values))
-       (match ,values ,@clauses))))
+       (match ,values ,@(mapcar (lambda (x)
+                                  (cons (cons 'list (car x)) (cdr x)))
+                                clauses)))))
 
 (defun intersperse (item list &optional (last-item item))
   (labels ((rec (rest acc)