diff --git a/CHANGELOG.md b/CHANGELOG.md index bfde42a9..870dfa10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- `janet_dobytes` and `janet_dostring` return parse errors in \*out - Add `repeat` macro for iterating something n times. - Add `eachy` (each yield) macro for iterating a fiber. - Fix `:generate` verb in loop macro to accept non symbols as bindings. diff --git a/src/core/run.c b/src/core/run.c index 4e88ca36..f675810a 100644 --- a/src/core/run.c +++ b/src/core/run.c @@ -55,9 +55,10 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char done = 1; } } else { + ret = janet_wrap_string(cres.error); if (cres.macrofiber) { janet_eprintf("compile error in %s: ", sourcePath); - janet_stacktrace(cres.macrofiber, janet_wrap_string(cres.error)); + janet_stacktrace(cres.macrofiber, ret); } else { janet_eprintf("compile error in %s: %s\n", sourcePath, (const char *)cres.error); @@ -67,25 +68,23 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char } } + if (done) break; + /* Dispatch based on parse state */ switch (janet_parser_status(&parser)) { case JANET_PARSE_DEAD: done = 1; break; - case JANET_PARSE_ERROR: + case JANET_PARSE_ERROR: { + const char *e = janet_parser_error(&parser); errflags |= 0x04; - janet_eprintf("parse error in %s: %s\n", - sourcePath, janet_parser_error(&parser)); + ret = janet_cstringv(e); + janet_eprintf("parse error in %s: %s\n", sourcePath, e); done = 1; break; - case JANET_PARSE_PENDING: - if (index == len) { - janet_parser_eof(&parser); - } else { - janet_parser_consume(&parser, bytes[index++]); - } - break; + } case JANET_PARSE_ROOT: + case JANET_PARSE_PENDING: if (index >= len) { janet_parser_eof(&parser); } else {