[honu] allow classes to accept 0 constructor parameters. add 'to' as a binary operator that creates a list of numbers

This commit is contained in:
Jon Rafkind 2012-01-13 13:10:29 -07:00
parent a823986281
commit 6552d3f2cd
5 changed files with 33 additions and 23 deletions

View File

@ -33,6 +33,7 @@
[honu-var var]
[honu-val val]
[honu-for for]
[honu-to to]
[honu-if if]
[honu-quote quote]
[honu-quasiquote quasiquote]

View File

@ -26,6 +26,7 @@
(define-honu-syntax honu-class
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
;; FIXME: empty parenthesis for constructor arguments should be optional
[(_ name (#%parens (~var constructor-argument (separate-ids (literal-syntax-class honu-comma) (literal-syntax-class honu-comma))))
(#%braces method:honu-class-thing ...) . rest)
(define class

View File

@ -54,25 +54,7 @@
#'rest
#f)])))
(provide honu-for)
(define-honu-syntax honu-for
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal honu-in)
[(_ iterator:id honu-equal start:honu-expression honu-to end:honu-expression
honu-do body:honu-expression . rest)
(values
#'(%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/list ([iterator stuff.result])
body.result))
#'rest
#t)])))
(provide honu-if)
(define-honu-syntax honu-if
@ -259,6 +241,10 @@
(define-binary-operator honu-string=? 1 'left string=?)
(define-binary-operator honu-modulo 2 'left modulo)
(define-binary-operator honu-to 0.001 'left
(lambda (left right)
(for/list ([i (in-range left right)]) i)))
(define-unary-operator honu-not 0.7 'left not)
(define-binary-operator honu-equal 1 'left equal?)
@ -372,7 +358,8 @@
[pattern (~seq (~var first (id-except separator end))
(~seq (~var between (id-must-be separator))
(~var next (id-except separator end))) ...)
#:with (id ...) #'(first.x next.x ...)]))
#:with (id ...) #'(first.x next.x ...)]
[pattern (~seq) #:with (id ...) '()]))
(begin-for-syntax
(provide honu-declaration)
@ -417,3 +404,24 @@
(provide true false)
(define true #t)
(define false #f)
(provide honu-for)
(define-honu-syntax honu-for
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal honu-in)
#;
[(_ iterator:id honu-equal start:honu-expression honu-to end:honu-expression
honu-do body:honu-expression . rest)
(values
#'(%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/list ([iterator stuff.result])
body.result))
#'rest
#t)])))

View File

@ -161,7 +161,7 @@
(debug "Parse more: ~a unparsed ~a\n" parsed unparsed)
(define output (if parsed
(honu->racket parsed)
#'(begin)))
#'(void)))
(debug "Output ~a\n" output)
(with-syntax ([output output]
[(unparsed-out ...) unparsed]

View File

@ -1,9 +1,9 @@
#lang honu
for x = 1 + 5 to 10 do
for x in 1 + 5 to 10 do
printf("x is ~a\n" x)
for x = 1 to 10 do {
for x in 1 to 10 do {
var y = x + 1;
printf("x ~a y ~a\n", x, y)
}