NeBuild dev
Loading...
Searching...
No Matches
parser.inl File Reference
#include "preprocessor.hpp"
#include "array.hpp"
#include "date_time.hpp"
#include "parse_error.hpp"
#include "parser.hpp"
#include "source_region.hpp"
#include "std_optional.hpp"
#include "table.hpp"
#include "unicode.hpp"
#include "value.hpp"
#include <fstream>
#include <istream>
#include <sstream>
#include <iomanip>
#include "header_start.hpp"
#include "header_end.hpp"

Go to the source code of this file.

Classes

class  utf8_byte_stream< std::basic_string_view< Char > >
 
class  utf8_byte_stream< std::istream >
 
struct  utf8_codepoint
 
struct  utf8_reader_interface
 
class  utf8_reader< T >
 
struct  utf8_reader< T >::currently_decoding_t
 
struct  utf8_reader< T >::codepoints_t
 
class  utf8_buffered_reader
 
struct  parse_integer_traits< 2 >
 
struct  parse_integer_traits< 8 >
 
struct  parse_integer_traits< 10 >
 
struct  parse_integer_traits< 16 >
 
struct  escaped_codepoint
 
struct  error_builder
 
struct  parse_scope
 
struct  parse_key_buffer
 
struct  depth_counter_scope
 
struct  parsed_string
 
struct  table_vector_scope
 
class  parser
 

Macros

#define utf8_reader_error(...)   err_.emplace(__VA_ARGS__)
 
#define utf8_reader_return_after_error(...)   return __VA_ARGS__
 
#define utf8_reader_error_check(...)
 
#define TOML_OVERALIGNED   alignas(32)
 
#define utf8_buffered_reader_error_check(...)
 
#define TOML_RETURNS_BY_THROWING
 
#define push_parse_scope_2(scope, line)   parse_scope ps_##line(current_scope, scope)
 
#define push_parse_scope_1(scope, line)   push_parse_scope_2(scope, line)
 
#define push_parse_scope(scope)   push_parse_scope_1(scope, __LINE__)
 
#define is_eof()   !cp
 
#define assert_not_eof()   TOML_ASSERT_ASSUME(cp != nullptr)
 
#define return_if_eof(...)
 
#define is_error()   !!err
 
#define return_after_error(...)   return __VA_ARGS__
 
#define assert_not_error()   TOML_ASSERT(!is_error())
 
#define return_if_error(...)
 
#define return_if_error_or_eof(...)
 
#define parse_error_break()   static_assert(true)
 
#define set_error_and_return(ret, ...)
 
#define set_error_and_return_default(...)   set_error_and_return({}, __VA_ARGS__)
 
#define set_error_and_return_if_eof(...)
 
#define advance_and_return_if_error(...)
 
#define advance_and_return_if_error_or_eof(...)
 
#define TOML_PARSE_FILE_ERROR(msg, path)
 

Functions

template<typename Char >
 utf8_reader (std::basic_string_view< Char >, std::string_view) -> utf8_reader< std::basic_string_view< Char > >
 
template<typename Char >
 utf8_reader (std::basic_string_view< Char >, std::string &&) -> utf8_reader< std::basic_string_view< Char > >
 
template<typename Char >
 utf8_reader (std::basic_istream< Char > &, std::string_view) -> utf8_reader< std::basic_istream< Char > >
 
template<typename Char >
 utf8_reader (std::basic_istream< Char > &, std::string &&) -> utf8_reader< std::basic_istream< Char > >
 
TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv (node_type val) noexcept
 
TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv (const std::string &str) noexcept
 
TOML_CONST_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv (bool val) noexcept
 
TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv (const utf8_codepoint &cp) noexcept
 
TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv (const utf8_codepoint *cp) noexcept
 
template<typename T >
TOML_INTERNAL_LINKAGE void concatenate (char *&write_pos, char *const buf_end, const T &arg) noexcept
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::string_view doc, std::string_view source_path)
 Parses a TOML document from a string view.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::string_view doc, std::string &&source_path)
 Parses a TOML document from a string view.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::istream &doc, std::string_view source_path)
 Parses a TOML document from a stream.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::istream &doc, std::string &&source_path)
 Parses a TOML document from a stream.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse_file (std::string_view file_path)
 Parses a TOML document from a file.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::string_view doc, std::wstring_view source_path)
 Parses a TOML document from a string view.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse (std::istream &doc, std::wstring_view source_path)
 Parses a TOML document from a stream.
 
TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse_file (std::wstring_view file_path)
 Parses a TOML document from a file.
 

Variables

 TOML_DISABLE_WARNINGS
 
 TOML_ENABLE_WARNINGS
 
 TOML_ANON_NAMESPACE_START
 
