- Timestamp:
- 06/18/2007 03:47:51 PM (19 years ago)
- revision id:
- svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:9
- Location:
- trunk
- Files:
-
- 2 edited
-
csv.lisp (modified) (2 diffs)
-
parse3.lisp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/csv.lisp
r8 r9 4 4 (import 'parse::with-gensyms) 5 5 (import 'cl-ppcre:scan) 6 (load " lisp/parse/parse3")6 (load "parse/parse3") 7 7 8 8 (defmacro defparser (name rule) … … 20 20 (defgrammar 21 21 (file (+ row)) 22 (row (value (* ( comma value)) #\Newline))22 (row (value (* ((= comma) value)) (= #\Newline))) 23 23 (comma #\,) 24 24 (value (? (/ dquoted-value squoted-value raw-value))) -
trunk/parse3.lisp
r7 r9 17 17 `(if (and (string/= "" ,input) (char= ,char (char ,input 0))) 18 18 (let ((,next (substring ,input :start 1)) 19 (,match ,char))19 (,match '(,char))) 20 20 ,then) 21 21 ,else)) 22 22 23 23 (defmacro if-matches-string (input string (next match) 24 &body (&optional (then t) else))24 &body (&optional (then t) else)) 25 25 (declare (symbol next match) 26 26 (string string)) 27 27 (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))) 29 30 (let ((,next (substring ,input :start ,len)) 30 (,match ,string))31 (,match '(,string))) 31 32 ,then) 32 33 ,else))) … … 42 43 (if ,start 43 44 (let ((,next (substring ,input :start ,end)) 44 (,match ( substring ,input :end ,end)))45 (,match (list (substring ,input :end ,end)))) 45 46 ,then) 46 47 ,else))))) … … 59 60 60 61 (defmacro if-matches-sequence (input seq (next match) 61 &body (&optional (then t) else))62 &body (&optional (then t) else)) 62 63 (destructuring-bind (head . tail) seq 63 64 (if tail … … 65 66 `(if-matches ,input ,head (,head-next ,head-match) 66 67 (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) 70 71 ,else)) 71 72 (with-gensyms (head-match) 72 73 `(if-matches ,input ,head (,next ,head-match) 73 (let ((,match (cons ,head-match nil)))74 (let ((,match ,head-match)) 74 75 ,then) 75 76 ,else))))) … … 91 92 ,then)))) 92 93 93 ;;; This doesn't quite work yet.94 94 (defmacro if-matches-maxcount (input count rule (next match) 95 95 &body (&optional (then t) else)) … … 125 125 126 126 (defmacro if-matches-required (input rule (next match) 127 &body (&optional (then t) else))127 &body (&optional (then t) else)) 128 128 `(if-matches ,input ,rule (,(gensym) ,(gensym)) 129 129 (let ((,next ,input) … … 133 133 134 134 (defmacro if-matches-forbidden (input rule (next match) 135 &body (&optional (then t) else))135 &body (&optional (then t) else)) 136 136 `(if-matches ,input ,rule (,(gensym) ,(gensym)) 137 137 ,else … … 139 139 (,match nil)) 140 140 ,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))) 141 149 142 150 (defmacro if-matches (input rule (next match) &body (&optional (then t) else)) … … 166 174 (! (destructuring-bind (sub) tail 167 175 `(if-matches-forbidden ,input ,sub (,next ,match) ,then ,else))) 176 (= (destructuring-bind (sub) tail 177 `(if-matches-only ,input ,sub (,next ,match) ,then ,else))) 168 178 (t `(if-matches-sequence ,input ,rule (,next ,match) 169 179 ,then ,else)))))))
Note: See TracChangeset
for help on using the changeset viewer.
