Merge pull request #824 from nmeum/parse-commit-fk

`(chibi parse)`: allow (optionally) passing custom fk to parse-commit
This commit is contained in:
Alex Shinn 2022-04-14 10:16:33 +09:00 committed by GitHub
commit 899a6bace3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -520,10 +520,15 @@
;;> Parse with \var{f} once, keep the first result, and commit to the ;;> Parse with \var{f} once, keep the first result, and commit to the
;;> current parse path, discarding any prior backtracking options. ;;> 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) (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))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;