[honu] abstract out separated identifiers

This commit is contained in:
Jon Rafkind 2011-11-15 11:34:35 -07:00
parent 8f914f653f
commit 815c3887fb
3 changed files with 26 additions and 8 deletions

View File

@ -47,14 +47,14 @@
[(_ iterator:id honu-equal start:honu-expression honu-to end:honu-expression
honu-do body:honu-expression . rest)
(values
#'(%racket (for ([iterator (in-range start.result
end.result)])
#'(%racket (for/list ([iterator (in-range start.result
end.result)])
body.result))
#'rest
#t)]
[(_ iterator:id honu-in stuff:honu-expression
honu-do body:honu-expression . rest)
(values #'(%racket (for ([iterator stuff.result])
(values #'(%racket (for/list ([iterator stuff.result])
body.result))
#'rest
#t)])))
@ -259,6 +259,17 @@
(values #'(send/apply left name (list argument.result ...))
#'more))])))
(begin-for-syntax
(define-splicing-syntax-class (id-except ignores)
[pattern x:id #:when (not (for/fold ([ok #t])
([ignore ignores])
(and ok (free-identifier=? #'x ignore))))])
(define-splicing-syntax-class (separate-ids separator end)
[pattern (~seq (~var first (id-except (list separator end)))
(~seq (~var between (id-except (list separator end)))
(~var next (id-except (list separator end)))) ...)
#:with (ids ...) #'(first.x next.x ...)]))
(begin-for-syntax
(provide honu-declaration)
@ -266,12 +277,15 @@
(define-splicing-syntax-class var-id
[pattern x:id #:when (not ((literal-set->predicate declaration-literals) #'x))])
;; parses a declaration
;; var x = 9
;; var a, b, c = values(1 + 2, 5, 9)
(define-splicing-syntax-class honu-declaration
#:literal-sets (cruft)
#:literals (honu-equal honu-var)
[pattern (~seq honu-var (~seq name*:var-id (~optional honu-comma)) ... honu-equal one:honu-expression)
#:with result #'(%racket (define-values (name*.x ...) one.result))
#:with (name ...) #'(name*.x ...)
[pattern (~seq honu-var (~var variables (separate-ids #'honu-comma #'honu-equal))
honu-equal one:honu-expression)
#:with (name ...) #'(variables.ids ...)
#:with expression #'one.result]))
(provide honu-var)
@ -280,5 +294,6 @@
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal)
[(var:honu-declaration . rest)
(values #'var.result #'rest #t)])))
(define result #'(%racket (define-values (var.name ...) var.expression)))
(values result #'rest #t)])))

View File

@ -26,6 +26,9 @@
void
format
integer
cos sin
random
values
(rename-out [honu-cond cond]
[null empty]
[current-inexact-milliseconds currentMilliseconds]

View File

@ -8,4 +8,4 @@ class What(x){
};
var instance = new What(5);
printf("got ~a\n", instance.foobar(10))
printf("got ~a\n", instance->foobar(10))