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.
38 lines
1.3 KiB
Racket
38 lines
1.3 KiB
Racket
8 years ago
|
#lang br
|
||
8 years ago
|
(require brag/support
|
||
|
syntax-color/racket-lexer)
|
||
8 years ago
|
|
||
8 years ago
|
(define in-racket-expr? #f)
|
||
|
|
||
8 years ago
|
(define/contract (color-jsonic port)
|
||
|
(input-port? . -> .
|
||
|
(values (or/c string? eof-object?)
|
||
|
symbol?
|
||
|
(or/c symbol? #f)
|
||
|
(or/c exact-positive-integer? #f)
|
||
|
(or/c exact-positive-integer? #f)))
|
||
8 years ago
|
(define jsonic-lexer
|
||
8 years ago
|
(lexer
|
||
|
[(eof) (values lexeme 'eof #f #f #f)]
|
||
|
["@$" (begin
|
||
|
(set! in-racket-expr? #t)
|
||
8 years ago
|
(values lexeme 'parenthesis '|(|
|
||
|
(pos lexeme-start) (pos lexeme-end)))]
|
||
8 years ago
|
["$@" (begin
|
||
|
(set! in-racket-expr? #f)
|
||
8 years ago
|
(values lexeme 'parenthesis '|)|
|
||
|
(pos lexeme-start) (pos lexeme-end)))]
|
||
|
[(from/to "//" "\n")
|
||
|
(values lexeme 'comment #f (pos lexeme-start) (pos lexeme-end))]
|
||
8 years ago
|
[any-char
|
||
8 years ago
|
(values lexeme 'string #f (pos lexeme-start) (pos lexeme-end))]))
|
||
8 years ago
|
(if (and in-racket-expr?
|
||
|
(not (equal? (peek-string 2 0 port) "$@")))
|
||
8 years ago
|
(racket-lexer port)
|
||
|
(jsonic-lexer port)))
|
||
8 years ago
|
(provide color-jsonic)
|
||
|
|
||
|
(module+ test
|
||
|
(require rackunit)
|
||
|
(check-equal? (values->list (color-jsonic (open-input-string "x")))
|
||
|
(list "x" 'string #f 1 2)))
|