unittest to show the simplest usage of lazy
import unit_threaded; // endless -> a | a opt(endless) struct Endless { static Parser!(immutable(char)) lazyEndless() { return lazyParser!(immutable(char))(&parser); } static Parser!(immutable(char)) parser() { return match("a") ~ (-(lazyEndless())); } } auto p = Endless.parser(); auto res = p.parse("aa"); res.success.shouldBeTrue; res.results.shouldEqual(["a", "a"]); res = p.parse("aab"); res.success.shouldBeTrue; res.results.shouldEqual(["a", "a"]); res.rest.shouldEqual("b");
convenient function to instantiate a lazy parser with a function