1
0
mirror of https://github.com/janet-lang/janet synced 2025-05-09 19:04:13 +00:00

Reference #478 Update peg/compile to use dyn for default grammar.

This commit is contained in:
Calvin Rose 2021-01-23 13:54:02 -06:00
parent c909835b0a
commit 85155bb2b4
4 changed files with 14 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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 <core/peg>. 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,