-- | Parses the input 'ByteString' identifying a TSV document
-- using the provided delimiter. This function is /incremental/, i.e.
-- it will correctly identify rows which can't be parsed and skip them,
-- collecting the error along the way.
-- It returns a list of 'ParseCorpusResult', which will contain either
-- the parsed record or a diagnostic on the error on the given row.
parseTsvWithDiagnostics::Delimiter
->BL.ByteString
->[ParseCorpusResultTsvDoc]
...
...
@@ -374,6 +380,8 @@ parseTsvWithDiagnostics d bs =
MkHeaderParsingContext_p->
[ParseTsvRecordFailed(AtRow0("The parsing choked on the header (delimiter was "<>showd<>"). This might be a malformed TSV we can't recover from.",mempty))]
MkRecordParsingContext(RecordParsingContext{..})
-- As we accumulate records by consing (for efficiency sake),
-- we need a final 'reverse' at the end.
->reverse$_prs_ctx_parsed_records
where
...
...
@@ -391,7 +399,8 @@ parseTsvWithDiagnostics d bs =
MkHeaderParsingContextp->go_hdrstrict_chunkp
MkRecordParsingContextp->go_recstrict_chunkp
-- Specialised parser for the header.
-- Specialised parser for the header: once it fails
-- or completes, it morphs into a record parser.
go_hdr::StrictByteString
->CSVI.HeaderParserTsvDocParser
->ParsingContext(ParseCorpusResultTsvDoc)
...
...
@@ -410,7 +419,10 @@ parseTsvWithDiagnostics d bs =