better syntax error message when define-cstruct gets an identifier without a _

svn: r12420

original commit: 987b16447822e647552a8c28f53b870d8638a2c9
This commit is contained in:
Eli Barzilay 2008-11-13 02:18:16 +00:00
parent 5619b780b6
commit fe2ab39bbd

View File

@ -1466,12 +1466,15 @@
list->TYPE list*->TYPE TYPE->list TYPE->list*)))))))
(define (identifiers? stx)
(andmap identifier? (syntax->list stx)))
(define (_-identifier? stx)
(and (identifier? stx)
(regexp-match #rx"^_.+" (symbol->string (syntax-e stx)))))
(define (_-identifier? id stx)
(and (identifier? id)
(or (regexp-match #rx"^_." (symbol->string (syntax-e id)))
(raise-syntax-error #f "cstruct name must begin with a `_'"
stx id))))
(syntax-case stx ()
[(_ _TYPE ([slot slot-type] ...))
(and (_-identifier? #'_TYPE) (identifiers? #'(slot ...)))
(and (_-identifier? #'_TYPE stx)
(identifiers? #'(slot ...)))
(make-syntax #'_TYPE #f #'(slot ...) #'(slot-type ...))]
[(_ (_TYPE _SUPER) ([slot slot-type] ...))
(and (_-identifier? #'_TYPE) (identifiers? #'(slot ...)))