Exemple #1
0
        public Octal()
            :
            base(
                inp =>
        {
            var r = (from x in Prim.Character('o').Or(Prim.Character('O'))
                     from d in Prim.Many1(Prim.OctalDigit())
                     select d)
                    .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(Convert.ToInt32(val.Item1.AsString(), 8), inp.First().Location),
                               val.Item2
                               ).Cons()
                           ));
            }
        }
                )
        { }
Exemple #2
0
 public ParseEsc(char c, char code)
     :
     base(
         inp =>
 {
     var r = Prim.Character(c).Parse(inp);
     if (r.IsFaulted)
     {
         return(r);
     }
     else
     {
         var tuple = r.Value.First();
         return(ParserResult.Success <ParserChar>(
                    Tuple.Create <ParserChar, ImmutableList <ParserChar> >(
                        new ParserChar(
                            code,
                            tuple.Item1.Location
                            ),
                        tuple.Item2
                        ).Cons()
                    ));
     }
 }
         )
 { }
Exemple #3
0
        public Sign()
            :
            base(
                inp =>
        {
            var r = Prim.Character('-')
                    .Or(Prim.Character('+'))
                    .Parse(inp);

            return(r.IsFaulted
                        ? ParserResult.Success(Tuple.Create(new ParserChar('+'), inp).Cons())
                        : r);
        }
                )
        { }
Exemple #4
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()
                    ));
     }
 }
         )
 {}