You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket/br/demo/jsonic/main.rkt

41 lines
1.3 KiB
Racket

#lang at-exp br/quicklang
(require "parser.rkt")
(module+ reader
(define (read-syntax path port)
(define parse-tree (parse path (tokenize port)))
(define module-datum `(module bf-mod br/demo/jsonic/expander
,parse-tree))
(datum->syntax #f module-datum))
(provide read-syntax get-info))
(require parser-tools/lex parser-tools/lex-sre brag/support)
(define (tokenize port)
(define (next-token)
(define our-lexer
(lexer
[(eof) eof]
;; (char-complement "\n") means any char but "\n"
;; (complement "\n") means any whole string except "\n"
[(seq "//" (* (char-complement "\n"))) (next-token)]
["@$" (token 'OPEN lexeme)]
["$@" (token 'CLOSE lexeme)]
[any-char (token 'CHAR lexeme)]))
(our-lexer port))
next-token)
(define (get-info . _)
(λ (key default)
(case key
[(color-lexer)
(really-dynamic-require 'br/demo/jsonic/drracket-lexer 'drracket-lexer (λ () #f))]
[(drracket:indentation)
(really-dynamic-require 'br/demo/jsonic/drracket-indenter 'drracket-indenter (λ () #f))]
[else default])))
(define (test-tokenize str)
(define ip (open-input-string str))
(define token-producer (tokenize ip))
(for/list ([token (in-producer token-producer eof)])
token))