summaryrefslogtreecommitdiff
path: root/input.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2022-12-04 23:57:17 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2022-12-04 23:57:17 -0300
commitcdbfa453e870756dc32785b23a934b37e28d071c (patch)
treec04629d9c30911f2312718fc95212eb10ef7ecee /input.lisp
parentf205d4c5dbd0ccb26cb9020e3ef8ae86d1336403 (diff)
downloadmonparser-cdbfa453e870756dc32785b23a934b37e28d071c.tar.gz
monparser-cdbfa453e870756dc32785b23a934b37e28d071c.zip
First advances to lookahead implementation
Diffstat (limited to 'input.lisp')
-rw-r--r--input.lisp15
1 files changed, 10 insertions, 5 deletions
diff --git a/input.lisp b/input.lisp
index 3e646b4..4f803ec 100644
--- a/input.lisp
+++ b/input.lisp
@@ -5,17 +5,22 @@
(file nil :read-only t)
(data nil :read-only t))
-(defun has-data? (input)
- (< (input-cursor input)
+(defun has-data? (input &optional (window-size 1))
+ (< (+ window-size -1 (input-cursor input))
(length (input-data input))))
-(defun element (input)
+(defun peek-1 (input)
(char (input-data input)
(input-cursor input)))
-(defun advance (input)
+(defun peek-n (input window-size)
+ (subseq (input-data input)
+ (input-cursor input)
+ window-size))
+
+(defun advance (input &optional (amount 1))
(let ((new-input (copy-structure input)))
- (incf (input-cursor new-input))
+ (incf (input-cursor new-input) amount)
new-input))
(declaim (ftype (function (simple-string) (values input &optional)) from-string))