From d76f671d37a8ecfd873fdc24f6e5c176c68b1959 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 26 Nov 2020 18:57:24 -0600 Subject: [PATCH] Update changelog and make arg to peg's error optional. --- CHANGELOG.md | 6 ++++++ src/core/peg.c | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c13352e3..8d14442f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Backtick delimited strings and buffers are now reindented based on the column of the + opening delimiter. WHitespace in columns to the left of the starting column is ignored unless + there are non-space/non-newline characters in that region, in which case the old behavior is preserved. +- Argument to `(error)` combinator in PEGs is now optional. +- Add `(line)` and `(column)` combinators to PEGs to capture source line and column. + This should make error reporting a bit easier. - During installation and release, merge janetconf.h into janet.h for easier install. - Add `upscope` special form. - `os/execute` and `os/spawn` can take streams for redirecting IO. diff --git a/src/core/peg.c b/src/core/peg.c index 56d30159..06e8e650 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -488,8 +488,9 @@ tail: } else { /* Throw generic error */ int32_t start = (int32_t)(text - s->text_start); + LineCol lc = get_linecol_from_position(s, start); int32_t end = (int32_t)(result - s->text_start); - janet_panicf("match error in range (%d:%d)", start, end); + janet_panicf("match error at line %d, column %d", lc.line, lc.col); } return NULL; } @@ -898,7 +899,13 @@ static void spec_not(Builder *b, int32_t argc, const Janet *argv) { spec_onerule(b, argc, argv, RULE_NOT); } static void spec_error(Builder *b, int32_t argc, const Janet *argv) { - spec_onerule(b, argc, argv, RULE_ERROR); + if (argc == 0) { + Reserve r = reserve(b, 2); + uint32_t rule = peg_compile1(b, janet_wrap_number(0)); + emit_1(r, RULE_ERROR, rule); + } else { + spec_onerule(b, argc, argv, RULE_ERROR); + } } static void spec_drop(Builder *b, int32_t argc, const Janet *argv) { spec_onerule(b, argc, argv, RULE_DROP);