datalust / superpower

A C# parser construction toolkit with high-quality error reporting
Apache License 2.0
1.05k stars 98 forks source link

Creating a parser that doesn't consume tokens (PassThrough) #107

Closed xDGameStudios closed 4 years ago

xDGameStudios commented 4 years ago

I'm trying to create a dummy parser that doesn't consume tokens and I don't know how this can be done! Is it even possible? That returns a given argument...

Token.PassThrough(Token.Empty)

xDGameStudios commented 4 years ago
        private static TokenListParser<T, Token<T>> PassThrough<T>(Token<T> empty)
        {
            return input =>
            {
                var output = input.ConsumeToken();
                return TokenListParserResult.Value(empty, output.Location, output.Location);
            };
        }

this seems to do the trick!! Don't know if there is a better way ;)