s-expressionists / Eclector

A portable Common Lisp reader that is highly customizable, can recover from errors and can return concrete syntax trees
https://s-expressionists.github.io/Eclector/
BSD 2-Clause "Simplified" License
109 stars 9 forks source link

Issue with source-location. #47

Closed FiV0 closed 5 years ago

FiV0 commented 5 years ago

When taking the README example with the following input:

(with-input-from-string (stream "1 ") ;; with an extra space
  (eclector.parse-result:read (make-instance 'my-client) stream))

the source-location of the 1 is considered to be the range (0 . 2) where I think it should be (0 . 1). I think removing this when might fix the issue, but I am not sure it serves another purpose.

scymtym commented 5 years ago

I have encountered this problem as well and have been thinking about solutions.

I don't think simply not consuming the whitespace is the right solution since that would make the behavior of eclector.parse-result:read different from eclector.reader:read.

A potential solution I have been experimenting with is calling eclector.reader:read-preserving-whitespace instead of eclector.reader:read from eclector.parse-result:read. This could maybe be followed up by consuming any tailing whitespace. If this works, it would not consider the trailing whitespace in the source location but still skip it before returning to the caller.