Commit 2032124d5f39279117b435fc3763c40b3c6c4af3

Thomas de Grivel 2018-06-18T10:27:01

fix parser input

diff --git a/parser.lisp b/parser.lisp
index 324c6cf..0efe58d 100644
--- a/parser.lisp
+++ b/parser.lisp
@@ -78,21 +78,21 @@
      (let ((length (- (the fixnum (fill-pointer (parser-buffer pr)))
                       (the fixnum (parser-match-start pr)))))
        (declare (type fixnum length))
-       (when (parser-input-ended pr)
-         (return))
        (unless (< length n)
+         (return t))
+       (when (parser-input-ended pr)
          (return))
        (parser-input pr))))
 
 (defmethod parser-match-token ((pr parser) (index integer))
   (declare (type fixnum index))
-  (parser-input-n pr (the fixnum (1+ index)))
-  (let ((buf (parser-buffer pr))
-        (match-index (+ (the fixnum (parser-match-start pr))
-                        index)))
-    (declare (type vector buf)
-             (type fixnum match-index))
-    (aref (the (vector token) buf) match-index)))
+  (when (parser-input-n pr (the fixnum (1+ index)))
+    (let ((buf (parser-buffer pr))
+          (match-index (+ (the fixnum (parser-match-start pr))
+                          index)))
+      (declare (type vector buf)
+               (type fixnum match-index))
+      (aref (the (vector token) buf) match-index))))
 
 ;;  Matcher