diff options
author | Boutade <thegoofist@protonmail.com> | 2020-03-07 07:12:34 -0600 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2020-03-07 07:12:34 -0600 |
commit | db9bab71b4660062c601ab527b1dfdbcc884cc21 (patch) | |
tree | e072fbb3a2a43c84cd64c8c0f6d16983fb364ef2 /parzival.lisp | |
parent | 1181af61564962efcd3cfcfcb651371d86e86714 (diff) |
added <<ignore-until
Diffstat (limited to 'parzival.lisp')
-rw-r--r-- | parzival.lisp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/parzival.lisp b/parzival.lisp index d00a1d4..4c47c32 100644 --- a/parzival.lisp +++ b/parzival.lisp @@ -123,21 +123,34 @@ in then. If the parse fails the combinator else is run instead." "Consumes the stream one character at a time until PARSER succeeds. The parse value of (<<UNTIL PARSER) is a list of the characters consumed, ending in the value parsed by PARSER." - (lambda (stream) - (let ((collected nil)) - (labels ((rec (stream) - (let ((chkpt (replay-streams:checkpoint stream))) - (<<if (result parser stream) - (progn - (replay-streams:free-checkpoint stream chkpt) - (<<result (reverse (cons result collected)))) - (progn - (replay-streams:rewind-to stream chkpt) - (<<bind <item< - (lambda (item) - (push item collected) - #'rec))))))) - (rec stream))))) + (let ((collected nil)) + (labels ((rec (stream) + (let ((chkpt (replay-streams:checkpoint stream))) + (<<if (result parser stream) + (progn + (replay-streams:free-checkpoint stream chkpt) + (<<result (reverse (cons result collected)))) + (progn + (replay-streams:rewind-to stream chkpt) + (<<bind <item< + (lambda (item) + (push item collected) + #'rec))))))) + #'rec))) + +(defun <<ignore-until (parser) + "Just like <<UNTIL except it does not build up intermediate results. Results + in the result of PARSER." + (labels ((rec (stream) + (let ((chkpt (checkpoint stream))) + (<<if (result parser stream) + (progn + (free-checkpoint stream chkpt) + (<<result result)) + (progn + (rewind-to stream chkpt) + (<<and <item< #'rec)))))) + #'rec)) (defun <<or (&rest parsers) "Tries each parser one after the other, rewinding the input stream after each |