Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

READ-FROM-STRING-WITH-SOURCE-POSITIONS #89

Open
brpocock opened this issue Aug 2, 2017 · 0 comments
Open

READ-FROM-STRING-WITH-SOURCE-POSITIONS #89

brpocock opened this issue Aug 2, 2017 · 0 comments

Comments

@brpocock
Copy link
Member

brpocock commented Aug 2, 2017

For second-generation source maps (ref: #87 ), the longer-term solution will require tighter integration with the Reader. Since READ returns whole objects, it could be rewritten to have a lower-level function JSCL:Read-With-Source-Positions (and JSCL:Read-From-String-With-Source-Positions) that returns the FILE-POSITION (resp. string index) associated with the start and end of (recursively) reading each object.

CL:READ can then be simply a wrapper that discards the extra values. Or, both can be (tail-call friendly) front-ends for a back-end function that takes a parameter as to whether or not to return the additional value. Or we could maybe just return the extra value all the time (is that allowed per ANSI?)

This could also be quite useful in implementing a nice Listener later, as it should also enable reading partial expressions … any incomplete strings, lists, &c. that trail off in the partially-read expression would be closed out, and the end-positions of them all set to NIL, indicating that they're unfinished. Thus, reading

   (LIST A B "C" "D

… the String "D" would have a start-position, but no end-position, as well as the containing List.

Type:

 (function (&optional (or stream boolean) t t t t) (values t list))

 (defun read-with-source-positions (&optional (stream *standard-input*)
                                                           (eof-error-p t) (eof-value nil)
                                                           (recursive-p nil) (incomplete-error-p t))
        …
        (values object-read alist-of-positions))

… where alist-of-positions references object-read and sub-objects used to create it, ergō

 "(:a :b \"string\" 99)"
 ↓
  (values #1=(:a :b #2="string" 99)
              ( ( #1# 0 18 )
                ( :a 1 2 )
                ( :b 4 5 )
                ( #2# 7 14 )
                ( 99 16 17 ) ))
@brpocock brpocock mentioned this issue Aug 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant