Fix package use during bootstrap.
authorUtz-Uwe Haus <lisp@uuhaus.de>
Wed, 1 Oct 2008 19:53:53 +0000 (1 21:53 +0200)
committerUtz-Uwe Haus <lisp@uuhaus.de>
Wed, 1 Oct 2008 19:53:53 +0000 (1 21:53 +0200)
All provided parsing code is put into #:OPOSSUM-SYSTEM, the freshly generated
and public code is going to #:OPOSSUM. Users generating their own parsers
will only know the #:OPOSSUM package.

Signed-off-by: Utz-Uwe Haus <lisp@uuhaus.de>
bootstrap.lisp
pegparser-boot.lisp
pegutils.lisp

index b2d62ee..84ac17d 100644 (file)
@@ -36,8 +36,7 @@
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (format *trace-output* ";; bootstrap.lisp is creating pegparser.lisp~%")
-  (opossum:generate-parser-file "opossum.peg"
-                               (or (find-package 'xyzzy)
-                                   (make-package 'xyzzy)) ;; will become #:opossum
-                               "pegparser.lisp")
+  (opossum:generate-parser-file "opossum.peg" :opossum
+                               "pegparser.lisp"
+                               :parse-file-fun #'opossum-system::parse-file)
   (format *trace-output* ";; done creating pegparser.lisp~%"))
\ No newline at end of file
dissimilarity index 86%
index a5ad604..58f127b 100644 (file)
-;; -*- mode:lisp -*-
-(in-package :opossum)
-(eval-when (:compile-toplevel :load-toplevel :execute)
-  (declaim (optimize (speed 0) (safety 3) (debug 3))))
-(defun parse-file (f)
-  (let ((opossum:*context* (make-instance 'opossum:context :start-index 0
-                                         :destpkg *package*
-                                         :input (opossum:read-file f))))
-    (funcall (opossum::|parse_program|) 0)))
-
-(DEFUN |parse_program| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "program"
-                                    (opossum::SEQ (opossum::MANY (|parse_ws|))
-                                                  (opossum::MANY1
-                                                   (|parse_rule|))
-                                                  (LIST ':ACTION NIL
-                                                        '|metapeg_action320|)))))
-(DEFUN |parse_rule| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "rule"
-                                    (opossum::SEQ (|parse_id|)
-                                                  (opossum::MANY (|parse_ws|))
-                                                  (opossum::MATCH-STRING "<-")
-                                                  (opossum::MANY (|parse_ws|))
-                                                  (|parse_ordered-expr-list|)
-                                                  (opossum::MANY
-                                                   (|parse_ws_or_nl|))
-                                                  (LIST ':ACTION NIL
-                                                        '|metapeg_action321|)))))
-(DEFUN |parse_ordered-expr-list| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "ordered-expr-list"
-                                    (opossum::EITHER
-                                     (opossum::SEQ (|parse_expr-list|)
-                                                   (opossum::MANY (|parse_ws|))
-                                                   (opossum::MATCH-STRING "/")
-                                                   (opossum::MANY (|parse_ws|))
-                                                   (|parse_ordered-expr-list|)
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action322|))
-                                     (opossum::SEQ (|parse_expr-list|)
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action323|))))))
-(DEFUN |parse_expr-list| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "expr-list"
-                                    (opossum::SEQ (|parse_expr|)
-                                                  (opossum::MANY
-                                                   (opossum::SEQ
-                                                    (opossum::MANY1
-                                                     (|parse_ws|))
-                                                    (|parse_expr-list|)))
-                                                  (LIST ':ACTION NIL
-                                                        '|metapeg_action324|)))))
-(DEFUN |parse_expr| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "expr"
-                                    (opossum::EITHER
-                                     (opossum::SEQ (|parse_simple-expr|)
-                                                   (opossum::MATCH-STRING "*")
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action325|))
-                                     (opossum::SEQ (|parse_simple-expr|)
-                                                   (opossum::MATCH-STRING "+")
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action326|))
-                                     (opossum::SEQ (|parse_simple-expr|)
-                                                   (opossum::MATCH-STRING "?")
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action327|))
-                                     (opossum::SEQ (|parse_simple-expr|)
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action328|))))))
-(DEFUN |parse_simple-expr| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "simple-expr"
-                                    (opossum::EITHER
-                                     (opossum::SEQ (|parse_string|)
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action329|))
-                                     (|parse_action|)
-                                     (opossum::SEQ (opossum::MATCH-STRING "&")
-                                                   (|parse_simple-expr|)
-                                                   (LIST ':ACTION NIL
-                                                         '|metapeg_action330|))
-                                     (opossum::SEQ (opossum::MATCH-STRING "@")
-                                                   (|parse_id|)
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action331|))
-                                     (opossum::SEQ (|parse_id|)
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action332|))
-                                     (opossum::SEQ (|parse_bracketed-rule|)
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action333|))
-                                     (opossum::MATCH-STRING "!.")
-                                     (opossum::SEQ (opossum::MATCH-STRING "!")
-                                                   (|parse_expr|)
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action334|))
-                                     (opossum::SEQ (|parse_character-class|)
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action335|))
-                                     (opossum::SEQ (opossum::MATCH-STRING ".")
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action336|))))))
-(DEFUN |parse_bracketed-rule| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "bracketed-rule"
-                                    (opossum::EITHER
-                                     (opossum::MATCH-STRING "()")
-                                     (opossum::SEQ (opossum::MATCH-STRING "(")
-                                                   (opossum::MANY (|parse_ws|))
-                                                   (|parse_ordered-expr-list|)
-                                                   (opossum::MANY (|parse_ws|))
-                                                   (opossum::MATCH-STRING ")")
-                                                   (LIST ':action NIL
-                                                         '|metapeg_action337|))))))
-(DEFUN |parse_id| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "id"
-                                    (opossum::SEQ
-                                     (opossum::MANY1
-                                      (opossum::MATCH-CHAR
-                                       '(#\A #\B #\C #\D #\E #\F #\G #\H #\I
-                                         #\J #\K #\L #\M #\N #\O #\P #\Q #\R
-                                         #\S #\T #\U #\V #\W #\X #\Y #\Z #\a
-                                         #\b #\c #\d #\e #\f #\g #\h #\i #\j
-                                         #\k #\l #\m #\n #\o #\p #\q #\r #\s
-                                         #\t #\u #\v #\w #\x #\y #\z #\- #\_)))
-                                     (LIST ':action NIL
-                                           '|metapeg_action338|)))))
-(DEFUN |parse_character-class| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "character-class"
-                                    (opossum::SEQ (opossum::MATCH-STRING "[")
-                                                  (opossum::MANY1
-                                                   (opossum::SEQ
-                                                    (|parse_not_right_bracket|)
-                                                    (opossum::MATCH-ANY-CHAR)))
-                                                  (opossum::MATCH-STRING "]")
-                                                  (LIST ':action NIL
-                                                        '|metapeg_action339|)))))
-(DEFUN |parse_string| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "string"
-                                    (opossum::SEQ (opossum::MATCH-CHAR '(#\"))
-                                                  (opossum::MANY
-                                                   (opossum::SEQ
-                                                    (opossum::NEGATE
-                                                     (opossum::MATCH-CHAR
-                                                      '(#\")))
-                                                    (opossum::MATCH-ANY-CHAR)))
-                                                  (opossum::MATCH-CHAR '(#\"))
-                                                  (LIST ':action NIL
-                                                        '|metapeg_action340|)))))
-(DEFUN |parse_action| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "action"
-                                    (opossum::SEQ (opossum::MATCH-CHAR '(#\{))
-                                                  (opossum::MANY
-                                                   (opossum::SEQ
-                                                    (opossum::NEGATE
-                                                     (opossum::MATCH-CHAR
-                                                      '(#\})))
-                                                    (opossum::MATCH-ANY-CHAR)))
-                                                  (opossum::MATCH-CHAR '(#\}))
-                                                  (LIST ':action NIL
-                                                        '|metapeg_action341|
-                                                       *context*)))))
-(DEFUN |parse_not_right_bracket| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "not_right_bracket"
-                                    (opossum::NEGATE
-                                     (opossum::MATCH-STRING "]")))))
-(Defun |parse_comment| ()
-  (lambda (opossum::offset)
-    ;; ad-hoc comment handling addition to bootstrap ourselves
-    (opossum::BUILD-PARSER-FUNCTION "comment" (opossum::seq
-                                              (opossum::match-char '(#\#))
-                                              (opossum::many
-                                               (opossum::seq
-                                                (opossum::negate
-                                                 (opossum::match-char '(#\Newline)))
-                                                (opossum::match-any-char)))
-                                              (opossum::optional
-                                               (opossum::match-char '(#\Newline)))))))
-(DEFUN |parse_ws| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "ws" (opossum::either
-                                         (opossum::MATCH-CHAR '(#\Space #\Tab))
-                                         (|parse_comment|)))))
-(DEFUN |parse_nl| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "nl" (opossum::MATCH-CHAR '(#\Newline)))))
-(DEFUN |parse_ws_or_nl| ()
-  (LAMBDA (opossum::OFFSET)
-    (opossum::BUILD-PARSER-FUNCTION "ws_or_nl"
-                                    (opossum::EITHER (|parse_ws|)
-                                                     (|parse_nl|)
-                                                    ))))
-
-(defun |metapeg_action341| (data)
-  (let* ((action-sans-{ (second data))
-        (action-code (coerce
-                      ;; FIXME: fix escapes
-                      (opossum::fix-escape-sequences
-                       (mapcar #'second action-sans-{))
-                      'string))
-        (ctx (fourth (fourth data)))
-        (action-name (make-action-name :ctx ctx)))
-    (store-action opossum:*context*
-                 `(,action-name ,action-code))
-    `(list ':action nil ',action-name)))
-
-(defun |metapeg_action340| (data)  `(match-string ,(char-list-to-string (mapcar #'second (second data))))  )
-
-(defun |metapeg_action339| (data)
-  ;; FIXME: this is character-class matching and needs to use cl-ppcre
-  `(opossum::match-char-class ,(coerce (mapcar #'second (second data)) 'string)))
-
-(defun |metapeg_action338| (data)  (char-list-to-string (first data))  )
-(defun |metapeg_action337| (data)  (third data)  )
-(defun |metapeg_action336| (data)  (declare (ignore data)) `(match-any-char)  )
-(defun |metapeg_action335| (data)  (first data)  )
-(defun |metapeg_action334| (data)  `(negate ,(second data))  )
-(defun |metapeg_action333| (data)  (first data)  )
-(defun |metapeg_action332| (data)  
-       `(,(make-name (first data)))
- )
-(defun |metapeg_action331| (data)  `(match ,(second data))  )
-(defun |metapeg_action330| (data)  `(follow ,(second data))  )
-(defun |metapeg_action329| (data)  (first data)  )
-(defun |metapeg_action328| (data)  (first data)  )
-(defun |metapeg_action327| (data)  `(optional ,(first data))  )
-(defun |metapeg_action326| (data)  `(many1 ,(first data))  )
-(defun |metapeg_action325| (data)  `(many ,(first data))  )
-(defun |metapeg_action324| (data)  (if (or (equal (second data) "") (null (second data)))
-                                            (first data)
-                                            (let ((tail (second (first (second data)))))
-                                                 (if (equal (first tail) 'seq)
-                                                     `(seq ,(first data) ,@(rest tail))
-                                                     `(seq ,(first data) ,tail))))  )
-(defun |metapeg_action323| (data)  (first data)  )
-(defun |metapeg_action322| (data)  
-(let ((tail (fifth data)))
-       (if (equal (first tail) 'either)
-           `(either ,(first data) ,@(rest tail))
-           `(either ,(first data) ,(fifth data))))
- )
-(defun |metapeg_action321| (data)  `(defun ,(make-name (first data)) ()
-        (lambda (offset)
-         (build-parser-function ,(first data) ,(fifth data))))  )
-(defun |metapeg_action320| (data) 
-`(  ,@(second data))
- )
\ No newline at end of file
+;; -*- mode:lisp -*-
+(in-package :opossum-system)
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (declaim (optimize (speed 0) (safety 3) (debug 3))))
+(defun parse-file (f)
+  (let ((opossum:*context* (make-instance 'opossum:context :start-index 0
+                                         :destpkg *package*
+                                         :input (opossum:read-file f))))
+    (funcall (|parse_program|) 0)))
+
+(DEFUN |parse_program| ()
+  (opossum::BUILD-PARSER-FUNCTION "program"
+                                 (opossum::SEQ (opossum::MANY (|parse_ws|))
+                                               (opossum::MANY1
+                                                (|parse_rule|))
+                                               (LIST ':ACTION NIL
+                                                     '|metapeg_action320|))))
+
+(DEFUN |parse_rule| ()
+  (opossum::BUILD-PARSER-FUNCTION "rule"
+                                 (opossum::SEQ (|parse_id|)
+                                               (opossum::MANY (|parse_ws|))
+                                               (opossum::MATCH-STRING "<-")
+                                               (opossum::MANY (|parse_ws|))
+                                               (|parse_ordered-expr-list|)
+                                               (opossum::MANY
+                                                (|parse_ws_or_nl|))
+                                               (LIST ':ACTION NIL
+                                                     '|metapeg_action321|))))
+(DEFUN |parse_ordered-expr-list| ()
+  (opossum::BUILD-PARSER-FUNCTION "ordered-expr-list"
+                                 (opossum::EITHER
+                                  (opossum::SEQ (|parse_expr-list|)
+                                                (opossum::MANY (|parse_ws|))
+                                                (opossum::MATCH-STRING "/")
+                                                (opossum::MANY (|parse_ws|))
+                                                (|parse_ordered-expr-list|)
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action322|))
+                                  (opossum::SEQ (|parse_expr-list|)
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action323|)))))
+(DEFUN |parse_expr-list| ()
+  (opossum::BUILD-PARSER-FUNCTION "expr-list"
+                                 (opossum::SEQ (|parse_expr|)
+                                               (opossum::MANY
+                                                (opossum::SEQ
+                                                 (opossum::MANY1
+                                                  (|parse_ws|))
+                                                 (|parse_expr-list|)))
+                                               (LIST ':ACTION NIL
+                                                     '|metapeg_action324|))))
+(DEFUN |parse_expr| ()
+  (opossum::BUILD-PARSER-FUNCTION "expr"
+                                 (opossum::EITHER
+                                  (opossum::SEQ (|parse_simple-expr|)
+                                                (opossum::MATCH-STRING "*")
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action325|))
+                                  (opossum::SEQ (|parse_simple-expr|)
+                                                (opossum::MATCH-STRING "+")
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action326|))
+                                  (opossum::SEQ (|parse_simple-expr|)
+                                                (opossum::MATCH-STRING "?")
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action327|))
+                                  (opossum::SEQ (|parse_simple-expr|)
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action328|)))))
+(DEFUN |parse_simple-expr| ()
+  (opossum::BUILD-PARSER-FUNCTION "simple-expr"
+                                 (opossum::EITHER
+                                  (opossum::SEQ (|parse_string|)
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action329|))
+                                  (|parse_action|)
+                                  (opossum::SEQ (opossum::MATCH-STRING "&")
+                                                (|parse_simple-expr|)
+                                                (LIST ':ACTION NIL
+                                                      '|metapeg_action330|))
+                                  (opossum::SEQ (opossum::MATCH-STRING "@")
+                                                (|parse_id|)
+                                                (LIST ':action NIL
+                                                      '|metapeg_action331|))
+                                  (opossum::SEQ (|parse_id|)
+                                                (LIST ':action NIL
+                                                      '|metapeg_action332|))
+                                  (opossum::SEQ (|parse_bracketed-rule|)
+                                                (LIST ':action NIL
+                                                      '|metapeg_action333|))
+                                  (opossum::MATCH-STRING "!.")
+                                  (opossum::SEQ (opossum::MATCH-STRING "!")
+                                                (|parse_expr|)
+                                                (LIST ':action NIL
+                                                      '|metapeg_action334|))
+                                  (opossum::SEQ (|parse_character-class|)
+                                                (LIST ':action NIL
+                                                      '|metapeg_action335|))
+                                  (opossum::SEQ (opossum::MATCH-STRING ".")
+                                                (LIST ':action NIL
+                                                      '|metapeg_action336|)))))
+(DEFUN |parse_bracketed-rule| ()
+  (opossum::BUILD-PARSER-FUNCTION "bracketed-rule"
+                                 (opossum::EITHER
+                                  (opossum::MATCH-STRING "()")
+                                  (opossum::SEQ (opossum::MATCH-STRING "(")
+                                                (opossum::MANY (|parse_ws|))
+                                                (|parse_ordered-expr-list|)
+                                                (opossum::MANY (|parse_ws|))
+                                                (opossum::MATCH-STRING ")")
+                                                (LIST ':action NIL
+                                                      '|metapeg_action337|)))))
+(DEFUN |parse_id| ()
+  (opossum::BUILD-PARSER-FUNCTION "id"
+                                 (opossum::SEQ
+                                  (opossum::MANY1
+                                   (opossum::MATCH-CHAR
+                                    '(#\A #\B #\C #\D #\E #\F #\G #\H #\I
+                                      #\J #\K #\L #\M #\N #\O #\P #\Q #\R
+                                      #\S #\T #\U #\V #\W #\X #\Y #\Z #\a
+                                      #\b #\c #\d #\e #\f #\g #\h #\i #\j
+                                      #\k #\l #\m #\n #\o #\p #\q #\r #\s
+                                      #\t #\u #\v #\w #\x #\y #\z #\- #\_)))
+                                  (LIST ':action NIL
+                                        '|metapeg_action338|))))
+(DEFUN |parse_character-class| ()
+  (opossum::BUILD-PARSER-FUNCTION "character-class"
+                                 (opossum::SEQ (opossum::MATCH-STRING "[")
+                                               (opossum::MANY1
+                                                (opossum::SEQ
+                                                 (|parse_not_right_bracket|)
+                                                 (opossum::MATCH-ANY-CHAR)))
+                                               (opossum::MATCH-STRING "]")
+                                               (LIST ':action NIL
+                                                     '|metapeg_action339|))))
+(DEFUN |parse_string| ()
+  (opossum::BUILD-PARSER-FUNCTION "string"
+                                 (opossum::SEQ (opossum::MATCH-CHAR '(#\"))
+                                               (opossum::MANY
+                                                (opossum::SEQ
+                                                 (opossum::NEGATE
+                                                  (opossum::MATCH-CHAR
+                                                   '(#\")))
+                                                 (opossum::MATCH-ANY-CHAR)))
+                                               (opossum::MATCH-CHAR '(#\"))
+                                               (LIST ':action NIL
+                                                     '|metapeg_action340|))))
+(DEFUN |parse_action| ()
+  (opossum::BUILD-PARSER-FUNCTION "action"
+                                 (opossum::SEQ (opossum::MATCH-CHAR '(#\{))
+                                               (opossum::MANY
+                                                (opossum::SEQ
+                                                 (opossum::NEGATE
+                                                  (opossum::MATCH-CHAR
+                                                   '(#\})))
+                                                 (opossum::MATCH-ANY-CHAR)))
+                                               (opossum::MATCH-CHAR '(#\}))
+                                               (LIST ':action NIL
+                                                     '|metapeg_action341|
+                                                     opossum:*context*))))
+(DEFUN |parse_not_right_bracket| ()
+  (opossum::BUILD-PARSER-FUNCTION "not_right_bracket"
+                                 (opossum::NEGATE
+                                  (opossum::MATCH-STRING "]"))))
+(Defun |parse_comment| ()
+  (opossum::BUILD-PARSER-FUNCTION "comment" (opossum::seq
+                                            (opossum::match-char '(#\#))
+                                            (opossum::many
+                                             (opossum::seq
+                                              (opossum::negate
+                                               (opossum::match-char '(#\Newline)))
+                                              (opossum::match-any-char)))
+                                            (opossum::optional
+                                             (opossum::match-char '(#\Newline))))))
+(DEFUN |parse_ws| ()
+  (opossum::BUILD-PARSER-FUNCTION "ws" (opossum::either
+                                       (opossum::MATCH-CHAR '(#\Space #\Tab))
+                                       (|parse_comment|))))
+(DEFUN |parse_nl| ()
+  (opossum::BUILD-PARSER-FUNCTION "nl" (opossum::MATCH-CHAR '(#\Newline))))
+(DEFUN |parse_ws_or_nl| ()
+  (opossum::BUILD-PARSER-FUNCTION "ws_or_nl"
+                                 (opossum::EITHER (|parse_ws|)
+                                                  (|parse_nl|)
+                                                  )))
+
+(defun |metapeg_action341| (data)
+  (let* ((action-sans-{ (second data))
+        (action-code (coerce
+                      ;; FIXME: fix escapes
+                      (opossum::fix-escape-sequences
+                       (mapcar #'second action-sans-{))
+                      'string))
+        (ctx (fourth (fourth data)))
+        (action-name (opossum::make-action-name :ctx ctx)))
+    (opossum::store-action opossum:*context*
+                          `(,action-name ,action-code))
+    `(list ':action nil ',action-name)))
+
+(defun |metapeg_action340| (data)  `(opossum::match-string ,(opossum::char-list-to-string (mapcar #'second (second data))))  )
+
+(defun |metapeg_action339| (data)
+  ;; FIXME: this is character-class matching and needs to use cl-ppcre
+  `(opossum::match-char-class ,(coerce (mapcar #'second (second data)) 'string)))
+
+(defun |metapeg_action338| (data)  (opossum::char-list-to-string (first data))  )
+(defun |metapeg_action337| (data)  (third data)  )
+(defun |metapeg_action336| (data)  (declare (ignore data)) `(opossum::match-any-char)  )
+(defun |metapeg_action335| (data)  (first data)  )
+(defun |metapeg_action334| (data)  `(opossum::negate ,(second data))  )
+(defun |metapeg_action333| (data)  (first data)  )
+(defun |metapeg_action332| (data)  
+       `(,(opossum::make-name (first data)))
+ )
+(defun |metapeg_action331| (data)  `(opossum::match ,(second data))  )
+(defun |metapeg_action330| (data)  `(opossum::follow ,(second data))  )
+(defun |metapeg_action329| (data)  (first data)  )
+(defun |metapeg_action328| (data)  (first data)  )
+(defun |metapeg_action327| (data)  `(opossum::optional ,(first data))  )
+(defun |metapeg_action326| (data)  `(opossum::many1 ,(first data))  )
+(defun |metapeg_action325| (data)  `(opossum::many ,(first data))  )
+(defun |metapeg_action324| (data)  (if (or (equal (second data) "") (null (second data)))
+                                            (first data)
+                                            (let ((tail (second (first (second data)))))
+                                                 (if (equal (first tail) 'seq)
+                                                     `(opossum::seq ,(first data) ,@(rest tail))
+                                                     `(opossum::seq ,(first data) ,tail))))  )
+(defun |metapeg_action323| (data)  (first data)  )
+(defun |metapeg_action322| (data)  
+(let ((tail (fifth data)))
+       (if (equal (first tail) 'either)
+           `(opossum::either ,(first data) ,@(rest tail))
+           `(opossum::either ,(first data) ,(fifth data))))
+ )
+(defun |metapeg_action321| (data)  `(defun ,(opossum::make-name (first data)) ()
+                                    (opossum::build-parser-function ,(first data) ,(fifth data)))  )
+(defun |metapeg_action320| (data) 
+`(  ,@(second data))
+ )
\ No newline at end of file
index 3e8a53f..9fbd230 100644 (file)
   (coerce char-list 'string))
 
 (defmacro build-parser-function (name parser)
-  `(let* ((*context* (clone-ctx *context* ,name))
-         (result (funcall ,parser offset)))
-    (unless result
-      (break "Yow"))
-    (if (ctx-failed-p result)
-       (fail)
-       (succeed *context* (value result) (start-index result) (end-index result)))))
+  `(lambda (offset)
+    (let* ((*context* (clone-ctx *context* ,name))
+          (result (funcall ,parser offset)))
+      (unless result
+       (break "Yow"))
+      (if (ctx-failed-p result)
+         (fail)
+         (succeed *context* (value result) (start-index result) (end-index result))))))
 
 
 \f
@@ -372,12 +373,14 @@ returns the result of that function, or a failure context if none succeeded."
   (make-package (gensym "opossum-parser")
                :documentation (format T "Opossum parser for grammar ~A" grammarfile)))
 
-(defun generate-parser-package (grammarfile dst-package head)
+(defun generate-parser-package (grammarfile dst-package head &key start-rule (parse-file-fun #'opossum:parse-file))
   "Create functions to parse using GRAMMARFILE in DST-PACKAGE, starting ar rule named HEAD.
 DST-PACKAGE will contain the 3 functions PARSE-STRING, PARSE-FILE and PARSE-STREAM as exported entrypoints."
+  (declare (ignore start-rule))
+  (error "This is broken and needs to be merged with g-p-f.")
   (let ((*package* dst-package))
     (multiple-value-bind (form actions)
-       (opossum:parse-file grammarfile)
+       (funcall parse-file-fun grammarfile)
       (format *debug-io* "Injecting parser functions into ~A~%" dst-package)
       (loop :for aform :in form
            :do (progn
@@ -415,11 +418,11 @@ DST-PACKAGE will contain the 3 functions PARSE-STRING, PARSE-FILE and PARSE-STRE
          (when (char= #\Newline (char code (1- (length code))))
            (1+ (position #\Newline code :from-end T :test #'char/=)))))
   
-(defun generate-parser-file (grammarfile dst-package dst-file &optional start-rule)
+(defun generate-parser-file (grammarfile dst-package dst-file &key start-rule (parse-file-fun #'opossum:parse-file))
   "Create lisp code in DST-FILE that can be loaded to yield functions to parse using GRAMMARFILE in DST-PACKAGE.
 DST-PACKAGE will contain the 3 functions PARSE-STRING, PARSE-FILE and PARSE-STREAM as exported entrypoints."
   (let ((*package* dst-package))
-    (let ((result (opossum:parse-file grammarfile)))
+    (let ((result (funcall parse-file-fun grammarfile)))
       ;; FIXME: check for complete parse
       (let ((*context* result))        ;; routines in pegutils.lisp expect *context* to be bound properly
        (let ((forms (transform (value result)))