From 1af10ddc10e35805c6723d7a2a85d7e3768497f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 13 Oct 2024 00:51:57 -0300 Subject: Error out on parser failure --- input.lisp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'input.lisp') diff --git a/input.lisp b/input.lisp index e28e73a..100baa5 100644 --- a/input.lisp +++ b/input.lisp @@ -18,3 +18,14 @@ (defun cursor-distance (input1 input2) (- (input-cursor input1) (input-cursor input2))) + +(defun line-and-column (input) + (let ((line 1) (column 1)) + (dotimes (i (input-cursor input)) + (let ((c (char (input-data input) i))) + (case c + (#\Newline + (incf line) + (setf column 1)) + (t (incf column))))) + (values line column))) -- cgit v1.2.3