Changeset trunk,12 for trunk/parse3.lisp
- Timestamp:
- 06/21/2007 05:15:55 AM (19 years ago)
- revision id:
- svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:12
- File:
-
- 1 edited
-
trunk/parse3.lisp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/parse3.lisp
r11 r12 1 (in-package #:dso-parse) 2 3 4 1 5 (defmacro while (cond &body body) 2 6 `(do () … … 6 10 (defmacro if-matches-parser (input parser (next match) 7 11 &body (&optional (then t) else)) 12 "Matches if the function named by PARSER accepts the input. Such a 13 parser must return T, the remaining unmatched input, and the accepted 14 input as values (in that order), or NIL if matching fails. 15 16 NOTE: A parser that accepts a portion of input but does not wish to 17 emit it may do so. For example, a parser may return the values T, 18 \"blah....\", NIL." 8 19 (declare (symbol parser next match)) 9 20 (with-gensyms (ok) … … 13 24 (defmacro if-matches-char (input char (next match) 14 25 &body (&optional (then t) else)) 26 "Matches if the first character of INPUT is CHAR." 15 27 (declare (symbol next match) 16 28 (character char)) … … 23 35 (defmacro if-matches-string (input string (next match) 24 36 &body (&optional (then t) else)) 37 "Matches if INPUT is prefixed by STRING." 25 38 (declare (symbol next match) 26 39 (string string)) … … 35 48 (defmacro if-matches-regex (input regex (next match) 36 49 &body (&optional (then t) else)) 50 "Matches if REGEX matches the beginning of INPUT (REGEX is modified 51 to anchor to the beginning automatically)." 37 52 (declare (string regex) 38 53 (symbol next match)) … … 51 66 (declare (symbol next match) 52 67 (list alts)) 68 "Matches if any of ALTS match INPUT. The first rule in ALTS that 69 matches is used to consume input and build the parse tree." 53 70 (if alts 54 71 `(if-matches ,input ,(first alts) (,next ,match) … … 61 78 (defmacro if-matches-sequence (input seq (next match) 62 79 &body (&optional (then t) else)) 80 "Matches if all of the rules in SEQ match INPUT in sequence (ie, the 81 second rule matches what is left of the input after the first rule has 82 matched, and so on)." 63 83 (destructuring-bind (head . tail) seq 64 84 (if tail … … 78 98 (defmacro if-matches-eqcount (input count rule (next match) 79 99 &body (&optional (then t) else)) 80 "WARNING: ELSE code executes in an anonymous block!" 100 "Matches if RULE matches INPUT exactly COUNT times in sequence. 101 102 WARNING: ELSE code executes in an anonymous block!" 81 103 (declare ((or null (integer 0)) count) 82 104 (symbol next match)) … … 95 117 (defmacro if-matches-maxcount (input count rule (next match) 96 118 &body (&optional (then t) else)) 119 "Always matches INPUT, but attempts to match RULE up to COUNT times 120 in sequence (ie, RULE is matched against INPUT from 0 to COUNT times). 121 If COUNT is NIL, RULE is matched as often as it will." 97 122 (declare ((or null (integer 0)) count) 98 123 (symbol next match) … … 114 139 (defmacro if-matches-count (input mincount maxcount rule (next match) 115 140 &body (&optional (then t) else)) 141 "Matches RULE against INPUT from MINCOUNT to MAXCOUNT times 142 sequentially. If MINCOUNT is NIL, it is treated as 0. If MAXCOUNT is 143 NIL, RULE is matched as often as it will (after the MINCOUNT is 144 satisfied)." 116 145 (when (and maxcount mincount) (setf maxcount (- maxcount mincount))) 117 146 (with-gensyms (next2 match2)
Note: See TracChangeset
for help on using the changeset viewer.
