Commit 9f55a85faddfed19d658f3c0e310937b80689d0d

Thomas de Grivel 2018-06-29T04:53:16

match-until function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/token-stream.lisp b/token-stream.lisp
index 2181856..0a903fb 100644
--- a/token-stream.lisp
+++ b/token-stream.lisp
@@ -271,6 +271,16 @@ stack."))
      (lexer-input lx)
      (incf (the fixnum (lexer-match-start lx)))))
 
+(defmethod match-until ((lx lexer) (f function))
+  (loop
+     (let ((match (funcall f lx)))
+       (when match
+         (return match)))
+     (when (lexer-input-ended lx)
+       (return))
+     (lexer-input lx)
+     (incf (the fixnum (lexer-match-start lx)))))
+
 (defmethod match-option ((lx lexer) (f function))
   (or (funcall f lx)
       (lexer-match-start lx)))