Ejemplo n.º 1
0
        public Hexadecimal()
            :
            base(
                inp =>
        {
            var r = (from x in Prim.Character('x').Or(Prim.Character('X'))
                     from d in Prim.Many1(Prim.HexDigit())
                     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(), 16), inp.First().Location),
                               val.Item2
                               ).Cons()
                           ));
            }
        }
                )
        { }