|
4437 | 4437 | *default-data-reader-fn*
|
4438 | 4438 | nil)
|
4439 | 4439 |
|
4440 |
| -(defn- read-iterator |
4441 |
| - [opts x] |
4442 |
| - (let [read (:read opts basilisp.lang.reader/read)] |
4443 |
| - (read x |
4444 |
| - *resolver* |
4445 |
| - *data-readers* |
4446 |
| - (:eof opts) |
4447 |
| - (= (:eof opts) :eofthrow) |
4448 |
| - (:features opts) |
4449 |
| - (not= :preserve (:read-cond opts))))) |
| 4440 | +(defn read-seq |
| 4441 | + "Create an lazy sequence that will contain each form from the |
| 4442 | + ``stream``\\. If no stream is specified, uses the value currently |
| 4443 | + bound to :lpy:var:`*in*`. It is the callers responsibility to ensure |
| 4444 | + that the stream resource is not closed before the sequence has been |
| 4445 | + realised. |
| 4446 | + |
| 4447 | + Callers may bind a map of readers to :lpy:var:`*data-readers*` to customize |
| 4448 | + the data readers used reading this string |
| 4449 | + |
| 4450 | + The stream must satisfy the interface of :external:py:class:`io.TextIOBase`\\, but |
| 4451 | + does not require any pushback capabilities. The default |
| 4452 | + ``basilisp.lang.reader.StreamReader`` can wrap any object implementing ``TextIOBase`` |
| 4453 | + and provide pushback capabilities." |
| 4454 | + ([stream] |
| 4455 | + (read-seq {} stream)) |
| 4456 | + ([opts stream] |
| 4457 | + (let [read (:read opts basilisp.lang.reader/read)] |
| 4458 | + (lazy-seq (read stream |
| 4459 | + *resolver* |
| 4460 | + *data-readers* |
| 4461 | + (:eof opts) |
| 4462 | + (= (:eof opts) :eofthrow) |
| 4463 | + (:features opts) |
| 4464 | + (not= :preserve (:read-cond opts))))))) |
4450 | 4465 |
|
4451 | 4466 | (defn read-string
|
4452 | 4467 | "Read a string of Basilisp code.
|
|
4460 | 4475 | ([s]
|
4461 | 4476 | (read-string {:eof :eofthrow} s))
|
4462 | 4477 | ([opts s]
|
4463 |
| - (first (read-iterator (assoc opts :read basilisp.lang.reader/read-str) s)))) |
| 4478 | + (first (read-seq (assoc opts :read basilisp.lang.reader/read-str) s)))) |
4464 | 4479 |
|
4465 | 4480 | (defn read
|
4466 | 4481 | "Read the next form from the ``stream``\\. If no stream is specified, uses the value
|
|
4479 | 4494 | ([stream]
|
4480 | 4495 | (read stream true nil))
|
4481 | 4496 | ([opts stream]
|
4482 |
| - (first (read-iterator opts stream))) |
| 4497 | + (first (read-seq opts stream))) |
4483 | 4498 | ([stream eof-error? eof-value]
|
4484 |
| - (first (read-iterator {:eof (if eof-error? :eofthrow eof-value)} stream)))) |
4485 |
| - |
4486 |
| -(defn read-all |
4487 |
| - "Eagerly read all forms from the ``stream``\\. If no stream is specified, uses the |
4488 |
| - value currently bound to :lpy:var:`*in*`. |
4489 |
| - |
4490 |
| - Callers may bind a map of readers to :lpy:var:`*data-readers*` or a default data |
4491 |
| - reader function to :lpy:var::`*default-data-reader-fn*` to customize the data |
4492 |
| - readers used reading this string |
4493 |
| - |
4494 |
| - The stream must satisfy the interface of :external:py:class:`io.TextIOBase`\\, but |
4495 |
| - does not require any pushback capabilities. The default |
4496 |
| - ``basilisp.lang.reader.StreamReader`` can wrap any object implementing ``TextIOBase`` |
4497 |
| - and provide pushback capabilities." |
4498 |
| - ([stream] |
4499 |
| - (read-all nil stream)) |
4500 |
| - ([opts stream] |
4501 |
| - (let [eof (python/object)] |
4502 |
| - (->> (read-iterator (assoc opts :eof eof) stream) |
4503 |
| - seq |
4504 |
| - (take-while #(not (identical? % eof))) |
4505 |
| - doall)))) |
| 4499 | + (first (read-seq {:eof (if eof-error? :eofthrow eof-value)} stream)))) |
4506 | 4500 |
|
4507 | 4501 | (defn eval
|
4508 | 4502 | "Evaluate a form (not a string) and return its result.
|
|
4535 | 4529 | (python/str))
|
4536 | 4530 | ctx (basilisp.lang.compiler.CompilerContext. (or src "<Load Input>"))]
|
4537 | 4531 | (last
|
4538 |
| - (for [form (seq (read-all reader))] |
| 4532 | + (for [form (read-seq {} reader)] |
4539 | 4533 | (basilisp.lang.compiler/compile-and-exec-form form
|
4540 | 4534 | ctx
|
4541 | 4535 | *ns*)))))
|
|
0 commit comments