|
4 weeks ago | |
---|---|---|
examples | 4 weeks ago | |
margaret | 2 months ago | |
support | 2 months ago | |
test | 2 months ago | |
README.adoc | 2 months ago | |
notes.txt | 2 months ago | |
project.janet | 2 months ago |
This aims to be a pure-Janet implementation of Janet’s peg/match
.
While reading bakpakin’s How Janet’s PEG module works, started typing the code in and evaluating it, next thing I knew…
In progress, see Specials Implementation Status for details.
Aid in understanding Janet’s PEG system
Generate example PEG specials usages
Experiment with adding diagnostic info / tracing
Experiment with additional constructs
Clone this repository and cd to the relevant directory
Ensure janet
and jpm
are on your PATH
Install if you like: jpm install
meg/match
is an attempt at implementing peg/match
, so for example:
(import margaret/meg)
(meg/match ~(capture (some "smile")) "smile!")
should work.
There is some support for diagnostic output via the dynamic variable
:meg-debug
.
To try it, do:
(setdyn :meg-debug true)
or for more detailed info:
(setdyn :meg-debug {:captures true
:peg true
:text true})
before calling meg/match
.
Output format is still evolving but likely will support at least:
capture stack
tags
specials execution order
Run all tests by:
jpm test
from the project directory of margaret
There are currently tests for:
Some of the tests were adapted / copied from Janet’s tests.
Each of the 48 Janet PEG specials has an initial implementation with tests. Specifically, that includes:
Primitive Patterns
Combinators
Captures
In many cases an attempt to follow the original
peg.c
implementation by bakpakin was made. Some motivations for doing so
include:
If peg.c
changes, tracking those changes may be easier.
If an experimentally added special in margaret proves useful, it
might be easier to port it to peg.c
.
Arriving at a correct implementation might be easier because comparing it with a similar one is more meaningful.
Debugging information obtained here might be more relevant when
trying to understand a situation in the original peg.c
context.
Reading margaret’s implementation might be an easier place to start
if one wants to study peg.c
.
Some differences include:
peg.c
creates a bytecode representation before execution and some
information (e.g. tag names) is not retained. In at least one case,
some uses of range
get compiled to the same type of bytecode
instruction used by set
.
peg.c
has protections for too much recursion.
Thanks to (at least) the following folks:
ahungry
andrewchambers
bakpakin
crocket
goto-engineering
GrayJack
ikarius
jcmkk3
LeafGarland
leahneukirchen
LeviSchuck
MikeBeller
nate
pepe
pyrmont
Saikyun
skuza
subsetpark
swlkr
tami5
uvtc
yumaikas
…and other Janet community members :)