dev-srcloc
Matthew Butterick 8 years ago
parent 747657e6e0
commit 5465cae6c9

@ -21,6 +21,9 @@
#'(parameterize ([current-namespace (make-base-namespace)]) #'(parameterize ([current-namespace (make-base-namespace)])
(dynamic-require . ARGS))) (dynamic-require . ARGS)))
(provide values->list)
(define-macro (values->list EXPR)
#'(call-with-values (λ () EXPR) list))
(module reader syntax/module-reader (module reader syntax/module-reader
#:language 'br #:language 'br

@ -468,3 +468,17 @@ source-location information and properties. An alias for @racket[strip-context].
Uses the bindings from @racket[stx-source] to replace the bindings of all parts of @racket[stx-target], while preserving source-location Uses the bindings from @racket[stx-source] to replace the bindings of all parts of @racket[stx-target], while preserving source-location
information and properties. An alias for @racket[replace-context].} information and properties. An alias for @racket[replace-context].}
@section{Other helpers}
@defmodule[br/main]
@defform[(values->list values)]{
Convert @racket[values] to a simple list.
@examples[#:eval my-eval
(split-at '(a b c d e f) 3)
(values->list (split-at '(a b c d e f) 3))
]
}

@ -4,7 +4,13 @@
(define in-racket-expr? #f) (define in-racket-expr? #f)
(define (color-jsonic port) (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)))
(define jsonic-lexer (define jsonic-lexer
(lexer (lexer
[(eof) (values lexeme 'eof #f #f #f)] [(eof) (values lexeme 'eof #f #f #f)]
@ -25,3 +31,8 @@
(racket-lexer port) (racket-lexer port)
(jsonic-lexer port))) (jsonic-lexer port)))
(provide color-jsonic) (provide color-jsonic)
(module+ test
(require rackunit)
(check-equal? (values->list (color-jsonic (open-input-string "x")))
(list "x" 'string #f 1 2)))

@ -4,6 +4,12 @@
(define indent-width 2) (define indent-width 2)
(define (left-bracket? c)
(and c (or (char=? c #\{) (char=? c #\[))))
(define (right-bracket? c)
(and c (or (char=? c #\}) (char=? c #\]))))
(define (indent-jsonic tb [this-pos 0]) (define (indent-jsonic tb [this-pos 0])
(define this-line (line tb this-pos)) (define this-line (line tb this-pos))
(define prev-line (previous-line tb this-pos)) (define prev-line (previous-line tb this-pos))
@ -11,10 +17,10 @@
(define this-indent (define this-indent
(cond (cond
;; if this line begins with }, outdent. ;; if this line begins with }, outdent.
[((char tb (line-start-visible tb this-line)) . char=? . #\}) [(right-bracket? (char tb (line-start-visible tb this-line)))
(- prev-indent indent-width)] (- prev-indent indent-width)]
;; if last line begins with {, indent. ;; if last line begins with {, indent.
[((char tb (line-start-visible tb prev-line)) . char=? . #\{) [(left-bracket? (char tb (line-start-visible tb prev-line)))
(+ prev-indent indent-width)] (+ prev-indent indent-width)]
;; otherwise use previous indent ;; otherwise use previous indent
[else prev-indent])) [else prev-indent]))

Loading…
Cancel
Save