Skip to content

Instantly share code, notes, and snippets.

@jartur
Created June 9, 2010 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jartur/431147 to your computer and use it in GitHub Desktop.
Save jartur/431147 to your computer and use it in GitHub Desktop.
(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