lazyParser

convenient function to instantiate a lazy parser with a function

  1. Parser!(T) lazyParser(Parser!(T) delegate() parser)
  2. Parser!(T) lazyParser(Parser!(T) function() parser)
    Parser!(T)
    lazyParser
    (
    T
    )
    (
    Parser!(T) function
    ()
    parser
    )

Examples

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");

Meta