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

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

@ -467,4 +467,18 @@ source-location information and properties. An alias for @racket[strip-context].
@defproc[(replace-bindings [stx-source (or/c syntax? #f)] [stx-target syntax?]) syntax?]{
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 (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
(lexer
[(eof) (values lexeme 'eof #f #f #f)]
@ -24,4 +30,9 @@
(not (equal? (peek-string 2 0 port) "$@")))
(racket-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 (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 this-line (line tb this-pos))
(define prev-line (previous-line tb this-pos))
@ -11,10 +17,10 @@
(define this-indent
(cond
;; 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)]
;; 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)]
;; otherwise use previous indent
[else prev-indent]))
@ -35,4 +41,4 @@
here
)
(check-equal? (str->indents (test-indenter indent-jsonic test-str))
(map (λ(x) (* x indent-width)) '(0 0 1 1 2 2 1 1 0))))
(map (λ(x) (* x indent-width)) '(0 0 1 1 2 2 1 1 0))))

Loading…
Cancel
Save