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

Address #426 parse errors in *out janet_dostring

This should make its use a little more robust for
simple usage. To avoid printing to stderr, use

janet_table_put(env, janet_ckeywordv("err"), janet_wrap_false());
This commit is contained in:
Calvin Rose 2020-06-22 08:31:07 -05:00
parent d65814c53f
commit 561fc15ae9
2 changed files with 11 additions and 11 deletions

View File

@ -2,6 +2,7 @@
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 - ???
- `janet_dobytes` and `janet_dostring` return parse errors in \*out
- Add `repeat` macro for iterating something n times. - Add `repeat` macro for iterating something n times.
- Add `eachy` (each yield) macro for iterating a fiber. - Add `eachy` (each yield) macro for iterating a fiber.
- Fix `:generate` verb in loop macro to accept non symbols as bindings. - Fix `:generate` verb in loop macro to accept non symbols as bindings.

View File

@ -55,9 +55,10 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
done = 1; done = 1;
} }
} else { } else {
ret = janet_wrap_string(cres.error);
if (cres.macrofiber) { if (cres.macrofiber) {
janet_eprintf("compile error in %s: ", sourcePath); janet_eprintf("compile error in %s: ", sourcePath);
janet_stacktrace(cres.macrofiber, janet_wrap_string(cres.error)); janet_stacktrace(cres.macrofiber, ret);
} else { } else {
janet_eprintf("compile error in %s: %s\n", sourcePath, janet_eprintf("compile error in %s: %s\n", sourcePath,
(const char *)cres.error); (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 */ /* Dispatch based on parse state */
switch (janet_parser_status(&parser)) { switch (janet_parser_status(&parser)) {
case JANET_PARSE_DEAD: case JANET_PARSE_DEAD:
done = 1; done = 1;
break; break;
case JANET_PARSE_ERROR: case JANET_PARSE_ERROR: {
const char *e = janet_parser_error(&parser);
errflags |= 0x04; errflags |= 0x04;
janet_eprintf("parse error in %s: %s\n", ret = janet_cstringv(e);
sourcePath, janet_parser_error(&parser)); janet_eprintf("parse error in %s: %s\n", sourcePath, e);
done = 1; done = 1;
break; 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_ROOT:
case JANET_PARSE_PENDING:
if (index >= len) { if (index >= len) {
janet_parser_eof(&parser); janet_parser_eof(&parser);
} else { } else {