Ejemplo n.º 1
0
        public void TestDigitList()
        {
            var p = from open in Prim.Character('[')
                    from d in Prim.Digit()
                    from ds in
                    Prim.Many(
                from comma in Prim.Character(',')
                from digit in Prim.Digit()
                select digit
                )
                    from close in Prim.Character(']')
                    select d.Cons(ds);

            var r = p.Parse("[1,2,3,4]").Value.Single();

            Assert.True(r.Item1.First().Value == '1');
            Assert.True(r.Item1.Skip(1).First().Value == '2');
            Assert.True(r.Item1.Skip(2).First().Value == '3');
            Assert.True(r.Item1.Skip(3).First().Value == '4');

            var r2 = p.Parse("[1,2,3,4");

            Assert.True(r2.IsFaulted);
            Assert.True(r2.Errors.First().Expected == "']'");
            Assert.True(r2.Errors.First().Input.IsEmpty);

            var r3 = p.Parse("[1,2,3,4*");

            Assert.True(r3.IsFaulted);
            Assert.True(r3.Errors.First().Expected == "']'");
            Assert.True(r3.Errors.First().Location.Line == 1);
            Assert.True(r3.Errors.First().Location.Column == 9);
        }
Ejemplo n.º 2
0
        public Factor()
            :
            base(
                inp => (from choice in
                        (from d in Prim.Digit()
                         select Int32.Parse(d.Value.ToString()))
                        | (from open in Prim.Character('(')
                           from expr in New.Expr()
                           from close in Prim.Character(')')
                           select expr)
                        select choice)
                .Parse(inp)

                )
        {
        }
Ejemplo n.º 3
0
 public Decimal()
     :
     base(
         inp => {
     var r = Prim.Many1(Prim.Digit()).Parse(inp);
     if (r.IsFaulted)
     {
         return(ParserResult.Fail <IntegerToken>(r.Errors));
     }
     else
     {
         var val = r.Value.First();
         return(ParserResult.Success <IntegerToken>(
                    Tuple.Create(
                        new IntegerToken(Int32.Parse(val.Item1.AsString()), inp.First().Location),
                        val.Item2
                        ).Cons()
                    ));
     }
 }
         )
 {}
Ejemplo n.º 4
0
        public void TestDigit()
        {
            var r = Prim.Digit().Parse("1").Value.Single();

            Assert.True(r.Item1.Value == '1');
        }