Skip to content

Commit

Permalink
Simplify newline classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Apr 3, 2024
1 parent dadaf57 commit 2e31ca3
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions code/pretty-stream.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,22 @@
(defclass fresh-newline (newline)
())

(defclass mandatory-newline (newline)
())

(defclass fill-newline (newline)
())

(defclass linear-newline (newline)
())

(defclass miser-newline (newline)
(defclass terpri-newline (newline)
())

(defclass conditional-newline (newline)
())

(defclass mandatory-conditional-newline (conditional-newline mandatory-newline)
(defclass mandatory-newline (conditional-newline terpri-newline)
())

(defclass fill-conditional-newline (conditional-newline fill-newline)
(defclass fill-newline (conditional-newline)
())

(defclass linear-conditional-newline (conditional-newline linear-newline)
(defclass linear-newline (conditional-newline)
())

(defclass miser-conditional-newline (conditional-newline miser-newline)
(defclass miser-newline (conditional-newline)
())

(defmethod print-object ((obj newline) stream)
Expand Down Expand Up @@ -239,14 +230,14 @@
(block-end (write-char #\> stream))
(fresh-newline (write-char #\r stream))
(fresh-conditional-newline (write-char #\R stream))
(terpri-newline (write-char #\x stream))
(mandatory-newline (write-char #\x stream))
(mandatory-conditional-newline (write-char #\x stream))
(linear-newline (write-char #\l stream))
(linear-conditional-newline (write-char #\L stream))
(linear-newline (write-char #\L stream))
(fill-newline (write-char #\f stream))
(fill-conditional-newline (write-char #\F stream))
(fill-newline (write-char #\F stream))
(miser-newline (write-char #\m stream))
(miser-conditional-newline (write-char #\M stream))
(miser-newline (write-char #\M stream))
(block-indent (write-char #\I stream))
(current-indent (write-char #\i stream))
(advance (write-char #\a stream))
Expand Down Expand Up @@ -540,7 +531,7 @@
(typep instruction 'relative-tab)))))

(defmethod layout
(stream (mode (eql :single-line)) (instruction mandatory-newline))
(stream (mode (eql :single-line)) (instruction terpri-newline))
(declare (ignore stream))
nil)

Expand Down Expand Up @@ -691,20 +682,20 @@

(defmethod pprint-newline (client (stream pretty-stream) (kind (eql :mandatory)))
(declare (ignore client))
(do-pprint-newline stream mandatory-conditional-newline))
(do-pprint-newline stream mandatory-newline))

(defmethod pprint-newline (client (stream pretty-stream) (kind (eql :miser)))
(declare (ignore client))
(when (miser-width (car (blocks stream)))
(do-pprint-newline stream miser-conditional-newline)))
(do-pprint-newline stream miser-newline)))

(defmethod pprint-newline (client (stream pretty-stream) (kind (eql :linear)))
(declare (ignore client))
(do-pprint-newline stream linear-conditional-newline))
(do-pprint-newline stream linear-newline))

(defmethod pprint-newline (client (stream pretty-stream) (kind (eql :fill)))
(declare (ignore client))
(do-pprint-newline stream fill-conditional-newline))
(do-pprint-newline stream fill-newline))

(defmethod pprint-tab (client (stream pretty-stream) (kind (eql :line)) colnum colinc)
(declare (ignore client))
Expand Down Expand Up @@ -856,7 +847,7 @@

(defmethod ngray:stream-write-char ((stream pretty-stream) (char (eql #\Newline)))
(if (head stream)
(do-pprint-newline stream mandatory-newline)
(do-pprint-newline stream terpri-newline)
(terpri (target stream)))
char)

Expand All @@ -874,7 +865,7 @@

(defmethod ngray:stream-terpri ((stream pretty-stream))
(if (head stream)
(do-pprint-newline stream mandatory-newline)
(do-pprint-newline stream terpri-newline)
(terpri (target stream)))
nil)

Expand Down

0 comments on commit 2e31ca3

Please sign in to comment.