From a60d9bd972f31a79aa0f0f8b10585187dc418fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 15 Oct 2024 18:49:43 -0300 Subject: Pretty print parser-input --- input.lisp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'input.lisp') diff --git a/input.lisp b/input.lisp index 100baa5..15b8e08 100644 --- a/input.lisp +++ b/input.lisp @@ -29,3 +29,12 @@ (setf column 1)) (t (incf column))))) (values line column))) + +(defmethod print-object ((obj parser-input) stream) + (let ((context-length 10)) + (let ((begin (max (- (input-cursor obj) context-length) 0)) + (end (min (+ (input-cursor obj) context-length) (length (input-data obj))))) + (format stream "...~a~a~a..." + (substitute #\¶ #\Newline (subseq (input-data obj) begin (input-cursor obj))) + (substitute #\¶ #\Newline (subseq (input-data obj) (input-cursor obj) (1+ (input-cursor obj)))) + (substitute #\¶ #\Newline (subseq (input-data obj) (1+ (input-cursor obj)) end)))))) -- cgit v1.2.3