Improve peg error on unknown rule.
This helps a lot when debugging large, failing grammars.
@@ -887,8 +887,10 @@ static uint32_t peg_compile1(Builder *b, Janet peg) {
JanetTable *grammar = old_grammar;
for (; i > 0 && janet_checktype(peg, JANET_KEYWORD); --i) {
peg = janet_table_get_ex(grammar, peg, &grammar);
- if (!grammar)
- peg_panic(b, "unknown rule");
+ if (!grammar || janet_checktype(peg, JANET_NIL)) {
+ builder_cleanup(b);
+ janet_panicf("grammar error in %p, unknown rule", b->form);
+ }
b->form = peg;
b->grammar = grammar;
}
