From 85155bb2b4b30870eee583a6bf635c6f521dd5cc Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 23 Jan 2021 13:54:02 -0600 Subject: [PATCH] Reference #478 Update peg/compile to use dyn for default grammar. --- CHANGELOG.md | 2 ++ src/boot/boot.janet | 4 +++- src/core/ev.c | 1 - src/core/peg.c | 11 +++++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff23c354..70434837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## ??? - Unreleased +- Use `(dyn :peg-grammar)` for passing a default grammar to `peg/compile` instead of loading + `default-peg-grammar` directly from the root environment. - Add `ev/thread` for combining threading with the event loop. - Add `ev/do-thread` to make `ev/thread` easier to use. - Automatically set supervisor channel in `net/accept-loop` and `net/server` correctly. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 13c1daa0..9ad70396 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2007,7 +2007,7 @@ :a (range "az" "AZ") :s (set " \t\r\n\0\f\v") :w (range "az" "AZ" "09") - :h (range "09" "af") + :h (range "09" "af" "AF") :S (if-not :s 1) :W (if-not :w 1) :A (if-not :a 1) @@ -2024,6 +2024,8 @@ :s* (any :s) :h* (any :h)}) +(setdyn :peg-grammar default-peg-grammar) + ### ### ### Evaluation and Compilation diff --git a/src/core/ev.c b/src/core/ev.c index abdf22f1..5effda18 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -2056,7 +2056,6 @@ static JanetEVGenericMessage janet_go_thread_subr(JanetEVGenericMessage args) { JANET_MARSHAL_UNSAFE, NULL, &nextbytes); if (!janet_checktype(fiberv, JANET_FIBER)) janet_panic("expected fiber"); JanetFiber *fiber = janet_unwrap_fiber(fiberv); - janet_gcroot(fiberv); janet_schedule(fiber, value); janet_loop(); args.tag = JANET_EV_TCTAG_NIL; diff --git a/src/core/peg.c b/src/core/peg.c index c3628839..ba0f0a8a 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -1486,7 +1486,13 @@ static JanetPeg *make_peg(Builder *b) { static JanetPeg *compile_peg(Janet x) { Builder builder; builder.grammar = janet_table(0); - builder.default_grammar = janet_get_core_table("default-peg-grammar"); + builder.default_grammar = NULL; + { + Janet default_grammarv = janet_dyn("peg-grammar"); + if (janet_checktype(default_grammarv, JANET_TABLE)) { + builder.default_grammar = janet_unwrap_table(default_grammarv); + } + } builder.tags = janet_table(0); builder.constants = NULL; builder.bytecode = NULL; @@ -1656,7 +1662,8 @@ static const JanetReg peg_cfuns[] = { "peg/compile", cfun_peg_compile, JDOC("(peg/compile peg)\n\n" "Compiles a peg source data structure into a . This will speed up matching " - "if the same peg will be used multiple times.") + "if the same peg will be used multiple times. Will also use `(dyn :peg-grammar)` to suppliment " + "the grammar of the peg for otherwise undefined peg keywords.") }, { "peg/match", cfun_peg_match,