Why does my nom parser not consume the entire input, leaving the last piece unparsed?

后端 未结 2 472
抹茶落季
抹茶落季 2020-12-21 00:32

I\'m trying to split a log line on space and commas in order to create a Vector of Tokens of Field and Separator as shown

2条回答
  •  感情败类
    2020-12-21 01:20

    The issue you're running into is that Nom is designed to always assume that there may be more input, unless you tell it otherwise. Since you know your input here is complete, you need to feed the parsers your literal wrapped in a CompleteByteSlice (or if you used a &str, a CompleteStr). These types are thin wrappers that Nom uses to indicate that we know there isn't more input coming. It will make it so a parser that fails to make a complete match returns an Error instead of an Incomplete, and in this case, will instruct the the parser to consume that final token, rather than ask for more characters.

提交回复
热议问题