Changeset trunk,27 for trunk/csv.lisp


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

More improvements to CSV parser.
Adjusted for speed fix in lexer.
Cons less.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/csv.lisp

    r26 r27  
    2323  ("." illegal))
    2424
    25 (defun lex-all-csv (input &optional tokens)
    26   (format t "~&Lexing '~A...'~%" (subseq input 0 40))
    27   (multiple-value-bind (class image left) (lex-csv input)
    28     (cond
    29       ((and class (eq class 'illegal))
    30        (princ "oops")
    31        (error "Illegal input"))
    32       (class
    33        (lex-all-csv left (cons (list class image) tokens)))
    34       (t
    35        (nreverse tokens)))))
     25(defun lex-all-csv (input)
     26  (labels ((lex-all (start tokens)
     27             (multiple-value-bind (class image next-offset)
     28                 (lex-csv input start)
     29               (cond
     30                 ((and class (eq class 'illegal))
     31                  (error "Illegal input"))
     32                 (class
     33                  (lex-all next-offset (cons (cons class image) tokens)))
     34                 (t
     35                  (nreverse tokens))))))
     36    (lex-all 0 nil)))
    3637
    3738(defmacro defmatcher (class)
     
    3940    `(defun ,fn-sym (token-list)
    4041      (when token-list
    41         (destructuring-bind (class image) (first token-list)
     42        (destructuring-bind (class . image) (first token-list)
    4243          (when (eq class ',class)
    4344            (values t (rest token-list) (list image))))))))
     
    5253  (file (+ row))
    5354  (row (t-value (* row-rest) (= t-newline))
    54        (lambda (row)
    55          (mapcar #'car (cons (first row) (mapcar #'second (second row))))))
     55       (lambda (row) (cons (caar row) (mapcar #'second (second row)))))
    5656  (row-rest ((= t-comma) t-value) car))
    5757
Note: See TracChangeset for help on using the changeset viewer.