From 5157a333bb6f48b174f823194f96052be018afe3 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Thu, 11 Aug 2011 11:38:45 -0600 Subject: [PATCH] [honu] use brackets to do list lookup instead of using dot --- collects/honu/core/private/extra.rkt | 5 +++++ collects/honu/core/private/honu2.rkt | 1 + collects/honu/core/private/parse2.rkt | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 collects/honu/core/private/extra.rkt diff --git a/collects/honu/core/private/extra.rkt b/collects/honu/core/private/extra.rkt new file mode 100644 index 0000000000..1c6824abc3 --- /dev/null +++ b/collects/honu/core/private/extra.rkt @@ -0,0 +1,5 @@ +#lang racket/base + +(provide do-lookup) +(define (do-lookup data slice) + (list-ref data slice)) diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 52dc4cfe05..5478c483e1 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -94,6 +94,7 @@ #'(let ([left* left] [right* right]) (cond + #; [(list? left*) (list-ref left* right*)] [else (error 'dot "don't know how to deal with ~a and ~a" left* right*)]))))) diff --git a/collects/honu/core/private/parse2.rkt b/collects/honu/core/private/parse2.rkt index 796183b070..d45202dd53 100644 --- a/collects/honu/core/private/parse2.rkt +++ b/collects/honu/core/private/parse2.rkt @@ -16,7 +16,8 @@ ;; phase -1 (require (for-template racket/base - racket/splicing)) + racket/splicing + "extra.rkt")) (provide parse parse-all) @@ -224,19 +225,27 @@ (if current (values (left current) stream) (do-parse #'(rest ...) precedence left #'x))] + ;; [1, 2, 3] -> (list 1 2 3) [(#%brackets stuff ...) (define value (with-syntax ([(data ...) (parse-comma-expression #'(stuff ...))]) #'(list data ...))) + (define lookup (with-syntax ([(data ...) + (parse-comma-expression #'(stuff ...))] + [current current]) + #'(do-lookup current data ...))) (if current - (values (left current) stream) + ;; (values (left current) stream) + (do-parse #'(rest ...) precedence left lookup) (do-parse #'(rest ...) precedence left value))] + ;; block of code [(#%braces stuff ...) (if current (values (left current) stream) (let () (define body (parse-all #'(stuff ...))) (do-parse #'(rest ...) precedence left body)))] + ;; expression or function application [(#%parens args ...) (if current (let ()