Closed hostilefork closed 3 years ago
...cc'ing @codebybrett because I think the usermode PARSE code is up the alley of the "generalized dialect evaluator". It's really pretty neat:
Introducing UPARSE, the hackable usermode parse
cc'ing @giuliolunati since he may not be following the forum
cc'ing @rgchris to see specifically this COLLECT/KEEP feature added via combinators, and to discuss it, as he hasn't mentioned grokking UPARSE yet.
cc'ing @IngoHohmann just because. :-)
The combinator-based approach to parsing breaks each parse keyword or datatype behavior out into a "parser function".
This is a simple implementation of COLLECT and KEEP combinators that collaborate with the BLOCK! combinator to do rollback. It would be preferable to have some kind of "generic rollback facility", but this is more or less what the C code was doing to implement the feature.
The PARSE as a whole maintains a block that it collects, and marks the high-water point on each block recursion...so that if an alternate fails it just drops the mark down.