diff --git a/beautiful-racket-demo/jsonic-demo-2/colorer.rkt b/beautiful-racket-demo/jsonic-demo-2/colorer.rkt index 6b18466..cc43da2 100644 --- a/beautiful-racket-demo/jsonic-demo-2/colorer.rkt +++ b/beautiful-racket-demo/jsonic-demo-2/colorer.rkt @@ -3,13 +3,7 @@ (define in-racket-expr? #f) -(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 (color-jsonic port) (define jsonic-lexer (lexer [(eof) (values lexeme 'eof #f #f #f)] @@ -31,7 +25,15 @@ (not (equal? (peek-string 2 0 port) "$@"))) (racket-lexer port) (jsonic-lexer port))) -(provide color-jsonic) +(provide + (contract-out + [color-jsonic + (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)))])) (module+ test (require rackunit) diff --git a/beautiful-racket-demo/jsonic-demo-2/indenter.rkt b/beautiful-racket-demo/jsonic-demo-2/indenter.rkt index 3010182..7c2b5ac 100644 --- a/beautiful-racket-demo/jsonic-demo-2/indenter.rkt +++ b/beautiful-racket-demo/jsonic-demo-2/indenter.rkt @@ -1,14 +1,11 @@ #lang br -(require br/indent racket/gui/base racket/contract) -(provide indent-jsonic) +(require br/indent racket/contract racket/gui/base) (define indent-width 2) (define (left-bracket? c) (member c (list #\{ #\[))) (define (right-bracket? c) (member c (list #\} #\]))) -(define/contract (indent-jsonic tbox [posn 0]) - ((is-a?/c text%) exact-nonnegative-integer? . -> . - (or/c exact-nonnegative-integer? #f)) +(define (indent-jsonic tbox [posn 0]) (define prev-line (previous-line tbox posn)) (define current-line (line tbox posn)) (define prev-indent (or (line-indent tbox prev-line) 0)) @@ -22,6 +19,11 @@ (- prev-indent indent-width)] [else prev-indent])) (and (exact-positive-integer? current-indent) current-indent)) +(provide + (contract-out + [indent-jsonic (((is-a?/c text%)) + (exact-nonnegative-integer?) . ->* . + (or/c exact-nonnegative-integer? #f))])) (module+ test (require rackunit) diff --git a/beautiful-racket-demo/jsonic-demo-2/reader.rkt b/beautiful-racket-demo/jsonic-demo-2/reader.rkt index f12c91b..82b8b1e 100644 --- a/beautiful-racket-demo/jsonic-demo-2/reader.rkt +++ b/beautiful-racket-demo/jsonic-demo-2/reader.rkt @@ -1,10 +1,10 @@ #lang br/quicklang (require "tokenizer.rkt" "parser.rkt" racket/contract) -(define/contract (read-syntax path port) - (any/c input-port? . -> . syntax?) +(define (read-syntax path port) (define parse-tree (parse path (tokenize port))) (define module-datum `(module jsonic-module jsonic-demo-2/expander ,parse-tree)) (datum->syntax #f module-datum)) -(provide read-syntax) +(provide (contract-out + [read-syntax (any/c input-port? . -> . syntax?)])) diff --git a/beautiful-racket-demo/jsonic-demo-2/tokenizer.rkt b/beautiful-racket-demo/jsonic-demo-2/tokenizer.rkt index 9744c6e..5887f01 100644 --- a/beautiful-racket-demo/jsonic-demo-2/tokenizer.rkt +++ b/beautiful-racket-demo/jsonic-demo-2/tokenizer.rkt @@ -13,11 +13,9 @@ (check-true (token? (token 'A-TOKEN-STRUCT "hi"))) (check-false (token? 42))) -(define/contract (tokenize port) - (input-port? . -> . (-> token?)) +(define (tokenize port) (port-count-lines! port) - (define/contract (next-token) - (-> token?) + (define (next-token) (define our-lexer (lexer [(eof) eof] @@ -37,7 +35,8 @@ (pos lexeme-start)))])) (our-lexer port)) next-token) -(provide tokenize) +(provide (contract-out + [tokenize (input-port? . -> . (-> token?))])) (module+ test (check-equal? (apply-tokenizer tokenize "// comment\n") empty)