public void TestItem() { Assert.True( Prim.Item().Parse("").Value.IsEmpty ); var r = Prim.Item().Parse("abc").Value.Single(); Assert.True( r.Item1.Value == 'a' && r.Item2.AsString() == "bc" ); }
public void TestBinding() { var p = from x in Prim.Item() from _ in Prim.Item() from y in Prim.Item() select new ParserChar[] { x, y }; var res = p.Parse("abcdef").Value.Single(); Assert.True(res.Item1.First().Value == 'a' && res.Item1.Second().Value == 'c'); Assert.True(res.Item1.First().Location.Line == 1); Assert.True(res.Item1.First().Location.Column == 1); Assert.True(res.Item1.Second().Location.Line == 1); Assert.True(res.Item1.Second().Location.Column == 3); bool found = p.Parse("ab").Value.IsEmpty; Assert.True(found); }
public void TestChoice() { var r = Prim.Choice(Prim.Item(), Prim.Return(Prim.ParserChar('d'))).Parse("abc").Value.Single(); Assert.True( r.Item1.Value == 'a' && r.Item2.AsString() == "bc" ); var inp = "abc".ToParserChar(); var parser = Prim.Choice( Prim.Failure <ParserChar>(ParserError.Create("failed because...", inp)), Prim.Return(Prim.ParserChar('d')) ) .Parse(inp); r = parser.Value.Single(); Assert.True( r.Item1.Value == 'd' && r.Item2.AsString() == "abc" ); }