;; works as expected
(run (attempt (p/char \space)) " ")
==> \space
;; expected nil
(run (attempt (p/char \space)) "")
==> Unexpected end of input at line: 1 column: 1
[Thrown class java.lang.RuntimeException]
;; expected nil
(run (attempt (p/char \space)) "x")
==> Unexpected token 'x' at line: 1 column: 1
[Thrown class java.lang.RuntimeException]
From the docstring “A parser that will attempt to parse p, and upon failure never consume any input” it was not clear to me, that attempt would throw an Exception.
From the docstring “A parser that will attempt to parse p, and upon failure never consume any input” it was not clear to me, that
attemptwould throw an Exception.