TOML_INTERNAL_LINKAGE constexpr auto utf8_byte_order_mark = "\xEF\xBB\xBF"sv
 
 TOML_ANON_NAMESPACE_END
 
 TOML_IMPL_NAMESPACE_START
 
 TOML_ABI_NAMESPACE_END
 
 TOML_IMPL_NAMESPACE_END
 
 TOML_NAMESPACE_START
 
 TOML_NAMESPACE_END
 

Macro Definition Documentation

◆ advance_and_return_if_error

#define advance_and_return_if_error (   ...)
Value:
do { \
assert_not_eof(); \
advance(); \
return_if_error(__VA_ARGS__); \
} while (false)

◆ advance_and_return_if_error_or_eof

#define advance_and_return_if_error_or_eof (   ...)
Value:
do { \
assert_not_eof(); \
advance(); \
return_if_error(__VA_ARGS__); \
set_error_and_return_if_eof(__VA_ARGS__); \
} while (false)

◆ assert_not_eof

#define assert_not_eof ( )    TOML_ASSERT_ASSUME(cp != nullptr)

◆ assert_not_error

#define assert_not_error ( )    TOML_ASSERT(!is_error())

◆ is_eof

#define is_eof ( )    !cp

◆ is_error

#define is_error ( )    !!err

◆ parse_error_break

#define parse_error_break ( )    static_assert(true)

◆ push_parse_scope

#define push_parse_scope (   scope)    push_parse_scope_1(scope, __LINE__)

◆ push_parse_scope_1

#define push_parse_scope_1 (   scope,
  line 
)    push_parse_scope_2(scope, line)

◆ push_parse_scope_2

#define push_parse_scope_2 (   scope,
  line 
)    parse_scope ps_##line(current_scope, scope)

◆ return_after_error

#define return_after_error (   ...)    return __VA_ARGS__

◆ return_if_eof

#define return_if_eof (   ...)
Value:
do { \
if TOML_UNLIKELY (is_eof()) return __VA_ARGS__; \
} while (false)
#define is_eof()
Definition parser.inl:808
#define TOML_UNLIKELY(...)
Definition preprocessor.hpp:538

◆ return_if_error

#define return_if_error (   ...)
Value:
do { \
if TOML_UNLIKELY (is_error()) return __VA_ARGS__; \
} while (false)
#define is_error()
Definition parser.inl:822

◆ return_if_error_or_eof

#define return_if_error_or_eof (   ...)
Value:
do { \
if TOML_UNLIKELY (is_eof() || is_error()) return __VA_ARGS__; \
} while (false)

◆ set_error_and_return

#define set_error_and_return (   ret,
  ... 
)
Value:
do { \
if (!is_error()) set_error(__VA_ARGS__); \
} while (false)
#define return_after_error(...)
Definition parser.inl:823

◆ set_error_and_return_default

#define set_error_and_return_default (   ...)    set_error_and_return({}, __VA_ARGS__)

◆ set_error_and_return_if_eof

#define set_error_and_return_if_eof (   ...)
Value:
do { \
if TOML_UNLIKELY (is_eof()) set_error_and_return(__VA_ARGS__, "encountered end-of-file"sv); \
} while (false)
#define set_error_and_return(ret,...)
Definition parser.inl:854

◆ TOML_OVERALIGNED

#define TOML_OVERALIGNED   alignas(32)

◆ TOML_PARSE_FILE_ERROR

#define TOML_PARSE_FILE_ERROR (   msg,
  path 
)
Value:
return parse_result { \
parse_error { \
msg, source_position{}, std::make_shared<const std::string>(std::move(path)) \
} \
}
The result of a parsing operation.
Definition parse_result.hpp:53
A TOML path.
Definition path.hpp:239
A source document line-and-column pair.
Definition source_region.hpp:43

◆ TOML_RETURNS_BY_THROWING

#define TOML_RETURNS_BY_THROWING

◆ utf8_buffered_reader_error_check

#define utf8_buffered_reader_error_check (   ...)
Value:
do { \
if TOML_UNLIKELY (reader_.error()) return __VA_ARGS__; \
} while (false)

◆ utf8_reader_error

#define utf8_reader_error (   ...)    err_.emplace(__VA_ARGS__)

◆ utf8_reader_error_check

#define utf8_reader_error_check (   ...)
Value:
do { \
if TOML_UNLIKELY (err_) return __VA_ARGS__; \
} while (false)

◆ utf8_reader_return_after_error

#define utf8_reader_return_after_error (   ...)    return __VA_ARGS__

Function Documentation

◆ concatenate()

template<typename T >
TOML_INTERNAL_LINKAGE void concatenate ( char *&  write_pos,
char *const  buf_end,
const T &  arg 
)
noexcept

◆ parse() [1/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::istream &  doc,
std::string &&  source_path 
)

Parses a TOML document from a stream.

\detail \cpp std::stringstream ss; ss << "a = 3"sv;

