diff --git a/home/architecture.md b/home/architecture.md index ea47bab6e..4975c1d1b 100644 --- a/home/architecture.md +++ b/home/architecture.md @@ -185,9 +185,11 @@ The lexer detects two optional extensions at compile time. Only `iterator_input_ random-access input of single-byte characters: - `supports_seek`, `get_consumed_count()`, and `copy_consumed_range()` let the lexer reconstruct already consumed input - for error messages instead of copying every character it reads. + for error messages instead of copying every character it reads. With `get_read_count()` and + `count_consumed_lines()`, the lexer also derives the read position from the adapter and counts lines only when an + error needs them, instead of counting characters and lines on every read. - `supports_bulk_scan`, `bulk_data()`, `bulk_remaining()`, and `bulk_skip()` let the lexer scan strings directly in - contiguous memory, several bytes at a time. + contiguous memory, several bytes at a time, and skip the spaces that indent a line in 8-byte steps. The function `input_adapter` picks the right adapter for the argument passed to `parse`, `accept`, `sax_parse`, or the `from_*` functions: diff --git a/home/architecture/index.html b/home/architecture/index.html index 06a0ac47a..0c263fee5 100644 --- a/home/architecture/index.html +++ b/home/architecture/index.html @@ -69,7 +69,7 @@ /// (used by the binary readers) template<class T> std::size_t get_elements(T* dest, std::size_t count = 1); -
The lexer detects two optional extensions at compile time. Only iterator_input_adapter provides them, and only for random-access input of single-byte characters:
supports_seek, get_consumed_count(), and copy_consumed_range() let the lexer reconstruct already consumed input for error messages instead of copying every character it reads.supports_bulk_scan, bulk_data(), bulk_remaining(), and bulk_skip() let the lexer scan strings directly in contiguous memory, several bytes at a time.The function input_adapter picks the right adapter for the argument passed to parse, accept, sax_parse, or the from_* functions:
iterator_input_adapter reads from an iterator range, which also covers strings, containers, and pointers.wide_string_input_adapter reads from ranges of wchar_t, char16_t, or char32_t and converts them to UTF-8. It cannot be used for binary formats; its get_elements() throws.input_stream_adapter reads from a std::istream.file_input_adapter reads from a std::FILE*.The parser does not build values itself. It reports what it reads as events to a SAX consumer, which implements the interface json_sax: null, boolean, number_integer, number_unsigned, number_float, string, binary, start_object, key, end_object, start_array, end_array, and parse_error.
The library comes with two consumers in detail/input/json_sax.hpp:
json_sax_dom_parser builds a basic_json value tree. parse uses it.json_sax_dom_callback_parser does the same, but calls a parser callback for each event, which can skip values. parse uses it when a callback is given.The binary_reader emits the same events for binary formats, so sax_parse works with a user-defined consumer for JSON and for all binary formats alike.
Output is written via output adapters:
void write_character(CharType c);
+The lexer detects two optional extensions at compile time. Only iterator_input_adapter provides them, and only for random-access input of single-byte characters:
supports_seek, get_consumed_count(), and copy_consumed_range() let the lexer reconstruct already consumed input for error messages instead of copying every character it reads. With get_read_count() and count_consumed_lines(), the lexer also derives the read position from the adapter and counts lines only when an error needs them, instead of counting characters and lines on every read.supports_bulk_scan, bulk_data(), bulk_remaining(), and bulk_skip() let the lexer scan strings directly in contiguous memory, several bytes at a time, and skip the spaces that indent a line in 8-byte steps.The function input_adapter picks the right adapter for the argument passed to parse, accept, sax_parse, or the from_* functions:
iterator_input_adapter reads from an iterator range, which also covers strings, containers, and pointers.wide_string_input_adapter reads from ranges of wchar_t, char16_t, or char32_t and converts them to UTF-8. It cannot be used for binary formats; its get_elements() throws.input_stream_adapter reads from a std::istream.file_input_adapter reads from a std::FILE*.The parser does not build values itself. It reports what it reads as events to a SAX consumer, which implements the interface json_sax: null, boolean, number_integer, number_unsigned, number_float, string, binary, start_object, key, end_object, start_array, end_array, and parse_error.
The library comes with two consumers in detail/input/json_sax.hpp:
json_sax_dom_parser builds a basic_json value tree. parse uses it.json_sax_dom_callback_parser does the same, but calls a parser callback for each event, which can skip values. parse uses it when a callback is given.The binary_reader emits the same events for binary formats, so sax_parse works with a user-defined consumer for JSON and for all binary formats alike.
Output is written via output adapters:
void write_character(CharType c);
void write_characters(const CharType* s, std::size_t length);
The serializer (used by dump and operator<<) and the binary_writer (used by the to_* functions) write to one of these adapters:
output_vector_adapter appends to a std::vector.output_stream_adapter writes to a std::ostream.output_string_adapter appends to a string.Values are converted from and to other types with the JSONSerializer template parameter. The default, adl_serializer, calls the free functions
template<class T>
@@ -77,4 +77,4 @@
template<class T>
void from_json(const basic_json& j, T& t);
-found by argument-dependent lookup. The library defines them for standard types in detail/conversions; users add them for their own types, see Arbitrary Type Conversions. The serialization macros generate these functions.
json_pointer) addresses values inside a tree. It is also the basis of JSON Patch.binary_reader and written by binary_writer.basic_json value.to_json and from_json functions for user-defined types.Namespace nlohmann::detail contains all implementation details. It is not part of the public API and may change in any release. Besides the components above, it contains:
detail/meta/type_traits.hpp),detail/meta/cpp_future.hpp), andstring_concat and string_escape.