Changeset trunk,6 for trunk


Ignore:
Timestamp:
06/08/2007 06:37:29 PM (19 years ago)
Author:
dsowen
revision id:
svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:6
Message:

Fleshed out the regex macro (untested).
Added a macro to handle symbols embedded in rules.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/parse2.lisp

    r5 r6  
    5151
    5252(defmacro with-regex-parser ((name regex) &body body)
    53   (error "Not implemented."))
     53  (declare ((symbol name)
     54            (string regex)))
     55  (follow "with-regex-parser~%")
     56  (let ((regex2 `(:sequence (:flags) :start-anchor
     57                  (:register (:regex ,regex)))))
     58    (with-gensyms (input start end)
     59      `(flet ((,name (,input)
     60               ,(format nil "Regex parser for ~S." regex)
     61               (declare (string ,input))
     62               (multiple-value-bind (,start ,end) (scan (quote ,regex2) ,input)
     63                 (when ,start
     64                   (values
     65                    t
     66                    (substring ,input :start ,end)
     67                    (list (substring ,input :end ,end)))))))))))
     68
     69(defmacro with-user-parser ((name parser) &body body)
     70  (declare (symbol name parser))
     71  (follow "with-user-parser~%")
     72  (with-gensyms (input)
     73    `(flet ((,name (,input)
     74             ,(format nil "User parser for ~S." parser)
     75             (,parser ,input)))
     76      (declare (inline ,name))
     77      ,@body)))
    5478
    5579(defmacro with-sequence-parser% ((name seq) &body body)
     
    181205    (character `(with-character-parser (,name ,rule) ,@body))
    182206    (string `(with-string-parser (,name ,rule) ,@body))
     207    (symbol `(with-user-parser (,name ,rule) ,@body))
    183208    (list
    184209     (destructuring-bind (head . tail) rule
Note: See TracChangeset for help on using the changeset viewer.