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

1 import unit_threaded;
2 
3 // endless -> a | a opt(endless)
4 struct Endless
5 {
6     static Parser!(immutable(char)) lazyEndless()
7     {
8         return lazyParser!(immutable(char))(&parser);
9     }
10 
11     static Parser!(immutable(char)) parser()
12     {
13         return match("a") ~ (-(lazyEndless()));
14     }
15 }
16 
17 auto p = Endless.parser();
18 auto res = p.parse("aa");
19 res.success.shouldBeTrue;
20 res.results.shouldEqual(["a", "a"]);
21 
22 res = p.parse("aab");
23 res.success.shouldBeTrue;
24 res.results.shouldEqual(["a", "a"]);
25 res.rest.shouldEqual("b");

Meta