1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Add the parse function.

This commit is contained in:
Calvin Rose 2020-04-25 12:46:32 -04:00
parent 0a4d58468e
commit 9bc5ac05c4
3 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased - ???
- Add the `parse` function to parse strings of source code more conveniently.
- Add `jpm rule-tree` subcommand.
- Add `--offline` flag to jpm to force use of the cache.
- Allow sending pointers and C functions across threads via `thread/send`.

View File

@ -1,6 +1,7 @@
# This file is invoked by build_win.bat
# Relevant configuration variables are set there.
SetCompressor /FINAL /SOLID lzma
Unicode True
!echo "Program Files: ${PROGRAMFILES}"

View File

@ -2052,6 +2052,19 @@
(res)
(error (res :error))))
(defn parse
"Parse a string and return the first value. For complex parsing, such as for a repl with error handling,
use the parser api."
[str]
(let [p (parser/new)]
(parser/consume p str)
(parser/eof p)
(if (parser/has-more p)
(parser/produce p)
(if (= :error (parser/status p))
(error (parser/error p))
(error "no value")))))
(def make-image-dict
"A table used in combination with marshal to marshal code (images), such that
(make-image x) is the same as (marshal x make-image-dict)."