don't put chars in parse tree

pull/6/head
Matthew Butterick 7 years ago
parent 954069276d
commit 9aad4b0f24

@ -167,7 +167,6 @@
(let loop ([x (syntax->datum (PARSE x))])
(cond
[(list? x) (map loop x)]
[(char? x) (string x)]
[else x])))
(define PARSE-TREE PARSE-TO-DATUM)))))]))

@ -76,11 +76,9 @@
[(? symbol?)
(lookup next-token next-token start end)]
[(? string?)
(lookup (string->symbol next-token) next-token start end)]
[(? char?)
(lookup (string->symbol (string next-token)) next-token start end)]
[(or (? string?) (? char?))
(define next-token-str (format "~a" next-token))
(lookup (string->symbol next-token-str) next-token-str start end)]
;; Compatibility
[(? lex:token?)

@ -6,25 +6,25 @@
(check-equal? (syntax->datum (parse ""))
'(equal))
(check-equal? (syntax->datum (parse "01"))
'(equal (zero (equal) #\0)
(one (equal) #\1)))
'(equal (zero (equal) "0")
(one (equal) "1")))
(check-equal? (syntax->datum (parse "10"))
'(equal (one (equal) #\1)
(zero (equal) #\0)))
'(equal (one (equal) "1")
(zero (equal) "0")))
(check-equal? (syntax->datum (parse "0011"))
'(equal (zero (equal) #\0)
(one (equal (zero (equal) #\0)
(one (equal) #\1))
#\1)))
'(equal (zero (equal) "0")
(one (equal (zero (equal) "0")
(one (equal) "1"))
"1")))
(check-equal? (syntax->datum (parse "0110"))
'(equal (one (equal (zero (equal) #\0)
(one (equal) #\1))
#\1)
(zero (equal) #\0)))
'(equal (one (equal (zero (equal) "0")
(one (equal) "1"))
"1")
(zero (equal) "0")))
(check-equal? (syntax->datum (parse "1100"))
'(equal (one (equal) #\1)
(zero (equal (one (equal) #\1)
(zero (equal) #\0))
#\0)))
'(equal (one (equal) "1")
(zero (equal (one (equal) "1")
(zero (equal) "0"))
"0")))

@ -16,4 +16,12 @@
(check-equal?
(syntax->datum
(parse "[[[{}]],[],[[{}]]]"))
'(json (array #\[ (json (array #\[ (json (array #\[ (json) #\])) #\])) #\, (json (array #\[ #\])) #\, (json (array #\[ (json (array #\[ (json) #\])) #\])) #\])))
'(json
(array
"["
(json (array "[" (json (array "[" (json) "]")) "]"))
","
(json (array "[" "]"))
","
(json (array "[" (json (array "[" (json) "]")) "]"))
"]")))

@ -18,7 +18,15 @@
(check-equal?
(syntax->datum
(parse "[[[{}]],[],[[{}]]]"))
'(json (array #\[ (json (array #\[ (json (array #\[ (json (object #\{ #\})) #\])) #\])) #\, (json (array #\[ #\])) #\, (json (array #\[ (json (array #\[ (json (object #\{ #\})) #\])) #\])) #\])))
'(json
(array
"["
(json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]"))
","
(json (array "[" "]"))
","
(json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]"))
"]")))

Loading…
Cancel
Save