From 1f8c1950fb1ec7728a8532216140781152e16e09 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Mon, 14 Nov 2011 17:48:14 -0700 Subject: [PATCH] [honu] allow multiple variables to be declared at once --- collects/honu/core/private/class.rkt | 2 +- collects/honu/core/private/honu2.rkt | 42 +++++++++++++++++----------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/collects/honu/core/private/class.rkt b/collects/honu/core/private/class.rkt index f98dc61068..542c1f66f1 100644 --- a/collects/honu/core/private/class.rkt +++ b/collects/honu/core/private/class.rkt @@ -19,7 +19,7 @@ [pattern method:honu-function #:with result (replace-with-public #'method.result)] [pattern var:honu-declaration - #:with result #'(field [var.name var.expression])])) + #:with result #'(field [var.name var.expression] ...)])) (provide honu-class) (define-honu-syntax honu-class diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 16b89ec504..017338e896 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -12,6 +12,7 @@ honu-in honu-prefix semicolon + honu-comma define-literal %racket) (for-syntax syntax/parse @@ -38,23 +39,6 @@ #'rest #f)]))) -(begin-for-syntax - (provide honu-declaration) - (define-splicing-syntax-class honu-declaration - #:literal-sets (cruft) - #:literals (honu-equal honu-var) - [pattern (~seq honu-var name:id honu-equal one:honu-expression) - #:with result #'(%racket (define name one.result)) - #:with expression #'one.result])) - -(provide honu-var) -(define-honu-syntax honu-var - (lambda (code context) - (syntax-parse code #:literal-sets (cruft) - #:literals (honu-equal) - [(var:honu-declaration . rest) - (values #'var.result #'rest #t)]))) - (provide honu-for) (define-honu-syntax honu-for (lambda (code context) @@ -274,3 +258,27 @@ (with-syntax ([left left]) (values #'(send/apply left name (list argument.result ...)) #'more))]))) + +(begin-for-syntax + (provide honu-declaration) + + (define-literal-set declaration-literals (honu-comma honu-equal)) + (define-splicing-syntax-class var-id + [pattern x:id #:when (not ((literal-set->predicate declaration-literals) #'x))]) + + (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 ...) + #:with expression #'one.result])) + +(provide honu-var) +(define-honu-syntax honu-var + (lambda (code context) + (syntax-parse code #:literal-sets (cruft) + #:literals (honu-equal) + [(var:honu-declaration . rest) + (values #'var.result #'rest #t)]))) +