Beispiel #1
0
    public void AlternativeParser()
    {
        var stream = new MemoryStream <char>("a".AsMemory());

        var p1 = Combinator.Alt(Combinator.Char('x'), Combinator.Char('y'), Combinator.Char('z'));
        var p2 = Combinator.Alt(Combinator.Char('a'), Combinator.Char('b'), Combinator.Char('c'));

        var r1 = p1.Parse(stream);
        var r2 = p2.Parse(stream);

        Assert.False(r1.IsOk);
        Assert.True(r2.IsOk);
        Assert.Equal('a', r2.Ok.Value);
    }