Skip to content

Commit

Permalink
Fixes to basic-parsers (#935)
Browse files Browse the repository at this point in the history
Fix early-onset bitrot, add a couple regression tests.
  • Loading branch information
fare authored Sep 28, 2023
1 parent e1bc3c9 commit 2d7f312
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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

0 comments on commit 2d7f312

Please sign in to comment.