Allow an implicit paren for (: <id> : T ... -> T)

svn: r12038
This commit is contained in:
Eli Barzilay 2008-10-14 18:44:05 +00:00
parent 20e8888dad
commit 9cc7f90a0a

View File

@ -160,24 +160,28 @@ This file defines two sorts of primitives. All of them are provided into any mod
(syntax-property #'arg 'type-ascription #'ty)])) (syntax-property #'arg 'type-ascription #'ty)]))
(define-syntax (: stx) (define-syntax (: stx)
(let ([stx* (define stx*
;; make it possible to add another colon after the id for clarity ;; make it possible to add another colon after the id for clarity
(syntax-case stx (:) ;; and in that case, a `->' on the RHS does not need to be
[(: id : . more) (syntax/loc stx (: id . more))] ;; explicitly parenthesized
[_ stx])]) (syntax-case stx (:)
(syntax-case stx* () [(: id : first x ... last)
[(_ id ty) (ormap (lambda (x) (eq? '-> (syntax-e x))) (syntax->list #'(x ...)))
(identifier? #'id) (syntax/loc stx (: id (first x ... last)))]
(syntax-property [(: id : . more) (syntax/loc stx (: id . more))]
(internal (syntax/loc stx (:-internal id ty))) [_ stx]))
'disappeared-use #'id)] (define (err str . sub)
[(_ id ty) (apply raise-syntax-error '|type declaration| str stx sub))
(raise-syntax-error '|type declaration| "can only annotate identifiers with types" (syntax-case stx* ()
stx #'id)] [(_ id ty)
[(_ _ _ _ . _) (identifier? #'id)
(raise-syntax-error '|type declaration| "too many arguments" stx)] (syntax-property (internal (syntax/loc stx (:-internal id ty)))
[(_ _) 'disappeared-use #'id)]
(raise-syntax-error '|type declaration| "too few arguments" stx)]))) [(_ id x ...)
(case (length (syntax->list #'(x ...)))
[(1) (err "can only annotate identifiers with types" #'id)]
[(0) (err "missing type")]
[else (err "bad syntax (multiple types after identifier)")])]))
(define-syntax (inst stx) (define-syntax (inst stx)
(syntax-case stx (:) (syntax-case stx (:)