From 9bc5ac05c4d9fe95d3193a283205e565b300a19e Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 25 Apr 2020 12:46:32 -0400 Subject: [PATCH] Add the parse function. --- CHANGELOG.md | 1 + janet-installer.nsi | 1 + src/boot/boot.janet | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8285f176..537be111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/janet-installer.nsi b/janet-installer.nsi index 8348dca5..92946feb 100644 --- a/janet-installer.nsi +++ b/janet-installer.nsi @@ -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}" diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 6053070b..9f34f2e6 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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)."