-
I want to parse file that has metadata on top, and I want to parse that metadata and populate that data to parse the rest of file ? How would I do that. As far as I understand the map function is called on second pass after successful parsing. So with MapParser I couldn't achieve that or am I missing something ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Probably the easiest is if you split this into two separate parsing steps: You can use the final metadataResult = metadataParser.parse(input);
final dataParser = buildDataParser(metadataResult.value);
final dataResult = dataParser.parseOn(metadataResult); Alternatively you can use the ContinuationParser to merge this into a single parser that returns the result of the data parser: final parser = metadataParser.callCC((continuation, context) {
final metadataResult = continuation(context);
final dataParser = buildDataParser(metadataResult.value);
return dataParser.parseOn(metadataResult);
}); |
Beta Was this translation helpful? Give feedback.
-
To also answer your question about the map function: It is immediately called if the inner parser succeeds. There is no second pass, everything is done in a single pass. |
Beta Was this translation helpful? Give feedback.
-
Thanks, the first approach worked. |
Beta Was this translation helpful? Give feedback.
Probably the easiest is if you split this into two separate parsing steps: You can use the
Result
of the meta-data parser to build the data parser, as well as to resume the parse where the meta-data parser completed. Something along these lines:Alternatively you can use the ContinuationParser to merge this into a single parser that returns the result of the data parser: