[honu] add example of lexically scoped macros

This commit is contained in:
Jon Rafkind 2011-11-21 14:54:27 -07:00
parent 42caad96de
commit a9ba721be8
2 changed files with 25 additions and 21 deletions

View File

@ -153,16 +153,6 @@
(debug 2 "Comma? ~a ~a\n" what is) (debug 2 "Comma? ~a ~a\n" what is)
is) is)
#;
(define-syntax (parse-more stx)
(syntax-parse stx
[(_ stuff ...)
(define-values (parsed unparsed)
(parse (strip-stops #'(stuff ...))))
(with-syntax ([(parsed-out ...) (honu->racket parsed)]
[(unparsed-out ...) unparsed])
#'(begin parsed-out ... (parse-stuff unparsed-out ...)))]))
(define (do-parse stx parse-more) (define (do-parse stx parse-more)
(syntax-parse stx (syntax-parse stx
[(_ stuff ...) [(_ stuff ...)
@ -518,14 +508,3 @@
(provide honu-expression/comma) (provide honu-expression/comma)
(define-splicing-syntax-class honu-expression/comma (define-splicing-syntax-class honu-expression/comma
[pattern (~seq x ...) #:with (result ...) (parse-comma-expression #'(x ...))]) [pattern (~seq x ...) #:with (result ...) (parse-comma-expression #'(x ...))])
#|
(provide honu-body)
(define-splicing-syntax-class honu-body
#:literal-sets (cruft)
[pattern (~seq (#%braces code ...))
#:with result #'(let-syntax ([parse-more (lambda (stx)
(honu->racket (parse-all #'(code ...))))])
(parse-more))])
|#

View File

@ -0,0 +1,25 @@
#lang honu
macro foo (){ x:identifier }{
syntax(macro x (){ e:expression }{
syntax(e + 2)
})
}
foo h
h 5
h 8 * 9
test(z){
macro foo (){ x:identifier }{
syntax(macro x (){ e:expression }{
syntax(e + z)
})
}
foo h
h 5
}
test(4)