Allow an implicit paren for (: <id> : T ... -> T)
svn: r12038
This commit is contained in:
parent
20e8888dad
commit
9cc7f90a0a
|
@ -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
|
||||||
|
;; and in that case, a `->' on the RHS does not need to be
|
||||||
|
;; explicitly parenthesized
|
||||||
(syntax-case stx (:)
|
(syntax-case stx (:)
|
||||||
|
[(: id : first x ... last)
|
||||||
|
(ormap (lambda (x) (eq? '-> (syntax-e x))) (syntax->list #'(x ...)))
|
||||||
|
(syntax/loc stx (: id (first x ... last)))]
|
||||||
[(: id : . more) (syntax/loc stx (: id . more))]
|
[(: id : . more) (syntax/loc stx (: id . more))]
|
||||||
[_ stx])])
|
[_ stx]))
|
||||||
|
(define (err str . sub)
|
||||||
|
(apply raise-syntax-error '|type declaration| str stx sub))
|
||||||
(syntax-case stx* ()
|
(syntax-case stx* ()
|
||||||
[(_ id ty)
|
[(_ id ty)
|
||||||
(identifier? #'id)
|
(identifier? #'id)
|
||||||
(syntax-property
|
(syntax-property (internal (syntax/loc stx (:-internal id ty)))
|
||||||
(internal (syntax/loc stx (:-internal id ty)))
|
|
||||||
'disappeared-use #'id)]
|
'disappeared-use #'id)]
|
||||||
[(_ id ty)
|
[(_ id x ...)
|
||||||
(raise-syntax-error '|type declaration| "can only annotate identifiers with types"
|
(case (length (syntax->list #'(x ...)))
|
||||||
stx #'id)]
|
[(1) (err "can only annotate identifiers with types" #'id)]
|
||||||
[(_ _ _ _ . _)
|
[(0) (err "missing type")]
|
||||||
(raise-syntax-error '|type declaration| "too many arguments" stx)]
|
[else (err "bad syntax (multiple types after identifier)")])]))
|
||||||
[(_ _)
|
|
||||||
(raise-syntax-error '|type declaration| "too few arguments" stx)])))
|
|
||||||
|
|
||||||
(define-syntax (inst stx)
|
(define-syntax (inst stx)
|
||||||
(syntax-case stx (:)
|
(syntax-case stx (:)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user