summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-15 18:49:43 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-15 18:49:43 -0300
commita60d9bd972f31a79aa0f0f8b10585187dc418fe8 (patch)
tree6f0fe9f7812bb92e8ec81bc2bc4b8a7af8f4639c
parentfd376f92536a7a1d8016292f5dbbab9e5af964e3 (diff)
downloadmonparser-a60d9bd972f31a79aa0f0f8b10585187dc418fe8.tar.gz
monparser-a60d9bd972f31a79aa0f0f8b10585187dc418fe8.zip
Pretty print parser-input
-rw-r--r--input.lisp9
1 files changed, 9 insertions, 0 deletions
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))))))