rename `parse-tree` as `parse-to-datum`

pull/10/head
Matthew Butterick 8 years ago
parent c58ac2a806
commit 4c02bf36cd

@ -8,4 +8,4 @@
here here
) )
(parse-tree (apply-tokenizer-maker make-tokenizer str)) (parse-to-datum (apply-tokenizer-maker make-tokenizer str))

@ -8,4 +8,4 @@
here here
) )
(parse-tree (apply-tokenizer-maker make-tokenizer str)) (parse-to-datum (apply-tokenizer-maker make-tokenizer str))

@ -1,3 +1,3 @@
#lang br #lang br
(require "parser.rkt") (require "parser.rkt")
(parse-tree "++++-+++-++-++[>++++-+++-++-++<-]>.") (parse-to-datum "++++-+++-++-++[>++++-+++-++-++<-]>.")

@ -2,21 +2,21 @@
(require "parser.rkt" "tokenizer.rkt" brag/support rackunit) (require "parser.rkt" "tokenizer.rkt" brag/support rackunit)
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "// line commment\n")) (apply-tokenizer-maker make-tokenizer "// line commment\n"))
'(jsonic-program)) '(jsonic-program))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "@$ 42 $@")) (apply-tokenizer-maker make-tokenizer "@$ 42 $@"))
'(jsonic-program (jsonic-sexp " 42 "))) '(jsonic-program (jsonic-sexp " 42 ")))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "hi")) (apply-tokenizer-maker make-tokenizer "hi"))
'(jsonic-program '(jsonic-program
(jsonic-char "h") (jsonic-char "h")
(jsonic-char "i"))) (jsonic-char "i")))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer (apply-tokenizer-maker make-tokenizer
"hi\n// comment\n@$ 42 $@")) "hi\n// comment\n@$ 42 $@"))
'(jsonic-program '(jsonic-program

@ -2,21 +2,21 @@
(require "parser.rkt" "tokenizer.rkt" brag/support rackunit) (require "parser.rkt" "tokenizer.rkt" brag/support rackunit)
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "// line commment\n")) (apply-tokenizer-maker make-tokenizer "// line commment\n"))
'(jsonic-program)) '(jsonic-program))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "@$ 42 $@")) (apply-tokenizer-maker make-tokenizer "@$ 42 $@"))
'(jsonic-program (jsonic-sexp " 42 "))) '(jsonic-program (jsonic-sexp " 42 ")))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer "hi")) (apply-tokenizer-maker make-tokenizer "hi"))
'(jsonic-program '(jsonic-program
(jsonic-char "h") (jsonic-char "h")
(jsonic-char "i"))) (jsonic-char "i")))
(check-equal? (check-equal?
(parse-tree (parse-to-datum
(apply-tokenizer-maker make-tokenizer (apply-tokenizer-maker make-tokenizer
"hi\n// comment\n@$ 42 $@")) "hi\n// comment\n@$ 42 $@"))
'(jsonic-program '(jsonic-program

File diff suppressed because it is too large Load Diff

@ -153,13 +153,16 @@
(parse tokenizer))])))])) (parse tokenizer))])))]))
(define parse (make-rule-parser start-id)) (define parse (make-rule-parser start-id))
(provide parse-tree) (provide parse-to-datum parse-tree)
(define (parse-tree x)
(define (parse-to-datum x)
(let loop ([x (syntax->datum (parse x))]) (let loop ([x (syntax->datum (parse x))])
(cond (cond
[(list? x) (map loop x)] [(list? x) (map loop x)]
[(char? x) (string x)] [(char? x) (string x)]
[else x])))))))])) [else x])))
(define parse-tree parse-to-datum)))))]))
;; Given a flattened rule, returns a syntax for the code that ;; Given a flattened rule, returns a syntax for the code that

@ -4,9 +4,9 @@
rackunit) rackunit)
(check-equal? (check-equal?
(parse-tree "\ty\n x\tz") (parse-to-datum "\ty\n x\tz")
'(start (tab "\t") (letter "y") (newline "\n") (space " ") (letter "x") (tab "\t") (letter "z"))) '(start (tab "\t") (letter "y") (newline "\n") (space " ") (letter "x") (tab "\t") (letter "z")))
(check-equal? (check-equal?
(parse-tree "\t\n \t") (parse-to-datum "\t\n \t")
'(start (tab "\t") (newline "\n") (space " ") (tab "\t"))) '(start (tab "\t") (newline "\n") (space " ") (tab "\t")))

Loading…
Cancel
Save