Changeset 26862 in project


Ignore:
Timestamp:
06/08/12 08:03:56 (9 years ago)
Author:
Ivan Raikov
Message:

ersatz: added a lexer generator with user-defined strings for begin/end block

Location:
release/4/ersatz/trunk
Files:
1 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/ersatz/trunk/ersatz.meta

    r26852 r26862  
    55 ; List here all the files that should be bundled as part of your egg. 
    66
    7  (files "ersatz.meta" "ersatz.setup"  "ersatz.grm" "ersatz.l"
     7 (files "ersatz.meta" "ersatz.setup"  "ersatz.grm" "make-ersatz-lexer.scm"
    88        "ersatz-lib.scm" "runtime.scm" "eval.scm" "parser.scm"
    99         )
  • release/4/ersatz/trunk/ersatz.setup

    r26861 r26862  
    1212        (run (csi -s ersatz.grm)))
    1313
     14       ("ersatz.l" ("make-ersatz-lexer.scm")
     15        (run (csi -n -e "'(include \"make-ersatz-lexer.scm\") (make-ersatz-lexer (open-output-file \"ersatz.l\"))'")))
     16       
    1417       ("ersatz.l.scm" ("ersatz.l")
    1518        (run (csi -n -R silex
  • release/4/ersatz/trunk/parser.scm

    r26861 r26862  
    2929    ((tok ln t l) (make-lexical-token (quasiquote t) ln l))
    3030    ))
     31
     32
     33(define-syntax lexer-yyungetcn
     34  (syntax-rules ()
     35    ((lexer-ungetcn i ungetc)
     36     (let recur ((i i))
     37       (if (positive? i)
     38           (begin (ungetc) (recur (- i 1))))
     39       ))
     40    ))
     41
     42
     43(define-syntax lexer-lookahead
     44  (syntax-rules ()
     45    ((lexer-lookahead c str n getc ungetc)
     46     (and (char=? (string-ref str 0) c)
     47          (let recur ((i 1))
     48            (if (< i n)
     49                (if (char=? (string-ref str i) (getc))
     50                    (recur (+ 1 i))
     51                 (begin (lexer-yyungetcn i ungetc) #f))
     52                #t))
     53          ))
     54    ))
     55       
    3156
    3257(define-datatype lexer-mode lexer-mode?
     
    103128(define lexer-error error)
    104129
    105 
    106 
    107 
     130(include "ersatz.l.scm")
    108131
    109132(define (make-parse-error loc)
     
    124147
    125148
    126 (include "ersatz.l.scm")
    127149(include "ersatz.grm.scm")
    128150
Note: See TracChangeset for help on using the changeset viewer.