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); } ) { }
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() )); } } ) { }
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); } ) { }
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() )); } } ) {}