I'm the author of Pegasus.
Pegasus will use the current location of the cursor along with the current version of the internal state as a key for caching the result of a specific rule, if that rule is set to memoize.
You should do this if the rule is likely to be called in the same state more than once.
For example, if you have this style of parser:
a = b "foo"
/ b "bar"
/ b "baz"
b = /* something expensive */
It would be worthwhile to memoize the b
rule, since it is used as a prefix to several expressions.
Of course, this is optional, because in many cases this can be optimized in a better way:
a = b ("foo" / "bar" / "baz")
If you mark every rule with -memoize
, this is basically the same thing as Packrat parsing. Pegasus allows you to control this selectively, since there is a sizeable overhead.