(test-parsepos ";blah blah\nfoo" (line-comment) "foo") (test-parsepos "#| a |#foo" (block-comment) "foo") (test-parsepos "#| a #| b |# c |#foo" (block-comment) "foo") (ptest-err "#| abc" (block-comment) "no closing |#") (ptest-err "#|#|#|#|abc|#|#|#xyzzy" (block-comment) "no closing |#") (test-parsepos "#;1 2" (s-expression-comment) " 2") (test-parsepos "#; 1 2" (s-expression-comment) " 2") (test-parsepos " ; foo\n #|blah|# \n abc" (skip-whitespace) "abc") (ptest "\\A" (backslash-sym-char) #\A) ; Test whether our parser parses something the same as ; Arc's builtin reader. (mac rtest (parser input) `(ptest ,input ,parser ',(read input))) (mac rtests (parser . inputs) `(do ,@(map (fn (example) `(rtest ,parser ,example)) inputs))) (rtests (msym-like) "abc" "abc(" "a#b" "\\(" "|abc|" "|\\|abc" "ab|c|") (ptest "." (msym-like) '<>) (ptest "2" (mdigit 2) '<>) (ptest "9" (mdigit 10) #\9) (ptest "A" (mdigit 10) '<>) (ptest "A" (mdigit 16) '#\A) (ptest "1234" (string (mdigits 10)) "1234") (ptest "A65DF" (string (mdigits# 16)) "A65DF") (ptest "3##(" (string (mdigits# 8)) "3##") (mac ptest-exactly (input parser) `(ptest ,input (entire ,parser) (ascons ,input))) (mac ptest-entire1 (input parser) `(testf ,input [parse _ (on-parsefail '<> (do (entire ,parser)) t)] ,parser t)) (mac ptest-entire (parser . inputs) `(do ,@(map (fn (input) `(ptest-entire1 ,input ,parser)) inputs))) (ptest-exactly "1234" (exact-integer 10)) (ptest-exactly "+1234" (exact-integer 10)) (ptest-exactly "-4/1A" (mexact-rational 16)) (ptest-exactly "3/4-15i" (mexact-complex 10)) (ptest-exactly "3###" (minexact-simple 8)) (ptest-exactly "3##." (minexact-simple 10)) (ptest-exactly "3##.#" (minexact-simple 10)) (ptest-exactly "0.1##" (minexact-simple 2)) (ptest-exactly "3#/4" (minexact-simple 10)) (ptest-exactly "3/4##" (minexact-simple 10)) (ptest-exactly "3###/4#" (minexact-simple 10)) (ptest-exactly "3e5" (minexact-normal 10)) (ptest-exactly "3e-5" (minexact-normal 10)) (ptest-exactly "3#.#e+5##" (minexact-normal 10)) (ptest-exactly "+inf.0" (minexact-real 10)) (ptest-exactly "-nan.0" (minexact-real 10)) (ptest-exactly "+3e5i" (minexact-complex 10)) (ptest-exactly "10+3e5i" (minexact-complex 10)) (ptest-exactly "-inf.0@3##.#e-18" (minexact-complex 10)) (ptest-exactly "-inf.0@3##.#e-18" (minexact 10)) (ptest-exactly "3.141e0" (minexact 10)) (ptest-exactly "3.2" (minexact 10)) (ptest-exactly "3" (minexact 10)) (ptest-exactly "3.2" (mbasenumber 10)) (ptest-exactly "3" (mbasenumber 10)) (ptest-exactly "#i3/2" (mgeneral-number 10)) (ptest-exactly "#e3.2" (mgeneral-number 10)) (ptest-entire (mprefixed-number) "#b1010" "#i1010" "#i#b1010" "#b#i1010" "#e3##.#e+4@1/2S8" ) (ptest "\\3(" (symbol-matcher) '((#\\ #\3) |3|)) (rtests (match-sym-or-number) "123" "123(" "123abc" "123abc(" "\\3" "#i3" ) (ptest " 123 foo\n 456 " (values) '(123 foo 456)) (ptest-err "123 #blah" (values) "unable to parse as an Arc value: #blah") (test '(123 456) (fromstring "123 456" (parse-arc))) (rtest (value) "#t") (rtest (value) " #f,") (ptest "n" (string-backslash-char) #\newline) (ptest "09" (backslash-octal) #\nul) (ptest "41abc" (backslash-octal) #\!) (ptest "101" (backslash-octal) #\A) (ptest "x41" (backslash-hex2) #\A) (ptest "u0041" (backslash-hex4) #\A) (ptest "U00000041" (backslash-hex8) #\A) (test-parsepos "\nfoo" (string-backslash-newline) "foo") (ptest "\\u0041" (string-backslash-sequence) #\A) (rtests (simple-string) "\"\"" "\"abc\"" "\"\\n\"" "\"a\\u41!\"" "\"abc\\ndef\"" ) (ptest "tab" (named-char) #\tab) (rtests (char-constant) "#\\null" "#\\space(a b c)" "#\\167" ;; "#\\x41" not implemented in PLT 4.2.1 "#\\u0041" "#\\U00000041" "#\\λ" ) (ptest-err "#\\nulx" (char-constant) "invalid character constant") (ptest ". x )" (dotted-list-ending) 'x) (ptest ".;foo\nx)" (dotted-list-ending) 'x) (ptest ".(x))" (dotted-list-ending) '(x)) (ptests (nonempty-list-values) "a)" '(a) "a b c)" '(a b c) "a . b)" '(a . b) "a b . c)" '(a b . c) ) (rtests (match-list) "()" "(a)" "(a b c)" "(())" "(a (b c (d e ((f)) g) h i) j k)" "(a ; foo\n )" "(a . b)" "(a b . c)" ) (ptest-err "'" (match-quotes) "a ' must be followed by an Arc value") (rtests (match-quotes) "'a" "'(a b c)" "`a" ",@ foo" ",foo" )