(You have to patch some ice-9 routines to make this work (syntax-_expression_ and syntax-object? need to be in the environment - the files are included)
(define <list2> (<parse-list> #t ;; signal error if #t else record error if #f
;; error msg if not a list "in let decl, (symbol val) malformed"
;; error msg in case of wrong number of elements "list must have length 2"
2)) ;; the length of the list
(define <arg2> (<parse-list..> #t "not a list Bug! args are a list" "either * and/or code1 is missing in:~% (let * code1 code ...)"
3))
(define <list> (<parse-list..> #t "declaration form in let is not a list" "Bug if this is printed"
))
;; here is an example of designing a matcher out of pieces (define <arg2..> (lambda (x) (match-parse -abs ((<arg2> x) (<list> y)) ;; matchers needs declaration
x
;; if 2 args followed by a list of 0 ... elements then success ((<arg2> <list>) (list #t)) (_ (error "Bug in let macro")))))
;; here is a simple checked let form
;; Using the symbol tool (define <sym> (<symbol> "variable decl in let"))
;;; THE MAIN MACRO (define-syntax my-let (syntax-parse ()
((_ (((s : <sym>) v : <list2>) ... : <list>) code2 ... : <arg2..> ) (let ((s v) ...) code2 ...))))
We get, (line number buggs still in the codebase) .............................................................................................
scheme@(guile-user)> (my-let a) While compiling _expression_: ERROR: error at 1, either * and/or code1 is missing in: (let * code1 code ...)
scheme@(guile-user)> (my-let a 1) While compiling _expression_:
ERROR: error at -1, declaration form in let is not a list
scheme@(guile-user)> (my-let (a 1) a) While compiling _expression_: ERROR: error at -1, in let decl, (symbol val) malformed
scheme@(guile-user)> (my-let ((1 1)) a)
While compiling _expression_: ERROR: error at 4, variable decl in let, not a symbol
scheme@(guile-user)> (my-let ((a 1)) a) $1 = 1
scheme@(guile-user)> (my-let ((a 1)) 1 a) $2 = 1
scheme@(guile-user)> (my-let ((a 1) b) 1 a)
While compiling _expression_: ERROR: error at -1, in let decl, (symbol val) malformed .............................................................................................
We should be able to use the Parser code-base in stead of my match macro and then this is really a small setup.