diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-15 18:49:43 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-15 18:49:43 -0300 |
commit | a60d9bd972f31a79aa0f0f8b10585187dc418fe8 (patch) | |
tree | 6f0fe9f7812bb92e8ec81bc2bc4b8a7af8f4639c | |
parent | fd376f92536a7a1d8016292f5dbbab9e5af964e3 (diff) | |
download | monparser-a60d9bd972f31a79aa0f0f8b10585187dc418fe8.tar.gz monparser-a60d9bd972f31a79aa0f0f8b10585187dc418fe8.zip |
Pretty print parser-input
-rw-r--r-- | input.lisp | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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[1;33m~a[m~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)))))) |