diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 2aea36274d..b691e570ab 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -41,7 +41,8 @@ (syntax-parse code #:literal-sets (cruft) #:literals (honu-=) [(_ name:id honu-= one:honu-expression . rest) - (values #'(%racket (define name one.result)) + (values (with-syntax ([one-parsed (parse-all #'one.result)]) + #'(%racket (define name one-parsed))) #'rest #t)]))) @@ -75,7 +76,10 @@ #:literals (else honu-then) [(_ condition:honu-expression honu-then true:honu-expression else false:honu-expression . rest) (values - #'(%racket-expression (if condition.result true.result false.result)) + (with-syntax ([condition-parsed (parse-all #'condition.result)] + [true-parsed (parse-all #'true.result)] + [false-parsed (parse-all #'false.result)]) + #'(%racket-expression (if condition-parsed true-parsed false-parsed))) #'rest #f)]))) diff --git a/collects/honu/core/private/parse2.rkt b/collects/honu/core/private/parse2.rkt index d4119566aa..284d544de5 100644 --- a/collects/honu/core/private/parse2.rkt +++ b/collects/honu/core/private/parse2.rkt @@ -228,10 +228,10 @@ (do-parse #'(rest ...) precedence left #'racket))] - [(%racket-expression racket) + [(%racket-expression racket rest ...) (if current (values (left current) stream) - (do-parse #'() + (do-parse #'(rest ...) precedence left #'racket))] [(head rest ...) @@ -304,9 +304,14 @@ [(#%brackets stuff ...) (syntax-parse #'(stuff ...) #:literal-sets (cruft) [(work:honu-expression colon (~seq variable:id honu-<- list:honu-expression (~optional honu-comma)) ...) - (define comprehension #'(for/list ([variable list.result] - ...) - work.result)) + (define comprehension + (with-syntax ([(list-parsed ...) (map (lambda (list) + (parse-all list)) + (syntax->list #'(list.result ...)))] + [work-parsed (parse-all #'work.result)]) + #'(for/list ([variable list-parsed] + ...) + work-parsed))) (if current (error 'parse "a list comprehension cannot follow an expression") (do-parse #'(rest ...) precedence left comprehension))] diff --git a/collects/honu/private/common.rkt b/collects/honu/private/common.rkt index ef4c116d07..88a2752b6b 100644 --- a/collects/honu/private/common.rkt +++ b/collects/honu/private/common.rkt @@ -17,8 +17,14 @@ [(_ (~seq clause:honu-expression colon body:honu-expression (~optional honu-comma)) ... . rest) (values - #'(%racket-expression (cond - [clause.result body.result] - ...)) + (with-syntax ([(clause-parsed ...) (map (lambda (clause) + (parse-all clause)) + (syntax->list #'(clause.result ...)))] + [(body-parsed ...) (map (lambda (body) + (parse-all body)) + (syntax->list #'(body.result ...)))]) + #'(%racket-expression (cond + [clause-parsed body-parsed] + ...))) #'rest #t)]))) diff --git a/collects/tests/honu/check.rkt b/collects/tests/honu/check.rkt index 6342522347..47dd28ee10 100644 --- a/collects/tests/honu/check.rkt +++ b/collects/tests/honu/check.rkt @@ -38,7 +38,8 @@ ;; (printf "output '~a'\n" stuff) (apply string-append "" (append stuff (list "\n")))) -(define (test input output) +(define (test name input output) + (printf "Running test ~a\n" name) (define final (run-honu input)) (when (not (same? final output)) (printf "Not the same!\n'~a'\nvs\n'~a'\n" final output))) @@ -47,6 +48,7 @@ (apply string-append "#lang honu\n" stuff)) (test + "basic numbers" @input{ 5 6 @@ -57,6 +59,7 @@ }) (test + "basic math" @input{ 1 + 1 } @@ -65,6 +68,7 @@ }) (test + "function call" @input{ foo(x){ x * 2 @@ -76,6 +80,7 @@ }) (test + "cond" @input{ var n = 5; cond @@ -87,6 +92,7 @@ }) (test + "if" @input{ if 2 > 1 then 1 @@ -98,6 +104,7 @@ }) (test + "list comprehension" @input{ [x + 1: x <- [1, 2, 3]]; [x + y: x <- [1, 2, 3], y <- [4, 5, 6]]