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

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

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

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

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

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

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

@ -849,11 +849,11 @@ If the parse cannot be performed successfully, or if a token in the
@racket[parse] raises an instance of @racket[exn:fail:parsing].}
@defproc[(parse-tree [source any/c #f]
@defproc[(parse-to-datum [source any/c #f]
[token-source (or/c (sequenceof token)
(-> token))])
list?]{
Same as @racket[parse], but the result is converted into a visible parse tree. Useful for testing or debugging a parser.
Same as @racket[parse], but the result is converted into a plain datum. Useful for testing or debugging a parser.
}

@ -153,13 +153,16 @@
(parse tokenizer))])))]))
(define parse (make-rule-parser start-id))
(provide parse-tree)
(define (parse-tree x)
(provide parse-to-datum parse-tree)
(define (parse-to-datum x)
(let loop ([x (syntax->datum (parse x))])
(cond
[(list? x) (map loop 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

@ -4,9 +4,9 @@
rackunit)
(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")))
(check-equal?
(parse-tree "\t\n \t")
(parse-to-datum "\t\n \t")
'(start (tab "\t") (newline "\n") (space " ") (tab "\t")))

Loading…
Cancel
Save