|
|
@ -13,10 +13,10 @@
|
|
|
|
(check-true (token? (token 'A-TOKEN-STRUCT "hi")))
|
|
|
|
(check-true (token? (token 'A-TOKEN-STRUCT "hi")))
|
|
|
|
(check-false (token? 42)))
|
|
|
|
(check-false (token? 42)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (tokenize port)
|
|
|
|
(define (make-tokenizer port)
|
|
|
|
(port-count-lines! port)
|
|
|
|
(port-count-lines! port)
|
|
|
|
(define (next-token)
|
|
|
|
(define (next-token)
|
|
|
|
(define our-lexer
|
|
|
|
(define jsonic-lexer
|
|
|
|
(lexer
|
|
|
|
(lexer
|
|
|
|
[(eof) eof]
|
|
|
|
[(eof) eof]
|
|
|
|
[(from/to "//" "\n") (next-token)]
|
|
|
|
[(from/to "//" "\n") (next-token)]
|
|
|
@ -33,22 +33,24 @@
|
|
|
|
#:column (col lexeme-start)
|
|
|
|
#:column (col lexeme-start)
|
|
|
|
#:span (- (pos lexeme-end)
|
|
|
|
#:span (- (pos lexeme-end)
|
|
|
|
(pos lexeme-start)))]))
|
|
|
|
(pos lexeme-start)))]))
|
|
|
|
(our-lexer port))
|
|
|
|
(jsonic-lexer port))
|
|
|
|
next-token)
|
|
|
|
next-token)
|
|
|
|
(provide (contract-out
|
|
|
|
(provide (contract-out
|
|
|
|
[tokenize (input-port? . -> . (-> token?))]))
|
|
|
|
[make-tokenizer (input-port? . -> . (-> token?))]))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (apply-tokenizer tokenize "// comment\n") empty)
|
|
|
|
|
|
|
|
(check-equal?
|
|
|
|
(check-equal?
|
|
|
|
(apply-tokenizer tokenize "@$ (+ 6 7) $@")
|
|
|
|
(apply-tokenizer-maker make-tokenizer "// comment\n")
|
|
|
|
|
|
|
|
empty)
|
|
|
|
|
|
|
|
(check-equal?
|
|
|
|
|
|
|
|
(apply-tokenizer-maker make-tokenizer "@$ (+ 6 7) $@")
|
|
|
|
(list (token 'SEXP-TOK " (+ 6 7) "
|
|
|
|
(list (token 'SEXP-TOK " (+ 6 7) "
|
|
|
|
#:position 3
|
|
|
|
#:position 3
|
|
|
|
#:line 1
|
|
|
|
#:line 1
|
|
|
|
#:column 2
|
|
|
|
#:column 2
|
|
|
|
#:span 9)))
|
|
|
|
#:span 9)))
|
|
|
|
(check-equal?
|
|
|
|
(check-equal?
|
|
|
|
(apply-tokenizer tokenize "hi")
|
|
|
|
(apply-tokenizer-maker make-tokenizer "hi")
|
|
|
|
(list (token 'CHAR-TOK "h"
|
|
|
|
(list (token 'CHAR-TOK "h"
|
|
|
|
#:position 1
|
|
|
|
#:position 1
|
|
|
|
#:line 1
|
|
|
|
#:line 1
|
|
|
|