match

convenient function to instantiate a matcher

Parser!(T)
match
(
T
)
(
T[] s
,
bool collect = true
)

Examples

matching a string

import unit_threaded;

auto parser = match("test");
auto res = parser.parseAll("test");

res.success.shouldBeTrue;
res.rest.length.shouldEqual(0);

transform match result

import unit_threaded;

auto parser = match("test") ^^ (objects) {
    auto res = objects;
    if (objects[0] == "test")
    {
        res[0] = "super";
    }
    return objects;
};
auto res = parser.parse("test");
res.success.shouldBeTrue;
res.results[0].shouldEqual("super");

Meta