|
| | Fluent_parser (Parser &parser, const Format_t &format) |
| | Construct a new object, wrapping the given Parser, and using the given format when reading sub-objects. More...
|
| |
| | Fluent_parser ()=delete |
| |
| | Fluent_parser (const Fluent_parser &)=delete |
| |
| | Fluent_parser (Fluent_parser &&) noexcept=default |
| |
| Fluent_parser & | operator= (const Fluent_parser &)=delete |
| |
| Fluent_parser & | operator= (Fluent_parser &&) noexcept=default |
| |
| | ~Fluent_parser ()=default |
| |
| Self_t & | next_token_only_if (bool condition) |
| | Suppress the next token if condition is false. More...
|
| |
| Self_t & | next_token_only_if (const std::invocable auto &condition) |
| | If the states is not "closed", suppress the next token if condition evaluates to false. More...
|
| |
| Self_t & | check_prev_token (const std::invocable auto &checker) |
| | If the state is not "closed", invoke the given invocable. More...
|
| |
| Self_t & | end_optional () |
| | If the state is not "closed" save the current position, and if a subsequent invocation of a member function fails, rewind to the saved position and suppress the error. More...
|
| |
| Self_t & | call_unconditionally (const std::invocable auto &function) |
| | Invoke the given invocable regardless o the open/closed state. More...
|
| |
| Self_t & | read (auto &obj) |
| | If the state is not "closed", read into the given object once. More...
|
| |
| Self_t & | read_optional (auto &obj) |
| | If the state is not "closed" read into the given object once; if that fails with parse error, restore to the previous position and suppress the error. More...
|
| |
| Self_t & | read_any (auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until it fails. More...
|
| |
| Self_t & | read_at_least (std::size_t count, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until it fails. More...
|
| |
| Self_t & | read_at_most (std::size_t count, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until count instances are found or it fails. More...
|
| |
| Self_t & | read_exact (std::size_t count, auto &obj) |
| | If the state is not "closed", read into the given object count times. More...
|
| |
| Self_t & | read_range (std::size_t min, std::size_t max, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until max instances are found or it fails. More...
|
| |
| Self_t & | read_repeated (const Is_repeat auto &repeat, auto &object) |
| | If the state is not "closed" read with a number of repetitions specified by the given Is_repeat object. More...
|
| |
| Self_t & | read_with_format (const auto &format, auto &obj) |
| | If the state is not "closed", read into the given object once. More...
|
| |
| Self_t & | read_with_format_optional (const auto &format, auto &obj) |
| | If the state is not "closed" read into the given object once; if that fails with parse error, restore to the previous position and suppress the error. More...
|
| |
| Self_t & | read_with_format_any (const auto &format, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until it fails. More...
|
| |
| Self_t & | read_with_format_at_least (const auto &format, std::size_t count, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until it fails. More...
|
| |
| Self_t & | read_with_format_at_most (const auto &format, std::size_t count, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until count instances are found or it fails. More...
|
| |
| Self_t & | read_with_format_exact (const auto &format, std::size_t count, auto &obj) |
| | If the state is not "closed" read into the given object count times. More...
|
| |
| Self_t & | read_with_format_range (const auto &format, std::size_t min, std::size_t max, auto &obj) |
| | If the state is not "closed" read repeatedly into the given object until max instances are found or it fails. More...
|
| |
| Self_t & | read_with_format_repeated (const auto &format, const Is_repeat auto &repeat, auto &object) |
| | If the state is not "closed" read with a number of repetitions specified by the given Is_repeat object. More...
|
| |
| Self_t & | literal (const std::string_view &sv) |
| | Like read, but skips the given string literal. More...
|
| |
| Self_t & | literal_optional (const std::string_view &sv) |
| | Like read_optional, but skips the given string literal. More...
|
| |
| Self_t & | literal_any (const std::string_view &sv) |
| | Like read_any, but skips the given string literal. More...
|
| |
| Self_t & | literal_at_least (std::size_t count, const std::string_view &sv) |
| | Like read_at_least, but skips the given string literal. More...
|
| |
| Self_t & | literal_at_most (std::size_t count, const std::string_view &sv) |
| | Like read_at_most, but skips the given string literal. More...
|
| |
| Self_t & | literal_exact (std::size_t count, const std::string_view &sv) |
| | Like read_exact, but skips the given string literal. More...
|
| |
| Self_t & | literal_range (std::size_t min, std::size_t max, const std::string_view &sv) |
| | Like read_range, but skips the given string literal. More...
|
| |
| Self_t & | literal_repeated (const Is_repeat auto &repeat, const std::string_view &sv) |
| | Like read_repeated, but skips the given string literal. More...
|
| |
| Self_t & | call (const std::invocable auto &function) |
| | Like read, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_optional (const std::invocable auto &function) |
| | Like read_optional, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_any (const std::invocable auto &function) |
| | Like read_any, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_at_least (std::size_t count, const std::invocable auto &function) |
| | Like read_at_least, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_at_most (std::size_t count, const std::invocable auto &function) |
| | Like read_at_most, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_exact (std::size_t count, const std::invocable auto &function) |
| | Like read_exact, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_range (std::size_t min, std::size_t max, const std::invocable auto &function) |
| | Like read_range, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | call_repeated (const Is_repeat auto &repeat, const std::invocable auto &function) |
| | Like read_repeated, but invokes the given function instead of reading an object. More...
|
| |
| Self_t & | read_repeated_with_separators (auto &object, const std::string_view &separator, const Is_repeat auto &repeat, Allow_repeated_separators allow_repeated_separators, Leading_separators leading_separators, Trailing_separators trailing_separators) |
| | Reads repeatedly into the given object, using the given number of repetitions, and skipping string literals equal to the given string_view between reads. More...
|
| |
| Self_t & | call_repeated_with_separators (const std::invocable auto &function, const std::string_view &separator, const Is_repeat auto &repeat, Allow_repeated_separators allow_repeated_separators, Leading_separators leading_separators, Trailing_separators trailing_separators) |
| | Like read_repeated_with_separators, but invokes a function instead of reads into an object. More...
|
| |
template<Is_format Format_t>
class mysql::strconv::Fluent_parser< Format_t >
Fluent API for parsing strings.
This provides a higher-level, fluent API that wraps a lower-level Parser. An instance represents the parser together with the state of the fluent API.
By using the fluent API, parsers that read multiple sub-objects in sequence can often be implemented without having to explicitly handle the failure of each sub-object parser. This can make the implementation safer and the code clearer.
In general, the state of the Fluent_parser is either "open" or "closed". The state determines whether subsequent invocations of member functions are inhibited or not: when in "open" state, subsequent invocations are executed, and when in "closed" state, subsequent invocations do nothing. If the state is "open" and the user invokes a member function, the state remains "open" if the function succeeds and changes to "closed" if the function fails. This enables patterns such as the following for parsing a sequence of tokens:
fluent_parser
.read(object1)
.read(object2)
.read(object3);
The state of the Fluent_parser ensures that it will not attempt to parse object2 or object3 if the parsing of object1 failed. Thus, the user does not have to check for errors in this case. Fewer errors to check can make the user code simpler and safer.
There are also special member functions that provide support for common patterns in string formats:
- read_repeated_with_separators: Reads repeatedly into an object, skipping literal separators between reads, and optionally skipping literal separators before the first and/or after the last read.
- end_optional: Stores the information that it is valid for the string to end at the current position. If an error occurs while parsing subsequent tokens, the error is suppressed, the position rewound to the saved position, and the state altered to "closed".
- next_token_only_if: If the given boolean predicate is true, temporarily closes the Fluent_parser for only the following token.
- check_prev_token: Invokes a given invocable. If that produces an error in the Parser, rewinds to the position just before the last parsed token (so the error message points to just before the problematic token).
- call_unconditionally: Invokes a given invocable, regardless of the open/closed state.
The Fluent_parser also holds a Format object, used when reading objects.
- Template Parameters
-
| Format_t | Type used for the internal Format object. |