Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
parse_error.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "preprocessor.hpp"
8#if TOML_ENABLE_PARSER
9
10#include "header_start.hpp"
11#include "print_to_stream.hpp"
12#include "source_region.hpp"
13#include "std_except.hpp"
14
15#if TOML_DOXYGEN || !TOML_EXCEPTIONS
16#define TOML_PARSE_ERROR_BASE
17#else
18#define TOML_PARSE_ERROR_BASE : public std::runtime_error
19#endif
20
23
28 class parse_error TOML_PARSE_ERROR_BASE {
29 private:
30#if !TOML_EXCEPTIONS
31 std::string description_;
32#endif
33 source_region source_;
34
35 public:
36#if TOML_EXCEPTIONS
37
39 TOML_ATTR(nonnull)
40 parse_error(const char* desc, source_region&& src) noexcept //
41 : std::runtime_error{desc}, source_{std::move(src)} {}
42
44 TOML_ATTR(nonnull)
45 parse_error(const char* desc, const source_region& src) noexcept //
46 : parse_error{desc, source_region{src}} {}
47
49 TOML_ATTR(nonnull)
50 parse_error(const char* desc, const source_position& position,
51 const source_path_ptr& path = {}) noexcept
52 : parse_error{desc, source_region{position, position, path}} {}
53
54#else
55
57 parse_error(std::string&& desc, source_region&& src) noexcept //
58 : description_{std::move(desc)}, source_{std::move(src)} {}
59
61 parse_error(std::string&& desc, const source_region& src) noexcept //
62 : parse_error{std::move(desc), source_region{src}} {}
63
65 parse_error(std::string&& desc, const source_position& position,
66 const source_path_ptr& path = {}) noexcept
67 : parse_error{std::move(desc), source_region{position, position, path}} {}
68
69#endif
70
74 std::string_view description() const noexcept {
75#if TOML_EXCEPTIONS
76 return std::string_view{what()};
77#else
78 return description_;
79#endif
80 }
81
84 const source_region& source() const noexcept { return source_; }
85
110 friend std::ostream& operator<<(std::ostream& lhs, const parse_error& rhs) {
111 impl::print_to_stream(lhs, rhs.description());
112 impl::print_to_stream(lhs, "\n\t(error occurred at "sv);
113 impl::print_to_stream(lhs, rhs.source());
114 impl::print_to_stream(lhs, ")"sv);
115 return lhs;
116 }
117 };
118
119 TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS
120}
122
123#undef TOML_PARSE_ERROR_BASE
124
125#include "header_end.hpp"
126#endif // TOML_ENABLE_PARSER
#define rhs
Definition 17.names.cpp:536
#define position
Definition 17.names.cpp:519
#define lhs
Definition 17.names.cpp:489
An error generated when parsing fails.
TOML_NODISCARD_CTOR parse_error(std::string &&desc, source_region &&src) noexcept
TOML_NODISCARD_CTOR parse_error(std::string &&desc, const source_region &src) noexcept
friend std::ostream & operator<<(std::ostream &lhs, const parse_error &rhs)
Prints a parse_error to a stream.
TOML_NODISCARD const source_region & source() const noexcept
Returns the region of the source document responsible for the error.
TOML_NODISCARD_CTOR parse_error(std::string &&desc, const source_position &position, const source_path_ptr &path={}) noexcept
TOML_NODISCARD std::string_view description() const noexcept
Returns a textual description of the error.
A TOML path.
Definition path.hpp:209
#define TOML_EXCEPTIONS
Sets whether the library uses exceptions to report parsing failures. \detail Defaults to 1 or 0 accor...
Definition json.h:5363
TOML_NAMESPACE_START
TOML_ABI_NAMESPACE_END
TOML_NAMESPACE_END
#define TOML_NODISCARD_CTOR
#define TOML_ABI_NAMESPACE_BOOL(cond, T, F)
#define TOML_NODISCARD
#define TOML_ATTR(...)
std::shared_ptr< const std::string > source_path_ptr
A pointer to a shared string resource containing a source path.
A source document line-and-column pair.
A source document region.