adjust source
parent
522057f692
commit
640c716758
@ -1,34 +1,26 @@
|
||||
#lang br
|
||||
(require parser-tools/lex
|
||||
syntax-color/racket-lexer
|
||||
parser-tools/lex-sre)
|
||||
|
||||
(provide color-jsonic)
|
||||
(require brag/support
|
||||
syntax-color/racket-lexer)
|
||||
|
||||
(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 (color-jsonic input-port)
|
||||
(define (color-jsonic port)
|
||||
(define jsonic-lexer
|
||||
(lexer
|
||||
[(eof) (values lexeme 'eof #f #f #f)]
|
||||
["@$" (begin
|
||||
(set! in-racket-expr? #t)
|
||||
(values lexeme 'parenthesis '|(| (position-offset start-pos) (position-offset end-pos)))]
|
||||
(values lexeme 'parenthesis '|(|
|
||||
(pos lexeme-start) (pos lexeme-end)))]
|
||||
["$@" (begin
|
||||
(set! in-racket-expr? #f)
|
||||
(values lexeme 'parenthesis '|)| (position-offset start-pos) (position-offset end-pos)))]
|
||||
[(seq "//" (* (char-complement #\newline)))
|
||||
(values lexeme 'comment #f (position-offset start-pos) (position-offset end-pos))]
|
||||
(values lexeme 'parenthesis '|)|
|
||||
(pos lexeme-start) (pos lexeme-end)))]
|
||||
[(from/to "//" "\n")
|
||||
(values lexeme 'comment #f (pos lexeme-start) (pos lexeme-end))]
|
||||
[any-char
|
||||
(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)
|
||||
(jsonic-lexer input-port)))
|
||||
(values lexeme 'string #f (pos lexeme-start) (pos lexeme-end))]))
|
||||
(if (and in-racket-expr? (not (equal? (peek-string 2 0 port) "$@")))
|
||||
(racket-lexer port)
|
||||
(jsonic-lexer port)))
|
||||
(provide color-jsonic)
|
@ -1,14 +1,16 @@
|
||||
#lang br/quicklang
|
||||
(module reader br
|
||||
(require "reader.rkt" "colorer.rkt"
|
||||
"indenter.rkt" "buttons.rkt")
|
||||
(require "reader.rkt")
|
||||
(provide read-syntax get-info)
|
||||
(define (get-info port mod line col pos)
|
||||
(define (handle-query key default)
|
||||
(case key
|
||||
[(color-lexer) color-jsonic]
|
||||
[(drracket:indentation) indent-jsonic]
|
||||
[(drracket:toolbar-buttons) make-jsonic-buttons]
|
||||
[(color-lexer)
|
||||
(dynamic-require 'br/demo/jsonic-2/colorer 'color-jsonic)]
|
||||
[(drracket:indentation)
|
||||
(dynamic-require 'br/demo/jsonic-2/indenter 'indent-jsonic)]
|
||||
[(drracket:toolbar-buttons)
|
||||
(dynamic-require 'br/demo/jsonic-2/buttons 'make-buttons)]
|
||||
[else default]))
|
||||
handle-query))
|
||||
|
||||
|
Loading…
Reference in New Issue