1 import pry.atoms, pry.stream; 2 import std.range.primitives, std.conv, std.variant; 3 alias S = SimpleStream!string; 4 with(parsers!S) { 5 auto digits = range!('0', '9').rep.map!(x => x.to!int); 6 static assert(isParser!(typeof(digits))); 7 auto parser = any(tk!'a', digits); 8 S s = "10a"; 9 S.Error err; 10 Algebraic!(dchar, int) value; 11 assert(parser.parse(s, value, err)); 12 assert(value == 10); 13 assert(parser.parse(s, value, err)); 14 assert(value == cast(dchar)'a'); 15 assert(s.empty); 16 }
Try each of provided parsers until one succeeds.