From 8e917003bc243498e32547d214019ff9b48b36ec Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 24 Aug 2016 14:16:08 -0700 Subject: [PATCH] add `parse-tree` --- brag/brag/codegen/codegen.rkt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/brag/brag/codegen/codegen.rkt b/brag/brag/codegen/codegen.rkt index a44b12a..fa985ba 100755 --- a/brag/brag/codegen/codegen.rkt +++ b/brag/brag/codegen/codegen.rkt @@ -152,7 +152,14 @@ (parameterize ([current-source source]) (parse tokenizer))])))])) - (define parse (make-rule-parser start-id))))))])) + (define parse (make-rule-parser start-id)) + (provide parse-tree) + (define (parse-tree x) + (let loop ([x (syntax->datum (parse x))]) + (cond + [(list? x) (map loop x)] + [(char? x) (format "~a" x)] + [else x])))))))])) ;; Given a flattened rule, returns a syntax for the code that @@ -221,7 +228,7 @@ ;; ('hide value is handled at the top of this conditional ;; we need to use boolean because a symbol is treated as an identifier. ;; also we'll separate it into its own property for clarity and test for it in "runtime.rkt" - #`(list (syntax-property $X 'splice-rh-id #,(and (syntax-property primitive-pattern 'hide) #t)))] + #`(list (syntax-property $X 'splice-rh-id #,(and (syntax-property primitive-pattern 'hide) #t)))] [(lit val) #'(list (atomic-datum->syntax $X $X-start-pos $X-end-pos))] [(token val)