(markup-typecheck?): add full typechecking functions.
(make-markup-maker): add make-FOO-markup functions.
(markup-argument-list-error): nice error checking messages.
* scm/new-markup.scm (markup-thrower-typecheck)
(markup-typecheck?): add full typechecking functions.
(make-markup-maker): add make-FOO-markup functions.
+ (markup-argument-list-error): nice error checking messages.
2002-12-29 Jan Nieuwenhuizen <janneke@gnu.org>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-(define type-p-name-alist
- `(
- (,ly:dir? . "direction")
- (,scheme? . "any type")
- (,number-pair? . "pair of numbers")
- (,ly:input-location? . "input location")
- (,ly:grob? . "grob (GRaphical OBject)")
- (,grob-list? . "list of grobs")
- (,ly:duration? . "duration")
- (,pair? . "pair")
- (,integer? . "integer")
- (,list? . "list")
- (,symbol? . "symbol")
- (,string? . "string")
- (,boolean? . "boolean")
- (,ly:moment? . "moment")
- (,ly:input-location? . "input location")
- (,music-list? . "list of music")
- (,ly:music? . "music")
- (,number? . "number")
- (,char? . "char")
- (,input-port? . "input port")
- (,output-port? . "output port")
- (,vector? . "vector")
- (,procedure? . "procedure")
- (,boolean-or-symbol? . "boolean or symbol")
- (,number-or-string? . "number or string")
- (,markup? . "markup (list or string)")
- (,number-or-grob? . "number or grob")
- ))
+;; moved list to end of lily.scm: then all type-predicates are
+;; defined.
+(define type-p-name-alist '())
(define (match-predicate obj alist)
(if (null? alist)
'("music-types.scm"
"output-lib.scm"
"c++.scm"
+
"molecule.scm"
"bass-figure.scm"
"grob-property-description.scm"
+
+
+(set! type-p-name-alist
+ `(
+ (,ly:dir? . "direction")
+ (,scheme? . "any type")
+ (,number-pair? . "pair of numbers")
+ (,ly:input-location? . "input location")
+ (,ly:grob? . "grob (GRaphical OBject)")
+ (,grob-list? . "list of grobs")
+ (,ly:duration? . "duration")
+ (,pair? . "pair")
+ (,integer? . "integer")
+ (,list? . "list")
+ (,symbol? . "symbol")
+ (,string? . "string")
+ (,boolean? . "boolean")
+ (,ly:moment? . "moment")
+ (,ly:input-location? . "input location")
+ (,music-list? . "list of music")
+ (,ly:music? . "music")
+ (,number? . "number")
+ (,char? . "char")
+ (,input-port? . "input port")
+ (,output-port? . "output port")
+ (,vector? . "vector")
+ (,procedure? . "procedure")
+ (,boolean-or-symbol? . "boolean or symbol")
+ (,number-or-string? . "number or string")
+ (,markup? . "markup")
+ (,markup-list? . "list of markups")
+ (,number-or-grob? . "number or grob")
+ ))
(and (null? signature) (null? arguments)))
)
+
+(define (markup-argument-list-error signature arguments number)
+ (if (and (pair? signature) (pair? arguments))
+ (if (not ((car signature) (car arguments)))
+ (list number (type-name (car signature)) (car arguments))
+ (markup-argument-list-error (cdr signature) (cdr arguments) (+ 1 number)))
+ #f
+ ))
+
;;
;; full recursive typecheck.
;;
;; Invalid argument 4 : expecting a BLADIBLA, found: (list-ref 4 args)
;;
;; right now, you get the entire argument list.
+
+
(define (make-markup-maker entry)
(let*
((foo-markup (car entry))
)
`(define (,(string->symbol make-name) . args)
- (if (markup-argument-list? ,signature args)
+ (if (= (length args) (length ,signature))
+ #t
+ (scm-error 'markup-format ,make-name "Expect ~A arguments for ~A. Found ~A: ~S"
+ (list (length ,signature)
+ ,make-name
+ (length args)
+ args) #f))
+
+ (let*
+ (
+ (error-msg (markup-argument-list-error ,signature args 1))
+ )
+ (if error-msg
+ (scm-error 'markup-format ,make-name "Invalid argument in position ~A\n Expect: ~A\nFound: ~S." error-msg #f)
+
(cons ,foo-markup args)
- (scm-error 'markup-format ,make-name "Invalid argument list: ~A." (list args) #f)
)))
)
-
+)
(eval
(cons 'begin (map make-markup-maker markup-function-list))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; test make-foo-markup functions
-(if #f
-(begin
- (make-line-markup (make-simple-markup "FOO")
- (make-simple-markup "foo")
- )
+(if #t
+ (begin
+ (make-line-markup (make-simple-markup "FOO"))
+ (make-line-markup (make-simple-markup "FOO") (make-simple-markup "foo"))
+ (make-raise-markup "foo" (make-simple-markup "foo"))
+ )
+ )
- (make-teeny-markup (make-simple-markup 1)))
-)
;;
;; test typecheckers. Not wholly useful, because errors are detected