From cdbfa453e870756dc32785b23a934b37e28d071c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 4 Dec 2022 23:57:17 -0300 Subject: First advances to lookahead implementation --- input.lisp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'input.lisp') 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)) -- cgit v1.2.3