Created
June 9, 2010 06:59
-
-
Save jartur/431147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax (lexer-src-pos-kw s) | |
(define (char->ci-pattern c) | |
(list ':or (char-downcase c) (char-upcase c))) | |
(define (string->ci-pattern s) | |
(if (symbol? s) | |
(string->ci-pattern (symbol->string s)) | |
(cons ':: (map char->ci-pattern (string->list s))))) | |
(define (token-name s) | |
(if (symbol? s) | |
(token-name (symbol->string s)) | |
(string-append "token-" (string-upcase s)))) | |
(define (token-names l) | |
(map (λ (s) (string->symbol (token-name s))) (syntax->datum l))) | |
(syntax-case s () | |
((_ (kw ...) ((sm n) ...) forms ...) | |
(with-syntax ([(seq ...) (map string->ci-pattern | |
(syntax->datum (syntax (kw ...))))] | |
[(token-x ...) (token-names (syntax (kw ...)))] | |
[(token-n ...) (token-names (syntax (n ...)))]) | |
(syntax (lexer-src-pos | |
(seq (make-kw-tk token-x lexeme))... | |
(sm (make-kw-tk token-n lexeme))... | |
forms ...)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment