JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
reader.hpp
Go to the documentation of this file.
1/// \file jsonv/reader.hpp
2/// Read a JSON AST.
3///
4/// Copyright (c) 2015-2022 by Travis Gockel. All rights reserved.
5///
6/// This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
7/// as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
8/// version.
9///
10/// \author Travis Gockel (travis@gockelhut.com)
11#pragma once
12
13#include <jsonv/config.hpp>
14#include <jsonv/ast.hpp>
15#include <jsonv/optional.hpp>
16#include <expected>
17#include <string_view>
18
19#include <cstddef>
20#include <cstdint>
21#include <initializer_list>
22#include <iosfwd>
23#include <iterator>
24#include <memory>
25#include <string>
26
27namespace jsonv
28{
29
30class parse_index;
31class parse_options;
32class path;
33class value;
34
35namespace detail
36{
37
38class reader_lookahead;
39
40}
41
42/// \addtogroup Serialization
43/// \{
44
45/// A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON \ref ast_node
46/// sequence.
47///
48/// Readers normalize access to JSON source for conversion to some other format. They can be provided with pre-parsed
49/// JSON through a \c parse_index or \c value. They can be provided with a \c std::string or \c std::string_view
50/// directly. This allows \c deserializer implementations to operate on all forms of JSON without worrying about the
51/// implementation.
52///
53/// A reader is a forward cursor over that sequence. It starts on \c ast_node_type::document_start, so the first thing
54/// to do is step onto the value itself -- which \c jsonv::deserialize does for you when handed a fresh reader. Reading
55/// an object means walking its keys, handling the ones you recognize and skipping the ones you do not:
56///
57/// \code
58/// struct my_object
59/// {
60/// std::int64_t a = 0;
61/// };
62///
63/// std::optional<my_object> deserialize_my_object(jsonv::reader& from)
64/// {
65/// if (!from.expect(jsonv::ast_node_type::object_begin))
66/// return std::nullopt;
67///
68/// // Step onto the first key, or onto the } of an empty object.
69/// if (!from.next_token())
70/// return std::nullopt;
71///
72/// my_object out;
73/// while (from.good() && from.current_type() != jsonv::ast_node_type::object_end)
74/// {
75/// // Keys arrive canonical or escaped, depending on whether the source used escape sequences.
76/// if (!from.expect({ jsonv::ast_node_type::key_canonical, jsonv::ast_node_type::key_escaped }))
77/// return std::nullopt;
78///
79/// auto key = from.current().visit_key([](const auto& k) { return std::string(k.value()); });
80/// if (key == "a")
81/// {
82/// if (!from.next_token())
83/// return std::nullopt;
84///
85/// if (auto node = from.current_as<jsonv::ast_node::integer>())
86/// out.a = node->value();
87/// else
88/// return std::nullopt;
89///
90/// // Step off the value and onto the next key, or onto the closing }.
91/// if (!from.next_token())
92/// return std::nullopt;
93/// }
94/// else
95/// {
96/// // A key we do not care about -- skip its value, however large, and land on the next key.
97/// if (!from.next_key())
98/// return std::nullopt;
99/// }
100/// }
101/// return out;
102/// }
103/// \endcode
104///
105/// Note that \c next_key is only valid while sitting on a key or on the opening \c { -- it is the "skip this member"
106/// step, not the loop's advance. Use \c next_token to move off a value you have just read.
108{
109public:
110 /// Create a reader which reads from the given \a index.
111 explicit reader(parse_index index);
112
113 /// \{
114
115 /// Create a reader which reads from an in-memory \a value.
116 ///
117 /// \param value The value to read from. The overload taking a reference does not copy it, so it must remain
118 /// valid for the lifetime of the reader; the rvalue overload moves \a value into the reader, which
119 /// then keeps it alive.
120 ///
121 /// These are named rather than constructors because \c value converts implicitly from \c std::string, among
122 /// others. A \c reader(const value&) constructor would make <tt>reader(some_std_string)</tt> ambiguous -- a
123 /// \c std::string reaches \c std::string_view and \c value through user-defined conversions of equal rank --
124 /// and the same trap would reopen for every type \c value grows a converting constructor from. Returning by
125 /// value costs nothing: the result is a prvalue of the returned type, so it initializes the caller's object
126 /// directly without a move.
128 static reader from_value(const value& value);
131 /// \}
132
133 /// \{
134
135 /// Create a reader which reads from JSON \a source.
136 ///
137 /// The \a source must stay in memory for the duration of this instance's use, unless it is an rvalue reference to
138 /// a \c std::string, which is moved to the reader's implementation to keep it alive. It is parsed with
139 /// \a parse_options where they are given, and with the defaults \c parse_index::parse uses where they are not.
140 explicit reader(std::string_view source);
141 explicit reader(std::string_view source, const parse_options& parse_options);
142 explicit reader(const char* source);
143 explicit reader(const char* source, const parse_options& parse_options);
144
145 explicit reader(std::string&& source);
146 explicit reader(std::string&& source, const parse_options& parse_options);
147 /// \}
148
149 /// \{
150
151 /// Create a reader which reads JSON from what is left of the \a source stream, as \c parse(std::istream&) does.
152 ///
153 /// \code
154 /// std::ifstream file("file.json");
155 /// jsonv::reader from(file);
156 /// \endcode
157 ///
158 /// The stream is read to its end here, and the reader keeps the text, so \c owns_source is \c true and nothing
159 /// reads \a source again once this returns. The text is parsed with \a parse_options where they are given, and
160 /// with the defaults \c parse_index::parse uses where they are not. A \c parse_error position counts from where
161 /// \a source was when this was called.
162 explicit reader(std::istream& source);
163 explicit reader(std::istream& source, const parse_options& parse_options);
164 /// \}
165
166 // Not copyable.
167 reader(const reader&) = delete;
168 reader& operator=(const reader&) = delete;
169
170 /// \{
171
172 /// Moving a reader transfers its implementation, leaving the source moved-from: \c good is \c false and the
173 /// accessors throw \c std::invalid_argument. These are out-of-line because destroying the implementation needs a
174 /// complete \c reader::impl, which this header does not have -- the same reason the destructor is.
175 reader(reader&&) noexcept;
176 reader& operator=(reader&&) noexcept;
177 /// \}
178
179 ~reader() noexcept;
180
181 /// Check if this reader is still good to read from. This will be \c true if this instance has not been moved-from
182 /// and has not reached EOF. If this is \c false, \c current or \c current_path will throw an exception.
184 bool good() const;
185
186 /// Check that the source this reader was created from is valid JSON.
187 ///
188 /// Parsing text never throws: a malformed document produces a sequence which stops at an \c ast_node_type::error
189 /// node, and a reader walks it as far as it goes. What was wrong is not on that node in any form a reader of it can
190 /// act on, so this is the question \c parse_index::validate answers, asked of the reader. It is about the source,
191 /// not the cursor, so the answer is the same wherever the reader is positioned.
192 ///
193 /// \throws parse_error if this reader is over JSON text which did not parse. A reader over a \c value has nothing
194 /// to parse and never throws this.
195 /// \throws std::invalid_argument if this instance has been moved-from.
196 void validate() const;
197
198 /// Does this reader own the storage it reads from?
199 ///
200 /// This is \c true for a reader created from a \c std::string rvalue or by \c from_value(value&&), which keep their
201 /// source alive for exactly as long as the reader. Anything deserialized as a view of the source -- a
202 /// \c std::string_view, say -- is then valid only while the reader is. It is \c false for every other source,
203 /// where the caller owns the storage, and for a moved-from reader.
205 bool owns_source() const noexcept;
206
207 /// Get the current AST node this reader is pointing at.
208 ///
209 /// \throws std::logic_error if this instance is not \c good, or std::invalid_argument if it has been moved-from.
211 const ast_node& current() const;
212
213 /// Get the type of the \c current AST node, which is always \c current().type().
214 ///
215 /// Use this where the type is all that is wanted -- checking for the `]` which ends an array, say. A reader over a
216 /// \c value has to synthesise token text for a number, a string or a key before it can hand out an \c ast_node,
217 /// and answering this does not.
218 ///
219 /// \throws std::logic_error if this instance is not \c good, or std::invalid_argument if it has been moved-from.
221 ast_node_type current_type() const;
222
223 /// \{
224
225 /// Check that the \c current AST node has the given \a type or is one of the expected \a types.
226 ///
227 /// \returns Nothing if the \c current node matches \a type or one of the given \a types; otherwise the
228 /// \c ast_node_type the \c current node actually has.
229 /// \throws std::invalid_argument if \a types is empty.
230 /// \throws std::logic_error if this instance is not \c good, or std::invalid_argument if it has been moved-from.
231 ///
232 /// \see ast_node::expect
234 std::expected<void, ast_node_type> expect(ast_node_type type) const;
236 std::expected<void, ast_node_type> expect(std::initializer_list<ast_node_type> types) const;
237 /// \}
238
239 /// Get the \c current AST node as a specific \c TAstNode subtype, calling \c expect beforehand.
240 ///
241 /// \returns The \c current node as a \c TAstNode; otherwise the \c ast_node_type the \c current node actually has.
242 /// \throws std::logic_error if this instance is not \c good, or std::invalid_argument if it has been moved-from.
243 template <typename TAstNode>
245 std::expected<TAstNode, ast_node_type> current_as() const
246 {
247 // Written as an explicit branch rather than `expect(...).transform(...)` on purpose. The monadic operations on
248 // `std::expected` are a later addition than the type itself -- libstdc++ 12 and libc++ 16 have `expected` but
249 // no `transform` -- so using one here would quietly raise the minimum toolchain by a whole release.
250 if (auto matched = expect(TAstNode::type()); !matched)
251 return std::unexpected(matched.error());
252 else
253 return current().as<TAstNode>();
254 }
255
256 /// Get the in-memory \c value this reader is positioned on, if it has one to lend.
257 ///
258 /// A reader created by \c from_value is walking a \c value which already exists, so the subtree under \c current
259 /// is something it can hand out by reference rather than rebuild. A reader over JSON text has no such tree.
260 ///
261 /// Deserialization uses this to avoid copying a subtree it was already given, and so that a deserializer which
262 /// returns a view of what it was handed -- \c std::string_view among them -- borrows the caller's storage rather
263 /// than a temporary which dies with the call.
264 ///
265 /// \returns The value \c current names; or nothing if this reader is not value-backed, is not \c good, or is
266 /// positioned somewhere which does not start a value, such as an object key or a closing token.
269
270 /// Get the path to the current node this reader is pointing at. This is used in the generation of error messages to
271 /// describe the location of something that could not be deserialized.
272 ///
273 /// \code
274 /// ^ /* "." -- start of document is the empty path */
275 /// { /* "." -- opening { is still an empty path */
276 /// "a": /* ".a" -- the key starts the path */
277 /// [ /* ".a" -- the path refers to the entire array */
278 /// 1, /* ".a[0]" */
279 /// 2, /* ".a[1]" */
280 /// 3, /* ".a[2]" */
281 /// ], /* ".a" -- the path at the end of the array refers to the entire array again */
282 /// "b": /* ".b" */
283 /// { /* ".b" -- the path refers to the entire object */
284 /// "x": /* ".b.x" */
285 /// "taco" /* ".b.x" */
286 /// }, /* ".b" */
287 /// "c": /* ".c" */
288 /// 4 /* ".c" */
289 /// } /* "." */
290 /// $ /* "." */
291 /// \endcode
292 ///
293 /// \throws std::logic_error if this instance is not \c good, or std::invalid_argument if it has been moved-from.
295 const path& current_path() const;
296
297 /// Go to the next token.
298 ///
299 /// \code
300 /// ^
301 /// { /* <- go to "a" */
302 /// "a": /* <- go to [ */
303 /// [ /* <- go to 1 */
304 /// 1, /* <- go to 2 */
305 /// 2, /* ...and so on */
306 /// 3,
307 /// ],
308 /// "b":
309 /// {
310 /// },
311 /// "c":
312 /// 4
313 /// }
314 /// $
315 /// \endcode
316 ///
317 /// \returns \c true if the reader is still \c good to read from \c current.
319 bool next_token() noexcept;
320
321 /// Go to one past the end of the current structure.
322 ///
323 /// \code
324 /// ^
325 /// {
326 /// "a": /* <- go to end of document */
327 /// [ /* <- go to "b" */
328 /// 1, /* <- go to "b", too */
329 /// 2,
330 /// 3,
331 /// ], /* <- go to "b" */
332 /// "b": /* <- go to end of document */
333 /// { /* <- go to "c" */
334 /// }, /* <- go to "c" */
335 /// "c":
336 /// 4
337 /// } /* <- go to end of document */
338 /// $
339 /// \endcode
340 ///
341 /// The point of this over \ref next_token is abandoning a structure you are only part-way through. Once the one
342 /// member you came for has been read, there is no reason to walk the rest of the object:
343 ///
344 /// \code
345 /// /// Find the "a" member of an object and leave the rest of it unread.
346 /// std::optional<std::int64_t> find_a(jsonv::reader& from)
347 /// {
348 /// if (!from.expect(jsonv::ast_node_type::object_begin))
349 /// return std::nullopt;
350 ///
351 /// if (!from.next_token())
352 /// return std::nullopt;
353 ///
354 /// while (from.good() && from.current_type() != jsonv::ast_node_type::object_end)
355 /// {
356 /// if (!from.expect({ jsonv::ast_node_type::key_canonical, jsonv::ast_node_type::key_escaped }))
357 /// return std::nullopt;
358 ///
359 /// auto key = from.current().visit_key([](const auto& k) { return std::string(k.value()); });
360 /// if (key != "a")
361 /// {
362 /// if (!from.next_key())
363 /// return std::nullopt;
364 ///
365 /// continue;
366 /// }
367 ///
368 /// if (!from.next_token())
369 /// return std::nullopt;
370 ///
371 /// auto node = from.current_as<jsonv::ast_node::integer>();
372 ///
373 /// // Whatever is left of this object, we are done with it.
374 /// (void) from.next_structure();
375 ///
376 /// if (node)
377 /// return node->value();
378 /// else
379 /// return std::nullopt;
380 /// }
381 /// return std::nullopt;
382 /// }
383 /// \endcode
384 ///
385 /// Note the call site: \c next_structure is used while sitting on a *value* inside the object, which is where it
386 /// differs from \ref next_token. Called on the closing \c } itself it is merely \ref next_token, since there is no
387 /// longer a structure to leave.
388 ///
389 /// \returns \c true if the reader is still \c good to read from \c current.
391 bool next_structure() noexcept;
392
393 /// Go to one past the value this reader is on.
394 ///
395 /// Unlike \ref next_structure, which leaves the structure the reader is *inside*, this steps over the single value
396 /// the reader is *on*. On a structure that means the token *after* its matching close, since the structure is the
397 /// value being stepped over; on anything else it is the same as \ref next_token.
398 ///
399 /// \code
400 /// ^
401 /// {
402 /// "a": /* <- go to [ */
403 /// [ /* <- go to "b" */
404 /// 1, /* <- go to 2 */
405 /// 2,
406 /// 3,
407 /// ],
408 /// "b":
409 /// { /* <- go to "c" */
410 /// },
411 /// "c":
412 /// 4 /* <- go to } */
413 /// }
414 /// $
415 /// \endcode
416 ///
417 /// This is the primitive for ignoring a value you do not want. Note the difference from \ref next_structure at the
418 /// `4` above: this goes to the `}`, while \ref next_structure leaves the enclosing object entirely.
419 ///
420 /// \returns \c true if the reader is still \c good to read from \c current.
422 bool next_value() noexcept;
423
424 /// Go to the next object key or end-of-object.
425 ///
426 /// \code
427 /// ^
428 /// {
429 /// "a": /* <- calling here goes to "b" */
430 /// [ /* <- calling when not on an object key throws */
431 /// 1,
432 /// 2,
433 /// 3,
434 /// ],
435 /// "b": /* <- calling here goes to "c" */
436 /// {
437 /// },
438 /// "c": /* <- calling here goes to end of object */
439 /// 4
440 /// }
441 /// $
442 /// \endcode
443 ///
444 /// \returns \c true if the reader is still \c good to read from \c current.
445 /// \throws std::invalid_argument if the reader is not currently at the start of a key.
447 bool next_key();
448
449private:
450 class impl;
451 class impl_parse_index;
452 class impl_parse_index_owning;
453 class impl_value;
454 class impl_value_owning;
455
456 template <typename TImpl, typename... TArgs>
457 explicit reader(std::in_place_type_t<TImpl>, TArgs&&...);
458
459 explicit reader(std::unique_ptr<impl> impl) noexcept;
460
461 /// The library sometimes has to read ahead -- \c polymorphic_adapter has to find its discriminator before it knows
462 /// which type to deserialize. That is a second cursor on this reader's source rather than a rewind of this one, and
463 /// it is kept out of the public interface on purpose: promising it would commit every future source, including one
464 /// which streams, to supporting it.
465 friend class detail::reader_lookahead;
466
467 /// Hands out a reader for each of several documents, on a tape it reuses from one to the next.
468 friend class documents;
469
470private:
471 std::unique_ptr<impl> _impl;
472};
473
474/// The JSON documents in one input, read one after another, each through a \c reader of its own.
475///
476/// Every other way of reading JSON text takes all of it as one document, and refuses anything after its value. This
477/// takes it as a sequence of documents instead: JSON Lines, with one to a line; concatenated JSON as \c jq reads and
478/// writes it, as in <tt>{"a":1}{"a":2}</tt>; or a run of pretty-printed documents. Any whitespace may separate two
479/// documents, as may comments where \c parse_options::comments allows them, or nothing at all where the first ends
480/// with a character the second could not have continued: <tt>[1][2]</tt> and <tt>"a""b"</tt> are two documents each,
481/// while <tt>12</tt> is one.
482///
483/// \code
484/// std::ifstream file("records.jsonl");
485/// for (jsonv::reader& doc : jsonv::documents(file))
486/// records.push_back(jsonv::deserialize<record>(doc));
487/// \endcode
488///
489/// Each document is handed out as a \c reader on its \c ast_node_type::document_start, as a freshly-created one is, so
490/// \c jsonv::deserialize reads it as a whole document and anything else which takes a reader takes it. It is parsed
491/// with the \c parse_options this was created with as though it were the only document: \c
492/// parse_options::require_document and \c parse_options::max_structure_depth apply to each one. Nothing is parsed
493/// until the iterator reaches it, and then onto the tape the document before it was read from, so many small documents
494/// cost one tape the size of the largest rather than one each. That is also why the reader for a document is valid
495/// only until the iterator moves on, wherever it has been moved to: by then its tape holds the next document.
496///
497/// Whitespace and comments after the last document end the sequence, so input with no value in it holds no documents.
498///
499/// Parsing text never throws, here as elsewhere. A document which is not valid JSON is still handed out, as a reader
500/// whose \c reader::validate throws \c parse_error and from which \c jsonv::deserialize throws a
501/// \c deserialization_error saying so, and the sequence ends with it: the parse stopped at the error, and nothing says
502/// where that document would have ended and the next begun. The position in a \c parse_error counts from the start of
503/// the whole input, not of the document it is in.
504///
505/// A \c std::string_view deserialized from a document views the source. A source given as a \c std::string rvalue or a
506/// \c std::istream is kept by this instance, so such a view is valid for as long as it is; any other is the caller's,
507/// and valid for as long as the caller keeps it.
509{
510public:
511 class iterator;
512
513public:
514 /// \{
515
516 /// Read the documents in JSON \a source.
517 ///
518 /// The \a source must stay in memory for as long as this instance and the readers it hands out are used, unless it
519 /// is an rvalue reference to a \c std::string, which is moved into this instance to keep it alive. It is parsed
520 /// with \a parse_options where they are given, and with the defaults \c parse_index::parse uses where they are not.
521 explicit documents(std::string_view source);
522 explicit documents(std::string_view source, const parse_options& parse_options);
523 explicit documents(const char* source);
524 explicit documents(const char* source, const parse_options& parse_options);
525
526 explicit documents(std::string&& source);
527 explicit documents(std::string&& source, const parse_options& parse_options);
528 /// \}
529
530 /// \{
531
532 /// Read the documents in what is left of the \a source stream, as \c reader(std::istream&) reads one.
533 ///
534 /// The stream is read to its end here, and this instance keeps the text, so nothing reads \a source again once
535 /// this returns. A \c parse_error position counts from where \a source was when this was called.
536 explicit documents(std::istream& source);
537 explicit documents(std::istream& source, const parse_options& parse_options);
538 /// \}
539
540 // Not copyable.
541 documents(const documents&) = delete;
542 documents& operator=(const documents&) = delete;
543
544 /// \{
545
546 /// Moving transfers the source and the position in it. Iterators and readers already handed out are unaffected,
547 /// and go on belonging to the instance moved to. The moved-from instance has no documents to give: \c begin throws
548 /// \c std::invalid_argument, as using a moved-from \c reader does.
549 documents(documents&&) noexcept;
550 documents& operator=(documents&&) noexcept;
551 /// \}
552
553 ~documents() noexcept;
554
555 /// Get an iterator on the first document which has not been passed yet. The first call parses the first document;
556 /// any later call returns an iterator wherever the earlier ones have got to, since this is an input range and can
557 /// only be walked once.
558 ///
559 /// \throws std::invalid_argument if this instance has been moved-from, or if the \c parse_options ask for a \c
560 /// parse_options::max_structure_depth beyond the limit, as \c parse_index::parse does.
562 iterator begin();
563
564 /// The end of the documents, which an \c iterator compares equal to once it has passed the last one.
566 std::default_sentinel_t end() const noexcept
567 {
568 return std::default_sentinel;
569 }
570
571private:
572 class impl;
573
574private:
575 std::unique_ptr<impl> _impl;
576};
577
578/// An input iterator over \c documents. Dereferencing it gives the \c reader for the document it is on, and
579/// incrementing it parses the next one. Once it has passed the last, it compares equal to \c std::default_sentinel.
580class JSONV_PUBLIC documents::iterator final
581{
582public:
583 /// What this models in C++20 terms: an input iterator, since each document is parsed onto the tape of the last.
584 using iterator_concept = std::input_iterator_tag;
585
586 /// What dereferencing gives a reference to.
588
589 /// What every iterator has to name, although stepping through documents never measures a distance.
590 using difference_type = std::ptrdiff_t;
591
592public:
593 /// Create an iterator which is already at the end.
594 iterator() noexcept = default;
595
596 /// Get the reader for the document this is on. It reads the tape every document of the \c documents is parsed
597 /// onto, so it is valid until this iterator, or any other from the same \c documents, is incremented.
598 ///
599 /// \throws std::logic_error if this iterator is at the end.
601 reader& operator*() const;
602
603 /// \{
604
605 /// Parse the next document and move onto it, or onto the end if there is no other.
606 ///
607 /// \throws std::bad_alloc if the tape cannot grow to hold the next document, which ends the sequence there.
608 iterator& operator++();
609 void operator++(int) { ++*this; }
610 /// \}
611
612 /// Is \a self at the end of its \c documents?
614 friend bool operator==(const iterator& self, std::default_sentinel_t) noexcept
615 {
616 return self.at_end();
617 }
618
619private:
620 friend class documents;
621
622 explicit iterator(impl* owner) noexcept :
623 _owner(owner)
624 { }
625
626 bool at_end() const noexcept;
627
628private:
629 impl* _owner = nullptr;
630};
631
632/// \}
633
634}
Utilities for directly dealing with a JSON AST.
Represents an entry in a JSON AST.
Definition ast.hpp:172
The JSON documents in one input, read one after another, each through a reader of its own.
Definition reader.hpp:509
friend bool operator==(const iterator &self, std::default_sentinel_t) noexcept
Is self at the end of its documents?
Definition reader.hpp:614
documents(std::string_view source, const parse_options &parse_options)
Read the documents in JSON source.
std::ptrdiff_t difference_type
What every iterator has to name, although stepping through documents never measures a distance.
Definition reader.hpp:590
documents(std::string &&source)
Read the documents in JSON source.
documents(std::string_view source)
Read the documents in JSON source.
documents(const char *source)
Read the documents in JSON source.
documents(std::istream &source, const parse_options &parse_options)
Read the documents in what is left of the source stream, as reader(std::istream&) reads one.
documents(documents &&) noexcept
Moving transfers the source and the position in it.
documents(std::string &&source, const parse_options &parse_options)
Read the documents in JSON source.
iterator() noexcept=default
Create an iterator which is already at the end.
documents(std::istream &source)
Read the documents in what is left of the source stream, as reader(std::istream&) reads one.
std::input_iterator_tag iterator_concept
What this models in C++20 terms: an input iterator, since each document is parsed onto the tape of th...
Definition reader.hpp:584
documents(const char *source, const parse_options &parse_options)
Read the documents in JSON source.
Represents the index of a parsed AST.
Configuration for various parsing options.
Definition parse.hpp:58
Represents an exact path in some JSON structure.
Definition path.hpp:107
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON...
Definition reader.hpp:108
static reader from_value(const value &value)
Create a reader which reads from an in-memory value.
reader(std::string_view source, const parse_options &parse_options)
Create a reader which reads from JSON source.
reader(std::string &&source, const parse_options &parse_options)
Create a reader which reads from JSON source.
reader(std::istream &source)
Create a reader which reads JSON from what is left of the source stream, as parse(std::istream&) does...
reader(const char *source, const parse_options &parse_options)
Create a reader which reads from JSON source.
reader(parse_index index)
Create a reader which reads from the given index.
reader(std::string &&source)
Create a reader which reads from JSON source.
reader(std::istream &source, const parse_options &parse_options)
Create a reader which reads JSON from what is left of the source stream, as parse(std::istream&) does...
reader(std::string_view source)
Create a reader which reads from JSON source.
static reader from_value(value &&value)
Create a reader which reads from an in-memory value.
reader(const char *source)
Create a reader which reads from JSON source.
optional< const value & > current_value() const noexcept
Get the in-memory value this reader is positioned on, if it has one to lend.
reader(reader &&) noexcept
Moving a reader transfers its implementation, leaving the source moved-from: good is false and the ac...
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition value.hpp:165
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition config.hpp:143
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Definition config.hpp:124
ast_node_type
Marker type for an encountered token type.
Definition ast.hpp:87
STL namespace.
Pulls in an implementation of optional.
typename detail::optional_type< T >::type optional
Represents a value that may or may not be present.
Definition optional.hpp:239