JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::parse_index Class Referencefinal

Represents the index of a parsed AST. More...

#include <jsonv/parse_index.hpp>

Classes

class  iterator
 

Public Types

using const_iterator = iterator
 

Public Member Functions

 parse_index () noexcept=default
 Creates an empty not-an-AST instance.
 
 parse_index (parse_index &&src) noexcept
 
parse_index & operator= (parse_index &&src) noexcept
 
void reset ()
 Clear the contents of this instance.
 
bool success () const noexcept
 Check if this instance represents a valid AST.
 
 operator bool () const noexcept
 See success.
 
void validate () const
 Validate that the parse was a success.
 
iterator begin () const
 
iterator cbegin () const
 
iterator end () const
 
iterator cend () const
 
value extract_tree (const deserialize_options &options) const
 Build a value from the document this index holds.
 
value extract_tree () const
 Build a value from the document this index holds.
 

Static Public Member Functions

static parse_index parse (std::string_view src, const parse_options &options, std::optional< std::size_t > initial_buffer_capacity)
 Create a parse_index from the given src JSON.
 
static parse_index parse (std::string_view src, std::optional< std::size_t > initial_buffer_capacity)
 Create a parse_index from the given src JSON.
 
static parse_index parse (std::string_view src, const parse_options &options)
 Create a parse_index from the given src JSON.
 
static parse_index parse (std::string_view src)
 Create a parse_index from the given src JSON.
 

Friends

std::ostream & operator<< (std::ostream &, const parse_index &)
 Get a string representation of the AST.
 
std::string to_string (const parse_index &)
 Get a string representation of the AST.
 

Detailed Description

Represents the index of a parsed AST.

When combined with the original text, can be used to create a value. See parse_index::parse to construct instances from JSON source text.

Definition at line 29 of file parse_index.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 96 of file parse_index.hpp.

Constructor & Destructor Documentation

◆ parse_index()

jsonv::parse_index::parse_index ( parse_index &&  src)
inlinenoexcept

Definition at line 102 of file parse_index.hpp.

Member Function Documentation

◆ cbegin()

iterator jsonv::parse_index::cbegin ( ) const
inline

Definition at line 170 of file parse_index.hpp.

◆ cend()

iterator jsonv::parse_index::cend ( ) const
inline

Definition at line 176 of file parse_index.hpp.

◆ extract_tree() [1/2]

value jsonv::parse_index::extract_tree ( ) const

Build a value from the document this index holds.

Extraction is controlled by options where they are given, and by deserialize_options::create_default() where they are not.

Exceptions
parse_errorif the document holds no value, which is the case for source text that is empty, only whitespace or – with parse_options::comments – only comments. Such an index is a valid one (validate does not throw for it), but there is nothing to build a value from. The error is the input ending unexpectedly, at the end of the source text.

◆ extract_tree() [2/2]

value jsonv::parse_index::extract_tree ( const deserialize_options &  options) const

Build a value from the document this index holds.

Extraction is controlled by options where they are given, and by deserialize_options::create_default() where they are not.

Exceptions
parse_errorif the document holds no value, which is the case for source text that is empty, only whitespace or – with parse_options::comments – only comments. Such an index is a valid one (validate does not throw for it), but there is nothing to build a value from. The error is the input ending unexpectedly, at the end of the source text.

◆ operator=()

parse_index & jsonv::parse_index::operator= ( parse_index &&  src)
inlinenoexcept

Definition at line 106 of file parse_index.hpp.

◆ parse() [1/4]

static parse_index jsonv::parse_index::parse ( std::string_view  src)
static

Create a parse_index from the given src JSON.

Parsing is controlled by options where they are given, and by parse_options::create_default() where they are not. The underlying buffer starts with an initial_buffer_capacity where one is given; without one, or when it is nullopt, the buffer is sized according to the length of the src string.

Exceptions
std::length_errorif a given initial_buffer_capacity is too large for the buffer's size in bytes to be represented in a std::size_t.

◆ parse() [2/4]

static parse_index jsonv::parse_index::parse ( std::string_view  src,
const parse_options &  options 
)
static

Create a parse_index from the given src JSON.

Parsing is controlled by options where they are given, and by parse_options::create_default() where they are not. The underlying buffer starts with an initial_buffer_capacity where one is given; without one, or when it is nullopt, the buffer is sized according to the length of the src string.

Exceptions
std::length_errorif a given initial_buffer_capacity is too large for the buffer's size in bytes to be represented in a std::size_t.

◆ parse() [3/4]

static parse_index jsonv::parse_index::parse ( std::string_view  src,
const parse_options &  options,
std::optional< std::size_t >  initial_buffer_capacity 
)
static

Create a parse_index from the given src JSON.

Parsing is controlled by options where they are given, and by parse_options::create_default() where they are not. The underlying buffer starts with an initial_buffer_capacity where one is given; without one, or when it is nullopt, the buffer is sized according to the length of the src string.

Exceptions
std::length_errorif a given initial_buffer_capacity is too large for the buffer's size in bytes to be represented in a std::size_t.

◆ parse() [4/4]

static parse_index jsonv::parse_index::parse ( std::string_view  src,
std::optional< std::size_t >  initial_buffer_capacity 
)
static

Create a parse_index from the given src JSON.

Parsing is controlled by options where they are given, and by parse_options::create_default() where they are not. The underlying buffer starts with an initial_buffer_capacity where one is given; without one, or when it is nullopt, the buffer is sized according to the length of the src string.

Exceptions
std::length_errorif a given initial_buffer_capacity is too large for the buffer's size in bytes to be represented in a std::size_t.

◆ success()

bool jsonv::parse_index::success ( ) const
noexcept

Check if this instance represents a valid AST.

This will be false if the source JSON was not valid JSON text. This will also be false if this instance was default-constructed or moved-from.

Note
Even if this returns true, it is possible that conversion to a jsonv::value will throw an exception. For example, if the value of a number exceeds the range of an int64_t. This is because JSON does not specify an acceptable range for numbers, but the storage of jsonv::value does.

◆ validate()

void jsonv::parse_index::validate ( ) const

Validate that the parse was a success.

Exceptions
parse_errorif the parse was not successful. This will contain additional details about why the parse failed.
std::invalid_argumentif this instance was default-constructed or moved-from.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  ,
const parse_index &   
)
friend

Get a string representation of the AST.

+-----------------—+-----—+ | ast_node_type | Output | +-----------------—+-----—+ | document_start | ^ | | document_end | $ | | object_begin | { | | object_end | } | | array_begin | [ | | array_end | ] | | string_canonical | s | | string_escaped | S | | key_canonical | k | | key_escaped | K | | literal_true | t | | literal_false | f | | literal_null | n | | integer | i | | decimal | d | | error | ! | +-----------------—+-----—+

This exists primarily for debugging purposes.

◆ to_string

std::string to_string ( const parse_index &  )
friend

Get a string representation of the AST.

+-----------------—+-----—+ | ast_node_type | Output | +-----------------—+-----—+ | document_start | ^ | | document_end | $ | | object_begin | { | | object_end | } | | array_begin | [ | | array_end | ] | | string_canonical | s | | string_escaped | S | | key_canonical | k | | key_escaped | K | | literal_true | t | | literal_false | f | | literal_null | n | | integer | i | | decimal | d | | error | ! | +-----------------—+-----—+

This exists primarily for debugging purposes.


The documentation for this class was generated from the following file: