Skip to content

Commit

Permalink
Handle restoring READ-SUPPRESS-WAD instances from cache correctly
Browse files Browse the repository at this point in the history
In particular, return kind :SUPPRESS (not :SKIP) from READ-MAYBE-NOTHING so that
the behavior matches the non-cached case (and thus no incorrect additional
READ-MAYBE-NOTHING call is caused).
  • Loading branch information
scymtym committed Jun 16, 2024
1 parent 2362532 commit 5f7a066
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
5 changes: 3 additions & 2 deletions code/read.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
;; Eclector's result stack and advance STREAM.
(multiple-value-prog1
(etypecase cached
(non-cst-wad (values nil :skip cached t))
(cst-wad (values (cst:raw cached) :object cached t)))
(read-suppress-wad (values nil :suppress cached t))
(non-cst-wad (values nil :skip cached t))
(cst-wad (values (cst:raw cached) :object cached t)))
(push cached (first eclector.parse-result::*stack*)) ; HACK
(advance-stream-to-beyond-wad stream cached)))))

Expand Down
39 changes: 37 additions & 2 deletions test/regressions.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(cl:in-package #:incrementalist.test)

(in-suite :incrementalist)
(def-suite* :incrementalist.regressions
:in :incrementalist)

(test regressions
(test various-regressions
"Ensure that inputs which previously caused errors are processed
correctly."
(let ((fiveam:*test-dribble* nil))
Expand Down Expand Up @@ -91,3 +92,37 @@ correctly."
;; one of the FIRST and REST if they refer to the same object.
(test-case "(; (0 . 0) . ())")
(test-case "(0 . 0) . ())"))))

(test kind-of-restored-read-suppressed-wad
"Ensure that `read-maybe-nothing' returns the correct kind for a
`read-suppress-wad' that has been restored from the cache."
(edits-cases ()
(;; A `read-suppress-wad' for `b' is added to the cache.
"(
#+a
b
c
)"
`((inc:cons-wad ((0 0) (4 1)) ()
(inc:skipped-positive-conditional-wad ((1 2) (2 3))
(:feature-expression (inc:existing-symbol-token
:symbol ("KEYWORD" "A")))
,(expected-symbol-wad '((1 4) (1 5)) "A"
:token-class 'inc:existing-symbol-token
:package-name "KEYWORD")
(inc:read-suppress-wad ((2 2) (2 3))))
,(expected-symbol-wad '((3 2) (3 3)) "C")))
;; Remove the wad for the whole reader conditional from the cache. The
;; `read-suppress-wad' can be restored from the cache. The following wad is
;; processed correctly only if the `read-maybe-nothing' call for the
;; `read-suppress-wad' returns the correct kind.
'(progn (:move 1 0) " ")
`((inc:cons-wad ((0 0) (4 1)) ()
(inc:skipped-positive-conditional-wad ((1 3) (2 3))
(:feature-expression (inc:existing-symbol-token
:symbol ("KEYWORD" "A")))
,(expected-symbol-wad '((1 5) (1 6)) "A"
:token-class 'inc:existing-symbol-token
:package-name "KEYWORD")
(inc:read-suppress-wad ((2 2) (2 3))))
,(expected-symbol-wad '((3 2) (3 3)) "C"))))))

0 comments on commit 5f7a066

Please sign in to comment.