[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:
parent
a823986281
commit
6552d3f2cd
|
@ -33,6 +33,7 @@
|
||||||
[honu-var var]
|
[honu-var var]
|
||||||
[honu-val val]
|
[honu-val val]
|
||||||
[honu-for for]
|
[honu-for for]
|
||||||
|
[honu-to to]
|
||||||
[honu-if if]
|
[honu-if if]
|
||||||
[honu-quote quote]
|
[honu-quote quote]
|
||||||
[honu-quasiquote quasiquote]
|
[honu-quasiquote quasiquote]
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
(define-honu-syntax honu-class
|
(define-honu-syntax honu-class
|
||||||
(lambda (code context)
|
(lambda (code context)
|
||||||
(syntax-parse code #:literal-sets (cruft)
|
(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))))
|
[(_ name (#%parens (~var constructor-argument (separate-ids (literal-syntax-class honu-comma) (literal-syntax-class honu-comma))))
|
||||||
(#%braces method:honu-class-thing ...) . rest)
|
(#%braces method:honu-class-thing ...) . rest)
|
||||||
(define class
|
(define class
|
||||||
|
|
|
@ -54,25 +54,7 @@
|
||||||
#'rest
|
#'rest
|
||||||
#f)])))
|
#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)
|
(provide honu-if)
|
||||||
(define-honu-syntax honu-if
|
(define-honu-syntax honu-if
|
||||||
|
@ -259,6 +241,10 @@
|
||||||
(define-binary-operator honu-string=? 1 'left string=?)
|
(define-binary-operator honu-string=? 1 'left string=?)
|
||||||
(define-binary-operator honu-modulo 2 'left modulo)
|
(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-unary-operator honu-not 0.7 'left not)
|
||||||
|
|
||||||
(define-binary-operator honu-equal 1 'left equal?)
|
(define-binary-operator honu-equal 1 'left equal?)
|
||||||
|
@ -372,7 +358,8 @@
|
||||||
[pattern (~seq (~var first (id-except separator end))
|
[pattern (~seq (~var first (id-except separator end))
|
||||||
(~seq (~var between (id-must-be separator))
|
(~seq (~var between (id-must-be separator))
|
||||||
(~var next (id-except separator end))) ...)
|
(~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
|
(begin-for-syntax
|
||||||
(provide honu-declaration)
|
(provide honu-declaration)
|
||||||
|
@ -417,3 +404,24 @@
|
||||||
(provide true false)
|
(provide true false)
|
||||||
(define true #t)
|
(define true #t)
|
||||||
(define false #f)
|
(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)])))
|
||||||
|
|
|
@ -161,7 +161,7 @@
|
||||||
(debug "Parse more: ~a unparsed ~a\n" parsed unparsed)
|
(debug "Parse more: ~a unparsed ~a\n" parsed unparsed)
|
||||||
(define output (if parsed
|
(define output (if parsed
|
||||||
(honu->racket parsed)
|
(honu->racket parsed)
|
||||||
#'(begin)))
|
#'(void)))
|
||||||
(debug "Output ~a\n" output)
|
(debug "Output ~a\n" output)
|
||||||
(with-syntax ([output output]
|
(with-syntax ([output output]
|
||||||
[(unparsed-out ...) unparsed]
|
[(unparsed-out ...) unparsed]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#lang honu
|
#lang honu
|
||||||
|
|
||||||
for x = 1 + 5 to 10 do
|
for x in 1 + 5 to 10 do
|
||||||
printf("x is ~a\n" x)
|
printf("x is ~a\n" x)
|
||||||
|
|
||||||
for x = 1 to 10 do {
|
for x in 1 to 10 do {
|
||||||
var y = x + 1;
|
var y = x + 1;
|
||||||
printf("x ~a y ~a\n", x, y)
|
printf("x ~a y ~a\n", x, y)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user