Throw stream errors
I have stream of tokens. Token is enum like:
enum Token {
Error,
Num,
Str,
...
}
StreamOnce::uncons documentation: Returns Err if no element could be retrieved.
How I can throw error when I have Token::Error?
You would return an error if the stream can no longer be used to retrieve more tokens. If you have a specific error token the I would assume that the stream may still be used, just that one token was an error so you would return Ok(Token::Error) to allow the parsing to continue (if the parser accepts, and recovers from the error token that is)
I would assume that the stream may still be used
Not always. Unfinished string can break all following lexing
if the parser accepts, and recovers from the error token that is
That the only solution I found. I created my own token parser, but is it idiomatic way to handle such errors in combine?
That the only solution I found. I created my own token parser, but is it idiomatic way to handle such errors in combine?
Yes, I think so at least. What would be the alternative?
What would be the alternative?
Throw error from stream (maybe). It gives more guarentees that invalid input won't be skipped.
Otherwise I have to be sure that every parsing action is based on my own token parser
I suppose you could instead use a parser which inspects the error being returned and recovers if you deem it to be a recoverable error