Last active
May 7, 2021 10:27
-
-
Save sogaiu/ce48cb7ddc9421b5e457891d4763558f to your computer and use it in GitHub Desktop.
some issues encountered when learning to use janet's peg system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* the return value of `peg/match` is either `nil` -- which means that overall | |
matching failed (though submatches might have succeeded) -- or an array | |
that can contain matches (see below for more details). many of the | |
initial examples don't actually "capture" though so one keeps seeing | |
an empty array as a return value. | |
* `peg/match` does do matching, but it also "captures" along with the ability | |
to perform essentially arbitrary computations on values that are "captured". | |
so the name `peg/match` might be seen as a bit misleading. | |
* the name "capture stack". it's true that there is a stack on to which | |
things get captured, but this is not all that happens there. stuff can | |
get removed via `drop`. stuff can be replaced by `group`. | |
* had difficulty with the names `*` and `+` (which appear inherited from | |
lpeg) due to these being used to mean quite different things in the | |
context of regular expressions. luckily, one can use `sequence` and | |
`choice` instead and gradually get used to them. | |
* no name for the idea of the index / spot that the matching is about to | |
take place at. many references in the documentation say "advances" or | |
"does not advance", but it is kind of awkward to not have something one | |
can refer to which is or is not advancing. | |
* there is no tracing for `peg/match`. it's a black box. it's powerful, but | |
not really easily subject to introspection (it is possible via gdb fwiw). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment