- (if (and (list? (car type-spec))
- (not (= (length (car type-spec)) 2)))
- (parse-error errtxt "invalid type spec" type-spec))
+ (let ((expected
+ ", expected (mode [(dimensions)]) or ((mode bits) [(dimensions)])"))
+ (if (not (list? type-spec))
+ (parse-error context (string-append "invalid type spec" expected)
+ type-spec))
+ (let ((len (length type-spec)))
+ (if (or (< len 1)
+ (> len 2))
+ (parse-error context (string-append "invalid type spec" expected)
+ type-spec))
+ ; Validate the mode spec.
+ (cond ((symbol? (car type-spec))
+ #t) ; ok
+ ((list? (car type-spec))
+ (begin
+ (if (not (= (length (car type-spec)) 2))
+ (parse-error context
+ (string-append "invalid mode in type spec"
+ expected)
+ type-spec))
+ (if (not (symbol? (caar type-spec)))
+ (parse-error context
+ (string-append "invalid mode in type spec"
+ expected)
+ type-spec))
+ (if (not (integer? (cadar type-spec)))
+ (parse-error context
+ (string-append "invalid #bits in type spec"
+ expected)
+ type-spec))
+ ))
+ (else
+ (parse-error context
+ (string-append "invalid mode in type spec" expected)
+ type-spec)))
+ ; Validate the dimension list if present.
+ (if (= len 2)
+ (if (or (not (list? (cadr type-spec)))
+ (not (all-true? (map non-negative-integer?
+ (cadr type-spec)))))
+ (parse-error context
+ (string-append "invalid dimension spec in type spec"
+ expected)
+ type-spec)))
+ ))