diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-05 12:08:08 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-05 12:08:08 -0300 |
commit | c0e6ab7f1be115c2f3079d74eaa247cab89d1ef0 (patch) | |
tree | daf308fd32fe105c3d7a1d2839492a1b4e198811 /parser.lisp | |
parent | bb97077120cfa3966f0d43a7a1447d87ef8c818c (diff) | |
download | monparser-c0e6ab7f1be115c2f3079d74eaa247cab89d1ef0.tar.gz monparser-c0e6ab7f1be115c2f3079d74eaa247cab89d1ef0.zip |
Keep the one-of option that parsed the most
Diffstat (limited to 'parser.lisp')
-rw-r--r-- | parser.lisp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/parser.lisp b/parser.lisp index 2fe6f67..b231f14 100644 --- a/parser.lisp +++ b/parser.lisp @@ -85,14 +85,19 @@ (declare (ignore lazy)) (labels ((one-of-rec (parsers) (let ((intermediate-parsers '()) - (result (make-failure :place input - :message "Exausted options."))) + (result nil)) (dolist (p parsers) (let ((r (funcall p input (> (length parsers) 1)))) (cond ((functionp r) (push r intermediate-parsers)) ((parsing-p r) - (setf result r))))) + (when (or (not (parsing-p result)) + (> (cursor (parsing-input r)) + (cursor (parsing-input result)))) + (setf result r))) + ((failure-p r) + (when (failure-p result) + (setf result r)))))) (if intermediate-parsers (one-of-rec intermediate-parsers) result)))) |