Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to basic-parsers #935

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/std/text/basic-parsers-test.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(import
:std/error
(only-in :std/parser/base parse-error?)
:std/sugar
:std/test
:std/text/basic-parsers)

(export basic-parsers-test)

(defrule (check-parse parser string result)
(begin
(check-equal? (parse-string parser string) result)
(check-equal? (call-with-input-string string (cut parse-port parser <>)) result)))
(defrule (check-parse-error parser string)
(begin
(check-exception (parse-string parser string) parse-error?)
(check-exception (call-with-input-string string (cut parse-port parser <>)) parse-error?)))

(def basic-parsers-test
(test-suite "test suite for std/misc/basic-parsers"
(test-case "1"
(check-parse parse-natural "1" 1)
(check-parse parse-natural "010" 10) ;; ain't no octal
(check-parse (cut parse-natural <> 8) "10" 8) ;; octal this time.
(check-parse-error parse-natural " 1") ;; no space allowed in front unless you ask
(check-parse-error parse-natural "1 no junk allowed"))
(test-case "parse-integer"
(check-equal? 1 1))))
4 changes: 2 additions & 2 deletions src/std/text/basic-parsers.ss
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

;; Parse an entire port
(def (parse-port parser port (description port) (where 'parse-port))
(parse-reader parser (PeekableStringReader (make-raw-input-port port)) description where))
(parse-reader parser (PeekableStringReader (make-raw-textual-input-port port)) description where))

;; Parse an entire file
(def (parse-file parser file (description file) (where 'parse-file))
Expand Down Expand Up @@ -198,7 +198,7 @@
(parse-or
(parse-begin parse-terminator (parse-pure '()))
(parse-bind parse-element
(lambda (e) (parse-repeated (parse-begin parse-separator parse-element)
(lambda (e) (parse-repeated (parse-begin parse-separator parse-element)
parse-terminator [e])))))
(def ((parse-n-repeats n parse-element) reader)
(for/collect ((_ (in-range n))) (parse-element reader)))
Expand Down