Changeset trunk,12 for trunk/parse3.lisp


Ignore:
Timestamp:
06/21/2007 05:15:55 AM (19 years ago)
Author:
dsowen
revision id:
svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:12
Message:

Added some documentation to parse3.
Modified csv example for better tree output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/parse3.lisp

    r11 r12  
     1(in-package #:dso-parse)
     2
     3
     4
    15(defmacro while (cond &body body)
    26  `(do ()
     
    610(defmacro if-matches-parser (input parser (next match)
    711                             &body (&optional (then t) else))
     12  "Matches if the function named by PARSER accepts the input.  Such a
     13parser must return T, the remaining unmatched input, and the accepted
     14input as values (in that order), or NIL if matching fails.
     15
     16NOTE: A parser that accepts a portion of input but does not wish to
     17emit it may do so.  For example, a parser may return the values T,
     18\"blah....\", NIL."
    819  (declare (symbol parser next match))
    920  (with-gensyms (ok)
     
    1324(defmacro if-matches-char (input char (next match)
    1425                           &body (&optional (then t) else))
     26  "Matches if the first character of INPUT is CHAR."
    1527  (declare (symbol next match)
    1628           (character char))
     
    2335(defmacro if-matches-string (input string (next match)
    2436                             &body (&optional (then t) else))
     37  "Matches if INPUT is prefixed by STRING."
    2538  (declare (symbol next match)
    2639           (string string))
     
    3548(defmacro if-matches-regex (input regex (next match)
    3649                            &body (&optional (then t) else))
     50  "Matches if REGEX matches the beginning of INPUT (REGEX is modified
     51to anchor to the beginning automatically)."
    3752  (declare (string regex)
    3853           (symbol next match))
     
    5166  (declare (symbol next match)
    5267           (list alts))
     68  "Matches if any of ALTS match INPUT.  The first rule in ALTS that
     69matches is used to consume input and build the parse tree."
    5370  (if alts
    5471      `(if-matches ,input ,(first alts) (,next ,match)
     
    6178(defmacro if-matches-sequence (input seq (next match)
    6279                               &body (&optional (then t) else))
     80  "Matches if all of the rules in SEQ match INPUT in sequence (ie, the
     81second rule matches what is left of the input after the first rule has
     82matched, and so on)."
    6383  (destructuring-bind (head . tail) seq
    6484    (if tail
     
    7898(defmacro if-matches-eqcount (input count rule (next match)
    7999                              &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
     102WARNING: ELSE code executes in an anonymous block!"
    81103  (declare ((or null (integer 0)) count)
    82104           (symbol next match))
     
    95117(defmacro if-matches-maxcount (input count rule (next match)
    96118                               &body (&optional (then t) else))
     119  "Always matches INPUT, but attempts to match RULE up to COUNT times
     120in sequence (ie, RULE is matched against INPUT from 0 to COUNT times).
     121If COUNT is NIL, RULE is matched as often as it will."
    97122  (declare ((or null (integer 0)) count)
    98123           (symbol next match)
     
    114139(defmacro if-matches-count (input mincount maxcount rule (next match)
    115140                            &body (&optional (then t) else))
     141  "Matches RULE against INPUT from MINCOUNT to MAXCOUNT times
     142sequentially.  If MINCOUNT is NIL, it is treated as 0.  If MAXCOUNT is
     143NIL, RULE is matched as often as it will (after the MINCOUNT is
     144satisfied)."
    116145  (when (and maxcount mincount) (setf maxcount (- maxcount mincount)))
    117146  (with-gensyms (next2 match2)
Note: See TracChangeset for help on using the changeset viewer.