mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
(chibi parse): allow (optionally) passing custom fk to parse-commit
Without this patch, parse-commit will unconditionally use a faillure continuation which simply returns `#f`. This may be undesirable in some situations. As such, this commit allows (optionally) passing a custom failure continuation as a second argument. If none is passed the old behavior is used, hence this commit doesn't cause any backwards incompatible API changes. See #822
This commit is contained in:
parent
b4471ad6fd
commit
5fe400c688
1 changed files with 8 additions and 3 deletions
|
@ -520,10 +520,15 @@
|
|||
|
||||
;;> Parse with \var{f} once, keep the first result, and commit to the
|
||||
;;> current parse path, discarding any prior backtracking options.
|
||||
;;> Since prior backtracking options are discarded, prior failure
|
||||
;;> continuations are also not used. By default, \scheme{#f} is
|
||||
;;> returned on failure, a custom failure continuation can be passed
|
||||
;;> as the second argument.
|
||||
|
||||
(define (parse-commit f)
|
||||
(define (parse-commit f . o)
|
||||
(let ((commit-fk (if (pair? o) (car o) (lambda (s i r) #f))))
|
||||
(lambda (source index sk fk)
|
||||
(f source index (lambda (res s i fk) (sk res s i (lambda (s i r) #f))) fk)))
|
||||
(f source index (lambda (res s i fk) (sk res s i commit-fk)) fk))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue