improve jsonic coloring lexer

dev-srcloc
Matthew Butterick 8 years ago
parent 2ae113481c
commit dd67b321d5

@ -6,8 +6,18 @@
(provide drracket-lexer)
(define drracket-lexer
(let ([in-racket-expr? #f])
(define in-racket-expr? #f)
(define (at-racket-boundary? input-port)
(equal? (peek-string 2 0 input-port) "$@"))
(module+ test
(require rackunit)
(check-true (at-racket-boundary? (open-input-string "$@foo")))
(check-false (at-racket-boundary? (open-input-string "foo$@"))))
(define (drracket-lexer input-port)
(define this-lexer
(lexer
[(eof) (values lexeme 'eof #f #f #f)]
["@$" (begin
@ -19,6 +29,7 @@
[(:seq "//" (:* (char-complement #\newline)))
(values lexeme 'comment #f (position-offset start-pos) (position-offset end-pos))]
[any-char
(if in-racket-expr?
(racket-lexer (transplant-input-port (open-input-string lexeme) #f (position-offset start-pos)))
(values lexeme 'string #f (position-offset start-pos) (position-offset end-pos)))])))
(values lexeme 'string #f (position-offset start-pos) (position-offset end-pos))]))
(if (and in-racket-expr? (not (at-racket-boundary? input-port)))
(racket-lexer input-port)
(this-lexer input-port)))
Loading…
Cancel
Save