Changeset 14868 in project


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

added lst combinator to lexgen

Location:
release/4/lexgen/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/lexgen/trunk/lexgen.scm

    r14865 r14868  
    4343  ( tok seq star bar
    4444    try pass pos opt char
    45     set range lit
     45    set range lst lit
    4646    longest lex )
    4747
     
    151151            (char->integer a) (char->integer b)))))
    152152
     153;; Matches a consecutive list of patterns
     154
     155(define (lst ps)
     156  (let ((ps (reverse ps)))
     157    (let loop ((ps (cdr ps)) (p1 (car ps)))
     158      (cond ((null? ps) p1)
     159            ((null? (cdr ps))    (seq (car ps) p1))
     160            (else (loop (cdr ps) (seq (car ps) p1)))))))
     161 
    153162;; Matches a literal string s
    154163
    155164(define (lit s)
    156165  (let ((f (lambda (t) (tok t (try char=?)))))
    157     (seq (map f (if (string? s) (string->list s) s)))))
     166    (lst (map f (if (string? s) (string->list s) s)))))
    158167
    159168
  • release/4/lexgen/trunk/lexgen.setup

    r14865 r14868  
    1717
    1818  ;; Assoc list with properties for your extension:
    19   '((version 2.0)
     19  '((version 2.1)
    2020    (documentation "lexgen.html")
    2121    ))
  • release/4/lexgen/trunk/tests/run.scm

    r14865 r14868  
    1212(define a-b-opt-pat (seq a-pat (opt b-pat)))
    1313(define a-star-b-opt-pat (seq (star a-pat) (opt b-pat)))
     14(define aabac-pat (lit "aabac"))
    1415 
    1516(define abc-stream (list `(() ,(string->list "abc"))))
     
    7172                   `(((#\b #\a #\a) (#\a #\c)) )
    7273                   (a-star-b-opt-pat identity err aabac-stream))
     74
     75            (test (sprintf "match literal string ~S" "aabac")
     76                   `(((#\c #\a #\b #\a #\a) ()) )
     77                   (aabac-pat identity err aabac-stream))
    7378
    7479            )
Note: See TracChangeset for help on using the changeset viewer.