CultPong/Assets/Scripts/Parsley/Primitives/TokenByLiteralParser.cs
2020-09-25 07:12:38 +01:00

20 lines
No EOL
554 B
C#

namespace Parsley.Primitives
{
internal class TokenByLiteralParser : Parser<Token>
{
private readonly string expectation;
public TokenByLiteralParser(string expectation)
{
this.expectation = expectation;
}
public Reply<Token> Parse(TokenStream tokens)
{
if (tokens.Current.Literal == expectation)
return new Parsed<Token>(tokens.Current, tokens.Advance());
return new Error<Token>(tokens, ErrorMessage.Expected(expectation));
}
}
}