|
4428 | 4428 | *resolver*
|
4429 | 4429 | basilisp.lang.runtime/resolve-alias)
|
4430 | 4430 |
|
| 4431 | +(defn- read-iterator |
| 4432 | + [opts x] |
| 4433 | + (let [read (:read opts basilisp.lang.reader/read)] |
| 4434 | + (read x |
| 4435 | + *resolver* |
| 4436 | + *data-readers* |
| 4437 | + (:eof opts) |
| 4438 | + (= (:eof opts) :eofthrow) |
| 4439 | + (:features opts) |
| 4440 | + (not= :preserve (:read-cond opts))))) |
| 4441 | + |
4431 | 4442 | (defn read-string
|
4432 | 4443 | "Read a string of Basilisp code.
|
4433 | 4444 |
|
|
4440 | 4451 | ([s]
|
4441 | 4452 | (read-string {:eof :eofthrow} s))
|
4442 | 4453 | ([opts s]
|
4443 |
| - (first (basilisp.lang.reader/read-str s |
4444 |
| - *resolver* |
4445 |
| - *data-readers* |
4446 |
| - (:eof opts) |
4447 |
| - (if (= (:eof opts) :eofthrow) |
4448 |
| - true |
4449 |
| - false) |
4450 |
| - (:features opts) |
4451 |
| - (if (= :preserve (:read-cond opts)) |
4452 |
| - false |
4453 |
| - true))))) |
| 4454 | + (first (read-iterator (assoc opts :read basilisp.lang.reader/read-str) s)))) |
4454 | 4455 |
|
4455 | 4456 | (defn read
|
4456 | 4457 | "Read the next form from the ``stream``\\. If no stream is specified, uses the value
|
|
4468 | 4469 | ([stream]
|
4469 | 4470 | (read stream true nil))
|
4470 | 4471 | ([opts stream]
|
4471 |
| - (first (basilisp.lang.reader/read stream |
4472 |
| - *resolver* |
4473 |
| - *data-readers* |
4474 |
| - (:eof opts) |
4475 |
| - (if (= (:eof opts) :eofthrow) |
4476 |
| - true |
4477 |
| - false) |
4478 |
| - (:features opts) |
4479 |
| - (if (= :preserve (:read-cond opts)) |
4480 |
| - false |
4481 |
| - true)))) |
| 4472 | + (first (read-iterator opts stream))) |
4482 | 4473 | ([stream eof-error? eof-value]
|
4483 |
| - (first (basilisp.lang.reader/read stream |
4484 |
| - *resolver* |
4485 |
| - *data-readers* |
4486 |
| - eof-value |
4487 |
| - eof-error?)))) |
| 4474 | + (first (read-iterator {:eof (if eof-error? :eofthrow eof-value)} stream)))) |
| 4475 | + |
| 4476 | +(defn read-all |
| 4477 | + "Eagerly read all forms from the ``stream``\\. If no stream is specified, uses the |
| 4478 | + value currently bound to :lpy:var:`*in*`. |
| 4479 | + |
| 4480 | + Callers may bind a map of readers to :lpy:var:`*data-readers*` to customize |
| 4481 | + the data readers used reading this string |
| 4482 | + |
| 4483 | + The stream must satisfy the interface of :external:py:class:`io.TextIOBase`\\, but |
| 4484 | + does not require any pushback capabilities. The default |
| 4485 | + ``basilisp.lang.reader.StreamReader`` can wrap any object implementing ``TextIOBase`` |
| 4486 | + and provide pushback capabilities." |
| 4487 | + ([stream] |
| 4488 | + (read-all nil stream)) |
| 4489 | + ([opts stream] |
| 4490 | + (let [eof (python/object)] |
| 4491 | + (->> (read-iterator (assoc opts :eof eof) stream) |
| 4492 | + seq |
| 4493 | + (take-while #(not (identical? % eof))) |
| 4494 | + doall)))) |
4488 | 4495 |
|
4489 | 4496 | (defn eval
|
4490 | 4497 | "Evaluate a form (not a string) and return its result.
|
|
4517 | 4524 | (python/str))
|
4518 | 4525 | ctx (basilisp.lang.compiler.CompilerContext. (or src "<Load Input>"))]
|
4519 | 4526 | (last
|
4520 |
| - (for [form (seq (basilisp.lang.reader/read reader |
4521 |
| - *resolver* |
4522 |
| - *data-readers*))] |
| 4527 | + (for [form (seq (read-all reader))] |
4523 | 4528 | (basilisp.lang.compiler/compile-and-exec-form form
|
4524 | 4529 | ctx
|
4525 | 4530 | *ns*)))))
|
|
0 commit comments