use `contract-out` instead of `define/contract`

dev-srcloc
Matthew Butterick 8 years ago
parent 642ebc436a
commit 13e7f3ee97

@ -3,13 +3,7 @@
(define in-racket-expr? #f) (define in-racket-expr? #f)
(define/contract (color-jsonic port) (define (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)]
@ -31,7 +25,15 @@
(not (equal? (peek-string 2 0 port) "$@"))) (not (equal? (peek-string 2 0 port) "$@")))
(racket-lexer port) (racket-lexer port)
(jsonic-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 (module+ test
(require rackunit) (require rackunit)

@ -1,14 +1,11 @@
#lang br #lang br
(require br/indent racket/gui/base racket/contract) (require br/indent racket/contract racket/gui/base)
(provide indent-jsonic)
(define indent-width 2) (define indent-width 2)
(define (left-bracket? c) (member c (list #\{ #\[))) (define (left-bracket? c) (member c (list #\{ #\[)))
(define (right-bracket? c) (member c (list #\} #\]))) (define (right-bracket? c) (member c (list #\} #\])))
(define/contract (indent-jsonic tbox [posn 0]) (define (indent-jsonic tbox [posn 0])
((is-a?/c text%) exact-nonnegative-integer? . -> .
(or/c exact-nonnegative-integer? #f))
(define prev-line (previous-line tbox posn)) (define prev-line (previous-line tbox posn))
(define current-line (line tbox posn)) (define current-line (line tbox posn))
(define prev-indent (or (line-indent tbox prev-line) 0)) (define prev-indent (or (line-indent tbox prev-line) 0))
@ -22,6 +19,11 @@
(- prev-indent indent-width)] (- prev-indent indent-width)]
[else prev-indent])) [else prev-indent]))
(and (exact-positive-integer? current-indent) current-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 (module+ test
(require rackunit) (require rackunit)

@ -1,10 +1,10 @@
#lang br/quicklang #lang br/quicklang
(require "tokenizer.rkt" "parser.rkt" racket/contract) (require "tokenizer.rkt" "parser.rkt" racket/contract)
(define/contract (read-syntax path port) (define (read-syntax path port)
(any/c input-port? . -> . syntax?)
(define parse-tree (parse path (tokenize port))) (define parse-tree (parse path (tokenize port)))
(define module-datum `(module jsonic-module jsonic-demo-2/expander (define module-datum `(module jsonic-module jsonic-demo-2/expander
,parse-tree)) ,parse-tree))
(datum->syntax #f module-datum)) (datum->syntax #f module-datum))
(provide read-syntax) (provide (contract-out
[read-syntax (any/c input-port? . -> . syntax?)]))

@ -13,11 +13,9 @@
(check-true (token? (token 'A-TOKEN-STRUCT "hi"))) (check-true (token? (token 'A-TOKEN-STRUCT "hi")))
(check-false (token? 42))) (check-false (token? 42)))
(define/contract (tokenize port) (define (tokenize port)
(input-port? . -> . (-> token?))
(port-count-lines! port) (port-count-lines! port)
(define/contract (next-token) (define (next-token)
(-> token?)
(define our-lexer (define our-lexer
(lexer (lexer
[(eof) eof] [(eof) eof]
@ -37,7 +35,8 @@
(pos lexeme-start)))])) (pos lexeme-start)))]))
(our-lexer port)) (our-lexer port))
next-token) next-token)
(provide tokenize) (provide (contract-out
[tokenize (input-port? . -> . (-> token?))]))
(module+ test (module+ test
(check-equal? (apply-tokenizer tokenize "// comment\n") empty) (check-equal? (apply-tokenizer tokenize "// comment\n") empty)

Loading…
Cancel
Save