3#include "../parser/driver.hpp"
7 namespace speculative {
12 std::shared_ptr<void> owner,
17 owner(std::move(owner)),
18 initial_state(initial_state),
19 ending_state(ending_state),
23 bool empty()
const noexcept {
43 std::shared_ptr<void> owner;
62 auto bytes = std::make_shared<std::string>();
63 bytes->reserve(left.bytes.size() + right.bytes.size());
64 if (!left.bytes.empty()) {
65 bytes->append(left.bytes.data(), left.bytes.size());
67 if (!right.bytes.empty()) {
68 bytes->append(right.bytes.data(), right.bytes.size());
71 return CSVRowFragment(
81 size_t sequence_number = 0;
84 std::shared_ptr<void> owner;
85 bool starts_at_record_boundary =
true;
88 std::vector<CSVRow> complete_rows;
93 size_t sequence_number,
95 std::shared_ptr<void> owner,
98 bool starts_at_record_boundary,
102 result.sequence_number = sequence_number;
106 result.starts_at_record_boundary = starts_at_record_boundary
107 || parse_result.initial_state.pending_linefeed;
108 result.parse_result = parse_result;
111 if (!
result.starts_at_record_boundary) {
116 parse_result.initial_state,
117 parse_result.ending_state,
123 result.prefix_fragment = CSVRowFragment::from_row(
125 parse_result.initial_state,
132 result.complete_rows.reserve(parsed_rows.size() - first_complete_row);
133 for (
size_t i = first_complete_row; i < parsed_rows.size(); ++i) {
134 result.complete_rows.push_back(std::move(parsed_rows[i]));
137 if (parse_result.complete_prefix_length < chunk.size()) {
138 result.suffix_fragment = CSVRowFragment(
139 chunk.substr(parse_result.complete_prefix_length),
142 parse_result.ending_state,
143 chunk_offset + parse_result.complete_prefix_length
150 template<
typename Parser>
151 inline std::vector<CSVRow> materialize_row_fragment(
153 const CSVRowFragment& fragment
155 std::vector<CSVRow> rows;
156 if (fragment.empty()) {
164 ParserChunkOptions(ParserDFAState(), fragment.offset)
170 template<
typename Parser>
171 inline ParsedChunkRows repair_parsed_chunk_rows(
173 const ParsedChunkRows& chunk,
174 ParserDFAState corrected_initial_state
176 std::vector<CSVRow> parsed_rows;
178 const ParserChunkResult parse_result = parser.parse_chunk(
182 ParserChunkOptions(corrected_initial_state, chunk.offset)
185 return split_parsed_chunk_rows(
186 chunk.sequence_number,
190 std::move(parsed_rows),
191 chunk.starts_at_record_boundary,
201 template<
bool EagerClassify = false>
204 PermissiveParsePolicy,
205 CSVRowFieldPolicy<EagerClassify>,
217 ) :
Base(parse_flags, ws_flags) {}
222 const ColNamesPtr& col_names
223 ) :
Base(parse_flags, ws_flags, col_names) {}
Data structure for representing CSV rows.
csv::string_view raw_str() const noexcept
Return a string_view of the raw bytes of this row as they appear in the underlying parse buffer,...
Borrow a row and error state for synchronous, single-pass field access.
Minimal parser shell for caller-owned chunks.
std::array< ParseFlags, 256 > ParseFlagMap
An array which maps ASCII chars to a parsing flag.
std::array< bool, 256 > WhitespaceMap
An array which maps ASCII chars to a flag indicating if it is whitespace.
The all encompassing namespace.
std::string_view string_view
The string_view class used by this library.
Default row policy for the CSVRow path.
Explicit DFA state at a parse boundary.
Default parse policy hook.