Skip to content

Commit

Permalink
Better interaction between parse results and skipped input
Browse files Browse the repository at this point in the history
* Main change: When *READ-SUPPRESS* is true
  ECLECTOR.PARSE-RESULT:READ{-PRESERVING-WHITESPACE,-FROM-STRING}
  return what MAKE-SKIPPED-INPUT-RESULT returned instead of NIL.

* This removes two kinds of bogus results that were previously
  returned:

  1) Bogus NIL children around non-toplevel skipped input due
     to *READ-SUPPRESS*.

  2) An "orphan" result corresponding to toplevel skipped input due
     to *READ-SUPPRESS*. This result is now returned as the primary
     result as described above.

  In particular, this gets rid of the bogus results mentioned in #69.
  • Loading branch information
scymtym committed Jun 20, 2020
1 parent 81803ec commit 1c2981c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
36 changes: 18 additions & 18 deletions code/parse-result/read.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@
(eclector.base:%reader-error input-stream 'eclector.reader:end-of-file))
(return-from eclector.reader:read-common eof-value))
(let* (;; *START* is used and potentially modified in
;; NOTE-SKIPPED-INPUT to reflect skipped input
;; (comments, reader macros, *READ-SUPPRESS*) before
;; actually reading something.
;; NOTE-SKIPPED-INPUT to reflect skipped input (comments,
;; reader macros, *READ-SUPPRESS*) before actually reading
;; something.
(*start* (source-position client input-stream))
(result (call-next-method))
(children (reverse (first *stack*)))
(end (source-position client input-stream))
(source (make-source-range client *start* end))
(parse-result (make-expression-result
client result children source)))
(push parse-result (second *stack*))
(values result parse-result))))
(result (call-next-method)))
(if *read-suppress*
(values result (first (second *stack*)))
(let* ((children (reverse (first *stack*)))
(end (source-position client input-stream))
(source (make-source-range client *start* end))
(parse-result (make-expression-result
client result children source)))
(push parse-result (second *stack*))
(values result parse-result))))))

;;; Entry points

Expand Down Expand Up @@ -78,13 +80,11 @@
(eof-value nil))
(read-aux client input-stream eof-error-p eof-value t))

(defun read-from-string (client string &optional
(eof-error-p t)
(eof-value nil)
&key
(start 0)
(end nil)
(preserve-whitespace nil))
(defun read-from-string (client string &optional (eof-error-p t)
(eof-value nil)
&key (start 0)
(end nil)
(preserve-whitespace nil))
(let ((index))
(multiple-value-bind (result orphan-results)
(with-input-from-string (stream string :start start :end end
Expand Down
40 changes: 15 additions & 25 deletions test/parse-result/read.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,18 @@
("1 2" nil 1 () 2)

;; Toplevel comments
("#||# 1" nil 1 ((:block-comment (0 . 4))))
("#||# 1" t nil ((:block-comment (0 . 4))
(*read-suppress* (5 . 6))))
("; test" nil :eof (((:line-comment . 1) (0 . 6))))
("; test~% 1" nil 1 (((:line-comment . 1) (0 . 6))))
(";; test~% 1" nil 1 (((:line-comment . 2) (0 . 7))))
(";;; test~% 1" nil 1 (((:line-comment . 3) (0 . 8))))
("#||# 1" nil 1 ((:block-comment (0 . 4))))
("#||# 1" t (*read-suppress* (5 . 6)) ((:block-comment (0 . 4))))
("; test" nil :eof (((:line-comment . 1) (0 . 6))))
("; test~% 1" nil 1 (((:line-comment . 1) (0 . 6))))
(";; test~% 1" nil 1 (((:line-comment . 2) (0 . 7))))
(";;; test~% 1" nil 1 (((:line-comment . 3) (0 . 8))))
;; Toplevel reader conditionals
("#+(or) 1 2" nil (2 . (((:or) . (:or))
(*read-suppress* (7 . 8))
nil))
(*read-suppress* (7 . 8))))
(((:sharpsign-plus . (:or)) (0 . 9))))
("#-(and) 1 2" nil (2 . (((:and) . (:and))
(*read-suppress* (8 . 9))
nil))
(*read-suppress* (8 . 9))))
(((:sharpsign-minus . (:and)) (0 . 10))))

;; Non-toplevel comments
Expand All @@ -334,20 +331,13 @@
;; Non-toplevel reader conditionals
("(#+(or) 1 2)" nil ((2) . (((:sharpsign-plus . (:or)) (1 . 10))
(2 . (((:or) . (:or))
(*read-suppress* (8 . 9))
nil)))))
(*read-suppress* (8 . 9)))))))
;; Order of skipped inputs
("#|1|# #|2|# 3" nil 3 ((:block-comment (0 . 5))
(:block-comment (6 . 11))))
("#|1|# #|2|# 3" t nil ((:block-comment (0 . 5))
(:block-comment (6 . 11))
(*read-suppress* (12 . 13))))
("#|1|# #|2|# 3" nil 3 ((:block-comment (0 . 5))
(:block-comment (6 . 11))))
("#|1|# #|2|# 3" t (*read-suppress* (12 . 13)) ((:block-comment (0 . 5))
(:block-comment (6 . 11))))

;; Non-toplevel suppressed objects
;; FIXME `nil' children are bogus
;; FIXME the suppressed input should not appear as an orphan result
("(nil)" t (nil (*read-suppress* (1 . 4)) nil)
((*read-suppress* (0 . 5))))
("#|1|# (nil)" t (nil (*read-suppress* (7 . 10)) nil)
((:block-comment (0 . 5))
(*read-suppress* (6 . 11)))))))
("(nil)" t (*read-suppress* (0 . 5)) ())
("#|1|# (nil)" t (*read-suppress* (6 . 11)) ((:block-comment (0 . 5)))))))

0 comments on commit 1c2981c

Please sign in to comment.