Changeset 14866 in project


Ignore:
Timestamp:
06/03/09 07:37:08 (10 years ago)
Author:
Ivan Raikov
Message:

lexgen doc updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/lexgen

    r14809 r14866  
    3636removed from the list of input elements.
    3737
    38 <procedure>(seq MATCHER-LIST) => MATCHER</procedure>
     38<procedure>(seq MATCHER1 MATCHER2) => MATCHER</procedure>
    3939
    4040{{seq}} builds a matcher that matches a sequence of patterns.
    4141
    42 <procedure>(bar MATCHER-LIST) => MATCHER</procedure>
     42<procedure>(bar MATCHER1 MATCHER2) => MATCHER</procedure>
    4343
    44 {{bar}} matches any of a list of patterns. It's analogous to a series
    45 of patterns separated by {{|}} in traditional regular expressions.
     44{{bar}} matches either of two patterns. It's analogous to patterns
     45separated by {{|}} in traditional regular expressions.
    4646
    4747<procedure>(star MATCHER) => MATCHER</procedure>
     
    4949{{star}} is an implementation of the Kleene closure. It is analogous
    5050to {{*}} in traditional regular expressions.
    51 
    5251
    5352==== Convenience procedures
     
    9695
    9796
    98 <procedure>(lex MATCHER STRING) => CHAR-LIST</procedure>
     97<procedure>(lex MATCHER ERROR STRING) => CHAR-LIST</procedure>
    9998
    10099{{lex}} takes a pattern and a string, turns the string into a list of
    101100streams (containing one stream), applies the pattern, and returns the
    102 longest match.
     101longest match. Argument {{ERROR}} is a single-argument procedure
     102called when the pattern does not match anything.
    103103
    104104=== Examples
    105105
    106   (define a-pat (tok #\a (try char=?)))
    107   (define b-pat (tok #\b (try char=?)))
    108   (define a-then-b-pat (seq (list a-pat b-pat)))
    109   (define a-or-b-pat (seq (list a-pat b-pat)))
    110   (define a-star-pat (star a-pat))
    111  
    112   (define abc-stream (list `(() ,(string->list "abc"))))
    113 
    114   (print (a-pat abc-stream))
    115   (print (b-pat abc-stream))
    116   (print (a-then-b-pat abc-stream))
    117   (print (a-or-b-pat abc-stream))
    118   (print (a-star-pat abc-stream))
    119 
    120106  ;; A pattern to match floating point numbers.
    121107  ;; "-"?(([0-9]+(\\.[0-9]+)?)|(\\.[0-9]+))([eE][+-]?[0-9]+)?
     108
     109  (define (err s)
     110    (print "lexical error on stream: " s)
     111    (list))
    122112
    123113  (define numpat
     
    129119           (sign         (opt (char #\-)) ))     
    130120     (seq `(,sign ,(seq `(,significand ,(opt exp)))))))
    131   (print (lex numpat "3.45e-6"))
     121
     122  (print (lex numpat err "3.45e-6"))
    132123
    133124=== Requires
     
    137128=== Version History
    138129
     130* 2.0 Core procedures rewritten in continuation-passing style
    139131* 1.5 Using (require-extension srfi-1)
    140132* 1.4 Ported to Chicken 4
Note: See TracChangeset for help on using the changeset viewer.