1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00

Add parse-all function as a natural extension to the parse function.

This commit is contained in:
Calvin Rose 2022-05-28 18:43:11 -05:00
parent dfa78ad3c6
commit 2f64a6b0cb
2 changed files with 16 additions and 1 deletions

View File

@ -2,7 +2,8 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## Unreleased - ???
- Added `os/cpu-count` to get the number of available processors on a machine - Add `parse-all` as a generalization of the `parse` function.
- Add `os/cpu-count` to get the number of available processors on a machine
## 1.22.0 - 2022-05-09 ## 1.22.0 - 2022-05-09
- Prohibit negative size argument to `table/new`. - Prohibit negative size argument to `table/new`.

View File

@ -2575,6 +2575,20 @@
(error (parser/error p)) (error (parser/error p))
(error "no value"))))) (error "no value")))))
(defn parse-all
`Parse a string and return all parsed values. For complex parsing, such as for a repl with error handling,
use the parser api.`
[str]
(let [p (parser/new)
ret @[]]
(parser/consume p str)
(parser/eof p)
(while (parser/has-more p)
(array/push ret (parser/produce p)))
(if (= :error (parser/status p))
(error (parser/error p))
ret)))
(def load-image-dict (def load-image-dict
``A table used in combination with `unmarshal` to unmarshal byte sequences created ``A table used in combination with `unmarshal` to unmarshal byte sequences created
by `make-image`, such that `(load-image bytes)` is the same as `(unmarshal bytes load-image-dict)`.`` by `make-image`, such that `(load-image bytes)` is the same as `(unmarshal bytes load-image-dict)`.``