Changeset trunk,9 for trunk


Ignore:
Timestamp:
06/18/2007 03:47:51 PM (19 years ago)
Author:
dsowen
revision id:
svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:9
Message:

Added match-only matcher (consumes but doesn't add to tree).
Fixed: String-matching against short input would fail.
In process of changing tree representation (to match original parse.lisp).
Re-indenting GNU-Emacs--style.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/csv.lisp

    r8 r9  
    44(import 'parse::with-gensyms)
    55(import 'cl-ppcre:scan)
    6 (load "lisp/parse/parse3")
     6(load "parse/parse3")
    77
    88(defmacro defparser (name rule)
     
    2020(defgrammar
    2121  (file (+ row))
    22   (row (value (* (comma value)) #\Newline))
     22  (row (value (* ((= comma) value)) (= #\Newline)))
    2323  (comma #\,)
    2424  (value (? (/ dquoted-value squoted-value raw-value)))
  • trunk/parse3.lisp

    r7 r9  
    1717  `(if (and (string/= "" ,input) (char= ,char (char ,input 0)))
    1818    (let ((,next (substring ,input :start 1))
    19           (,match ,char))
     19          (,match '(,char)))
    2020      ,then)
    2121    ,else))
    2222
    2323(defmacro if-matches-string (input string (next match)
    24                                    &body (&optional (then t) else))
     24                             &body (&optional (then t) else))
    2525  (declare (symbol next match)
    2626           (string string))
    2727  (let ((len (length string)))
    28     `(if (string= ,string (substring ,input :length ,len))
     28    `(if (and (>= (length ,input) ,len)
     29          (string= ,string (substring ,input :length ,len)))
    2930      (let ((,next (substring ,input :start ,len))
    30             (,match ,string))
     31            (,match '(,string)))
    3132        ,then)
    3233      ,else)))
     
    4243        (if ,start
    4344            (let ((,next (substring ,input :start ,end))
    44                   (,match (substring ,input :end ,end)))
     45                  (,match (list (substring ,input :end ,end))))
    4546              ,then)
    4647            ,else)))))
     
    5960
    6061(defmacro if-matches-sequence (input seq (next match)
    61                                      &body (&optional (then t) else))
     62                               &body (&optional (then t) else))
    6263  (destructuring-bind (head . tail) seq
    6364    (if tail
     
    6566          `(if-matches ,input ,head (,head-next ,head-match)
    6667            (if-matches-sequence ,head-next ,tail (,next ,tail-match)
    67              (let ((,match (cons ,head-match ,tail-match)))
    68                ,then)
    69              ,else)
     68              (let ((,match (append ,head-match ,tail-match)))
     69                ,then)
     70              ,else)
    7071            ,else))
    7172        (with-gensyms (head-match)
    7273          `(if-matches ,input ,head (,next ,head-match)
    73             (let ((,match (cons ,head-match nil)))
     74            (let ((,match ,head-match))
    7475              ,then)
    7576            ,else)))))
     
    9192        ,then))))
    9293
    93 ;;; This doesn't quite work yet.
    9494(defmacro if-matches-maxcount (input count rule (next match)
    9595                                     &body (&optional (then t) else))
     
    125125
    126126(defmacro if-matches-required (input rule (next match)
    127                                      &body (&optional (then t) else))
     127                               &body (&optional (then t) else))
    128128  `(if-matches ,input ,rule (,(gensym) ,(gensym))
    129129    (let ((,next ,input)
     
    133133
    134134(defmacro if-matches-forbidden (input rule (next match)
    135                                       &body (&optional (then t) else))
     135                                &body (&optional (then t) else))
    136136  `(if-matches ,input ,rule (,(gensym) ,(gensym))
    137137    ,else
     
    139139          (,match nil))
    140140      ,then)))
     141
     142(defmacro if-matches-only (input rule (next match)
     143                           &body (&optional (then t) else))
     144  (with-gensyms (match2)
     145    `(if-matches ,input ,rule (,next ,match2)
     146      (let ((,match nil))
     147        ,then)
     148      ,else)))
    141149
    142150(defmacro if-matches (input rule (next match) &body (&optional (then t) else))
     
    166174         (! (destructuring-bind (sub) tail
    167175              `(if-matches-forbidden ,input ,sub (,next ,match) ,then ,else)))
     176         (= (destructuring-bind (sub) tail
     177              `(if-matches-only ,input ,sub (,next ,match) ,then ,else)))
    168178         (t `(if-matches-sequence ,input ,rule (,next ,match)
    169179              ,then ,else)))))))
Note: See TracChangeset for help on using the changeset viewer.