auto tbl = toml::parse(ss, "foo.toml"); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse() [2/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::istream &  doc,
std::string_view  source_path = {} 
)

Parses a TOML document from a stream.

\detail \cpp std::stringstream ss; ss << "a = 3"sv;

auto tbl = toml::parse(ss); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse() [3/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::istream &  doc,
std::wstring_view  source_path 
)

Parses a TOML document from a stream.

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

\detail \cpp std::stringstream ss; ss << "a = 3"sv;

auto tbl = toml::parse(ss); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse() [4/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::string_view  doc,
std::string &&  source_path 
)

Parses a TOML document from a string view.

\detail \cpp auto tbl = toml::parse("a = 3"sv, "foo.toml"); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse() [5/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::string_view  doc,
std::string_view  source_path = {} 
)

Parses a TOML document from a string view.

\detail \cpp auto tbl = toml::parse("a = 3"sv); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse() [6/6]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse ( std::string_view  doc,
std::wstring_view  source_path 
)

Parses a TOML document from a string view.

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

\detail \cpp auto tbl = toml::parse("a = 3"sv, L"foo.toml"); std::cout << tbl["a"] << "\n"; \ecpp

\out 3 \eout

Parameters
docThe TOML document to parse. Must be valid UTF-8.
source_pathThe path used to initialize each node's source().path. If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse_file() [1/2]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse_file ( std::string_view  file_path)

Parses a TOML document from a file.

\detail \cpp toml::parse_result get_foo_toml() { return toml::parse_file("foo.toml"); } \ecpp

Parameters
file_pathThe TOML document to parse. Must be valid UTF-8.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ parse_file() [2/2]

TOML_EXTERNAL_LINKAGE parse_result TOML_CALLCONV parse_file ( std::wstring_view  file_path)

Parses a TOML document from a file.

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

\detail \cpp toml::parse_result get_foo_toml() { return toml::parse_file(L"foo.toml"); } \ecpp

Parameters
file_pathThe TOML document to parse. Must be valid UTF-8.
Returns
\conditional_return{With exceptions} A toml::table. \conditional_return{Without exceptions} A toml::parse_result.

◆ to_sv() [1/5]

TOML_CONST_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv ( bool  val)
noexcept

◆ to_sv() [2/5]

TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv ( const std::string &  str)
noexcept

◆ to_sv() [3/5]

TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv ( const utf8_codepoint cp)
noexcept

◆ to_sv() [4/5]

TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv ( const utf8_codepoint cp)
noexcept

◆ to_sv() [5/5]

TOML_PURE_GETTER TOML_INTERNAL_LINKAGE std::string_view to_sv ( node_type  val)
noexcept

◆ utf8_reader() [1/4]

template<typename Char >
utf8_reader ( std::basic_istream< Char > &  ,
std::string &&   
) -> utf8_reader< std::basic_istream< Char > >

◆ utf8_reader() [2/4]

template<typename Char >
utf8_reader ( std::basic_istream< Char > &  ,
std::string_view   
) -> utf8_reader< std::basic_istream< Char > >

◆ utf8_reader() [3/4]

template<typename Char >
utf8_reader ( std::basic_string_view< Char >  ,
std::string &&   
) -> utf8_reader< std::basic_string_view< Char > >

◆ utf8_reader() [4/4]

template<typename Char >
utf8_reader ( std::basic_string_view< Char >  ,
std::string_view   
) -> utf8_reader< std::basic_string_view< Char > >

Variable Documentation

◆ TOML_ABI_NAMESPACE_END

TOML_ABI_NAMESPACE_END

◆ TOML_ANON_NAMESPACE_END

TOML_ANON_NAMESPACE_END

◆ TOML_ANON_NAMESPACE_START

TOML_ANON_NAMESPACE_START
Initial value:
{
template <typename T>
class utf8_byte_stream

◆ TOML_DISABLE_WARNINGS

TOML_DISABLE_WARNINGS

◆ TOML_ENABLE_WARNINGS

TOML_ENABLE_WARNINGS

◆ TOML_IMPL_NAMESPACE_END

TOML_IMPL_NAMESPACE_END

◆ TOML_IMPL_NAMESPACE_START

TOML_IMPL_NAMESPACE_START
Initial value:
{
#define TOML_EXCEPTIONS
Sets whether the library uses exceptions to report parsing failures. \detail Defaults to 1 or 0 accor...
Definition preprocessor.hpp:1126
#define TOML_ABI_NAMESPACE_BOOL(cond, T, F)
Definition preprocessor.hpp:1323

◆ TOML_NAMESPACE_END

TOML_NAMESPACE_END

◆ TOML_NAMESPACE_START

TOML_NAMESPACE_START
Initial value:

◆ utf8_byte_order_mark

TOML_INTERNAL_LINKAGE constexpr auto utf8_byte_order_mark = "\xEF\xBB\xBF"sv
constexpr