diff --git a/collects/honu/core/main.rkt b/collects/honu/core/main.rkt index bbce5585d0..3216225e2d 100644 --- a/collects/honu/core/main.rkt +++ b/collects/honu/core/main.rkt @@ -11,6 +11,7 @@ [honu-function function] [honu-var var] [honu-val val] + [honu-for for] [honu-+ +] [honu-- -] [honu-* *] diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 20f7016edf..915a12a4c6 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -40,6 +40,18 @@ #'unparsed) #t)]))) +(provide honu-for) +(define-honu-syntax honu-for + (lambda (code context) + (syntax-parse code #:literal-sets (cruft) + [(_ iterator:id honu-= start:honu-expression honu-to end:honu-expression + honu-do body:honu-expression . rest) + (values + #'(for ([iterator (in-range start.result end.result)]) + body.result) + #'rest + #t)]))) + (provide honu-val) (define-honu-syntax honu-val (lambda (code context) diff --git a/collects/honu/core/private/parse2.rkt b/collects/honu/core/private/parse2.rkt index cc04a90ad5..11c862a48f 100644 --- a/collects/honu/core/private/parse2.rkt +++ b/collects/honu/core/private/parse2.rkt @@ -9,6 +9,7 @@ "debug.rkt" (prefix-in transformer: "transformer.rkt") syntax/stx + syntax/parse/experimental/splicing syntax/parse) ;; phase 1 (require-syntax racket/base) @@ -205,7 +206,7 @@ (parse #'(rest ...)))]) so-far (more)))] [else - (syntax-parse #'(head rest ...) + (syntax-parse #'(head rest ...) #:literal-sets (cruft) [(function:identifier (#%parens args ...) (#%braces code ...) . rest) (values (with-syntax ([(parsed-arguments ...) (parse-arguments #'(args ...))]) @@ -216,7 +217,11 @@ #'rest)] [else (syntax-parse #'head #:literal-sets (cruft) - [x:atom (do-parse #'(rest ...) precedence left #'x)] + [x:atom + (debug "atom ~a current ~a\n" #'x current) + (if current + (values (left current) #'(head rest ...)) + (do-parse #'(rest ...) precedence left #'x))] [(#%parens args ...) (debug "function call ~a\n" left) (values (left (with-syntax ([current current] @@ -238,7 +243,7 @@ (error 'parse "function call")] [else (error 'what "dont know how to parse ~a" #'head)])])])])) - (do-parse input 0 (lambda (x) x) #'(void))) + (do-parse input 0 (lambda (x) x) #f)) (define (empty-syntax? what) (syntax-parse what @@ -275,3 +280,20 @@ parsed (more-parsing . rest))))) #'(debug "regular parsing\n")))) + +;; rest will be some subset of full +(define (parsed-things full rest) + (define full-datum (syntax->datum full)) + (define rest-datum (syntax->datum rest)) + (- (length full-datum) (length rest-datum))) + +(provide honu-expression) +(define-primitive-splicing-syntax-class (honu-expression) + #:attributes (result) + #:description "expression" + (lambda (stx fail) + (debug "honu expression syntax class\n") + (define-values (parsed unparsed) + (parse stx)) + (debug "parsed ~a\n" parsed) + (list (parsed-things stx unparsed) parsed))) diff --git a/collects/honu/core/read.rkt b/collects/honu/core/read.rkt index 0695cf5707..288c3a6cc0 100644 --- a/collects/honu/core/read.rkt +++ b/collects/honu/core/read.rkt @@ -1,5 +1,8 @@ #lang racket/base +;; This module implements read related functions such as `read', `read-syntax', +;; and a colored lexer for drracket + (require rackunit) (require parser-tools/lex (prefix-in : parser-tools/lex-sre))