Nom with streaming data an optional line ending

I am using Nom 5.0 to parse some text data. I am trying to use the streaming functions in order to have the possibility of parsing big input data.

I am getting some troubles mixing the concept of optional field and optional line ending for the first line. Imagine something like this:

A,B,C
A,B
C,D

Is it possible to have two or three fields for each line, and the last line does not need a newline. When using the streaming functions, I get an Err::Incomplete when I reach D because I am using something like opt(tuple((streaming::tag(','), field))) to optionally get the third field.

I could use the complete version, but AFAIK I would get a parsing error if my buffer just ended in that position and my stream would contain more data.

I thought that nom::combinator::complete could help me, but I am not able to make it work (it looks like it only works on the parsed being passed, not the inner sub-parsers. Am I wrong?).

Any hint?

How do you know that there isn't more data to be parsed? What if the next bytes you receive are ",E"?

I know it just because the owner of the buffer that uses the parser stores the status of the input stream.

However, I tried to change my way of thinking, and I think I have an idea. My main concern is that I wanted to parse both streaming and complete data with the same parser. But what I probably want is to use the same code, and I can probably do it with a macro.

So, my actual idea is pass the namespace (streaming or complete) to a custom macro in order to create two very similar parsers. What do you think?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.