Exemplo n.º 1
0
        public Identifier(GeneralLanguageDef languageDef)
            :
            base(
                inp =>
        {
            var res = Tok.Lexeme(
                from name in new Ident(languageDef)
                where !IdentHelper.IsReservedName(name, languageDef)
                select new IdentifierToken(name, inp.First().Location)
                )
                      .Parse(inp);

            if (res.IsFaulted)
            {
                return(res);
            }

            if (res.Value.IsEmpty)
            {
                return(ParserResult.Fail <IdentifierToken>("unexpected: reserved word", inp));
            }

            return(res);
        }
                )
        { }
Exemplo n.º 2
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()
                           ));
            }
        }
                )
        { }
Exemplo n.º 3
0
        public Operator(GeneralLanguageDef languageDef)
            :
            base(
                inp =>
        {
            var res = Tok.Lexeme(
                from name in new Oper(languageDef)
                where !OpsHelper.IsReservedOp(name, languageDef)
                select new OperatorToken(name, inp.First().Location))
                      .Parse(inp);

            if (res.IsFaulted)
            {
                return(res);
            }

            if (res.Value.IsEmpty)
            {
                return(ParserResult.Fail <OperatorToken>("unexpected: reserved operator", inp));
            }

            return(res);
        }
                )
        { }
Exemplo n.º 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()
                    ));
     }
 }
         )
 {}