pull/10/head
Matthew Butterick 8 years ago
parent 50bd8e6301
commit 18081e6d6e

@ -1,7 +1,8 @@
#lang br #lang br
(require brag/support) (require brag/support)
(provide tokenize)
(define+provide (tokenize ip) (define (tokenize ip)
(define get-token (define get-token
(lexer (lexer
[(char-set "><-.,+[]") lexeme] [(char-set "><-.,+[]") lexeme]

@ -1,24 +0,0 @@
#lang racket/base
(require (for-syntax racket/base) br/define)
(provide (all-defined-out))
(define-macro (define-case-macro ID PRED)
#'(define-syntax (ID stx)
(syntax-case stx ()
[(_ test-val
[(match-vals) . result] (... ...)
[else . else-result])
#'(cond
[(PRED test-val '(match-vals)) . result] (... ...)
[else . else-result])]
[(_ test-val
match-clause (... ...))
#'(ID test-val
match-clause (... ...)
[else (error 'ID "no match")])])))
;; like case but strictly uses `eq?` comparison (as opposed to `equal?`)
(define-case-macro caseq memq)
;; `eqv?` is OK for chars (same as `char=?`)
(define-case-macro casev memv)

@ -1,6 +1,5 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base br/syntax) (require (for-syntax racket/base) br/define)
br/define)
(provide (all-defined-out)) (provide (all-defined-out))
(define-macro (until COND EXPR ...) (define-macro (until COND EXPR ...)
@ -15,13 +14,6 @@
EXPR ... EXPR ...
(loop)))) (loop))))
(define-macro (forever . EXPRS)
;; todo: would be better with a syntax parameter
(with-pattern
([STOP (datum->syntax #'EXPRS 'stop)])
#'(let/ec STOP
(while #t . EXPRS))))
(module+ test (module+ test
(require rackunit) (require rackunit)
(check-equal? (let ([x 5]) (check-equal? (let ([x 5])

@ -1,31 +1,32 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base br/syntax) br/define) (provide format-datum format-datums)
(provide (except-out (all-defined-out) string->datum))
(define (blank? str) (define (blank? str)
(or (zero? (string-length str)) (for/and ([c (in-string str)])
(andmap char-blank? (string->list str)))) (char-blank? c)))
;; read "foo bar" the same way as "(foo bar)" ;; read "foo bar" the same way as "(foo bar)"
;; otherwise "bar" is dropped, which is too astonishing ;; otherwise "bar" is dropped, which is too astonishing
(define (string->datum str) (define (string->datum str)
(if (blank? str) (unless (blank? str)
(void)
(let ([result (read (open-input-string (format "(~a)" str)))]) (let ([result (read (open-input-string (format "(~a)" str)))])
(if (= (length result) 1) (if (= (length result) 1)
(car result) (car result)
result)))) result))))
(define (datum? x) (define (datum? x) (or (list? x) (symbol? x)))
(or (list? x) (symbol? x)))
(define (format-datum datum-template . args) (define (format-datum datum-template . args)
(string->datum (apply format (format "~a" datum-template) (map (λ(arg) (if (syntax? arg) (unless (datum? datum-template)
(raise-argument-error 'format-datums "datum?" datum-template))
(string->datum (apply format (format "~a" datum-template)
(map (λ (arg) (if (syntax? arg)
(syntax->datum arg) (syntax->datum arg)
arg)) args)))) arg)) args))))
;; todo: rephrase errors from `format` or `map` in terms of `format-datums`
(define (format-datums datum-template . argss) (define (format-datums datum-template . argss)
(unless (datum? datum-template)
(raise-argument-error 'format-datums "datum?" datum-template))
(apply map (λ args (apply format-datum datum-template args)) argss)) (apply map (λ args (apply format-datum datum-template args)) argss))
(module+ test (module+ test

@ -1,6 +1,5 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base br/syntax) (require (for-syntax racket/base br/syntax) br/define)
br/define)
(provide (all-defined-out)) (provide (all-defined-out))
(define-macro-cases report (define-macro-cases report
@ -11,9 +10,7 @@
expr-result)]) expr-result)])
(define-macro-cases report-datum (define-macro-cases report-datum
[(_ STX-EXPR) [(_ STX-EXPR) #`(report-datum STX-EXPR #,(syntax->datum #'STX-EXPR))]
(with-pattern ([datum (syntax->datum #'STX-EXPR)])
#'(report-datum STX-EXPR datum))]
[(_ STX-EXPR NAME) [(_ STX-EXPR NAME)
#'(let () #'(let ()
(eprintf "~a = ~v\n" 'NAME (syntax->datum STX-EXPR)) (eprintf "~a = ~v\n" 'NAME (syntax->datum STX-EXPR))

@ -1,26 +1,13 @@
#lang racket/base #lang racket/base
(require (require racket/function
racket/function
(for-syntax racket/base (for-syntax racket/base
syntax/parse syntax/parse
br/private/syntax-flatten
br/private/generate-literals br/private/generate-literals
syntax/define)) syntax/define))
(provide (all-defined-out) (provide (all-defined-out)
(for-syntax with-shared-id)) (for-syntax with-shared-id))
(module+ test (module+ test (require rackunit))
(require rackunit))
(define-syntax (define+provide stx)
(with-syntax ([(id lambda-exp)
(let-values ([(id-stx body-exp-stx)
(normalize-definition stx (datum->syntax stx 'λ) #t #t)])
(list id-stx body-exp-stx))])
#'(begin
(provide id)
(define id lambda-exp))))
(begin-for-syntax (begin-for-syntax
;; expose the caller context within br:define macros with syntax parameter ;; expose the caller context within br:define macros with syntax parameter
@ -28,7 +15,6 @@
(provide caller-stx) (provide caller-stx)
(define-syntax-parameter caller-stx (λ(stx) (error 'caller-stx-not-parameterized)))) (define-syntax-parameter caller-stx (λ(stx) (error 'caller-stx-not-parameterized))))
(define-syntax (define-cases stx) (define-syntax (define-cases stx)
(syntax-parse stx (syntax-parse stx
#:literals (syntax) #:literals (syntax)
@ -73,7 +59,7 @@
(module+ test (module+ test
(require rackunit racket/port) (require racket/port)
(parameterize ([current-output-port (open-output-nowhere)]) (parameterize ([current-output-port (open-output-nowhere)])
(check-equal? (let () (check-equal? (let ()
(debug-define-macro (foo X Y Z) (debug-define-macro (foo X Y Z)
@ -180,7 +166,7 @@
(module+ test (module+ test
(define-macro plus (λ(stx) #'+)) (define-macro plus (λ (stx) #'+))
(check-equal? (plus 42) +) (check-equal? (plus 42) +)
(define-macro plusser #'plus) (define-macro plusser #'plus)
(check-equal? (plusser 42) +) (check-equal? (plusser 42) +)
@ -238,9 +224,9 @@
(check-equal? (elseop "+") 'got-arg) (check-equal? (elseop "+") 'got-arg)
(check-equal? (elseop "+" 42) 'got-else) (check-equal? (elseop "+" 42) 'got-else)
(check-exn exn:fail:syntax? (λ _ (expand-once #'(define-macro-cases no-cases)))) (check-exn exn:fail:syntax? (λ () (expand-once #'(define-macro-cases no-cases))))
(check-exn exn:fail:syntax? (λ _ (expand-once #'(define-macro-cases badelseop (check-exn exn:fail:syntax? (λ () (expand-once #'(define-macro-cases badelseop
[else #''got-else] [else #''got-else]
[(_ _arg) #''got-arg])))) [(_ _arg) #''got-arg]))))

@ -1,11 +0,0 @@
#lang racket/base
(require racket/class
racket/draw)
(provide (all-defined-out))
(define (make-drracket-button . args)
(define label (or (findf string? args) "untitled"))
(define bitmap (or (findf (λ(arg) (is-a? arg bitmap%)) args) (make-object bitmap% 16 16)))
(define callback (or (findf procedure? args) (λ(drr-frame) (void))))
(define number (or (findf (λ(arg) (or (real? arg) (equal? #f arg))) args) #f))
(list label bitmap callback number))

@ -1,19 +1,19 @@
#lang racket #lang racket
(require racket/class)
(provide (all-defined-out)) (provide (all-defined-out))
(require racket/class)
(define (indenter t pos) (define (indenter t pos)
(with-handlers ([exn:fail? (λ(exn) #f)]) ; this function won't work until gui-lib 1.26 (with-handlers ([exn:fail? (λ (exn) #f)]) ; this function won't work until gui-lib 1.26
(send t compute-racket-amount-to-indent pos (λ(x) (send t compute-racket-amount-to-indent pos (λ(x)
(case x (case x
[("with-pattern" "with-shared-id") 'lambda] [("with-pattern"
[("define-macro") 'define] "with-shared-id") 'lambda]
[("define-macro"
"define-macro-cases"
"define-cases") 'define]
[else #f]))))) [else #f])))))
(define (br-get-info key default default-filter) (define (br-get-info key default default-filter)
(case key (case key
#;[(color-lexer)
(dynamic-require 'syntax-color/default-lexer 'default-lexer)]
[(drracket:indentation) indenter] [(drracket:indentation) indenter]
[else [else (default-filter key default)]))
(default-filter key default)]))

@ -12,3 +12,13 @@
#'(let ([x (car ID)]) #'(let ([x (car ID)])
(set! ID (cdr ID)) (set! ID (cdr ID))
x)) x))
(module+ test
(require rackunit)
(check-equal? '(1 2 3) (values->list (values 1 2 3)))
(check-equal? (let ([xs '(2 3)])
(push! xs 1)
xs) '(1 2 3))
(check-equal? (let ([xs '(1 2 3)])
(define x (pop! xs))
(cons x xs)) '(1 2 3)))

@ -1,10 +1,10 @@
#lang racket/base #lang racket/base
(require racket/provide racket/list racket/string racket/format racket/match racket/port racket/function racket/provide (require racket/provide racket/list racket/string racket/format racket/match racket/port racket/function racket/provide
br/define br/syntax br/datum br/debug br/cond br/case br/exception br/list racket/class racket/vector br/reader-utils br/define br/syntax br/datum br/debug br/cond br/exception br/list racket/class racket/vector br/reader-utils
(for-syntax racket/base racket/syntax br/syntax br/debug br/define br/datum)) (for-syntax racket/base racket/syntax br/syntax br/debug br/define br/datum))
(provide (all-from-out racket/base) (provide (all-from-out racket/base)
(all-from-out racket/list racket/string racket/format racket/match racket/port racket/function racket/provide (all-from-out racket/list racket/string racket/format racket/match racket/port racket/function racket/provide
br/syntax br/datum br/debug br/cond br/case br/exception br/list racket/class racket/vector br/define br/reader-utils) br/syntax br/datum br/debug br/cond br/exception br/list racket/class racket/vector br/define br/reader-utils)
(for-syntax (all-from-out racket/base racket/syntax br/syntax br/debug br/datum)) (for-syntax (all-from-out racket/base racket/syntax br/syntax br/debug br/datum))
(for-syntax caller-stx with-shared-id)) ; from br/define (for-syntax caller-stx with-shared-id)) ; from br/define

Loading…
Cancel
Save