4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt.parse

Description

Library for parsers.

Link to fcppt_parse_interface.

Introduction

A parser gets a string as input and if it belongs to a certain language it transforms this string into a specific output. Parsers are built up from basic parsers and combinating parsers. The most basic parsers are:

From this, more complicated parsers can be built. The combinating parsers are:

Let us consider the following example. We want to parse numbers of the form {0, ..., 9}*, where we allow multiple leading zeroes for simplicity. Each word that belongs to this language should produce a word over the alphabet {0,...,9}. To encode this in C++, we start with an enum of the form

enum class digit : std::uint8_t
{
_0,
_1,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9
};

Next, we create a function that given char c and digit d, it produces a parser that returns d if and only if it gets c as input:

auto make_digit(char const c, digit const d)
{
}

We can use this function to create a parser that recognizes any digit:

auto const p09{
make_digit('0', digit::_0) | make_digit('1', digit::_1) | make_digit('2', digit::_2) |
make_digit('3', digit::_3) | make_digit('4', digit::_4) | make_digit('5', digit::_5) |
make_digit('6', digit::_6) | make_digit('7', digit::_7) | make_digit('8', digit::_8) |
make_digit('9', digit::_9)};

Here, the operator| constructs a fcppt::parse::alternative out of its two arguments. The result type of p09 is still digit because variant<digit, ..., digit> is simplified to digit. To recognize an arbitrary string of digits, we define the following parser:

auto const p09_repeat{*fcppt::make_cref(p09)};

The operator* creates an fcppt::parse::repetition out of its argument. Its result type is vector<digit>. The fcppt::parse::parse_string function takes a parser P and a string and returns an fcppt::either::object of fcppt::parse::parse_string_error and P's result type. We can then inspect this either by using fcppt::either::match.

fcppt::parse::parse_string(p09_repeat, std::string{"12345"}),
[](fcppt::parse::parse_string_error<char> const &error) { std::cerr << error << '\n'; },
[](std::vector<digit> const &result) {
std::cout << "Success\n";
print(result);
});

Whitespace Skipping

A lot of languages are not whitespace-sensitive, which means that whitespaces can be added in a lot of places. For example, in JSON, we can write [1,2] or [1, 2], which both result in an array with elements 1 and 2. Here, we use the notaiton of a Skipper to achieve this behaviour. A skipper is simpler than a parser in the sense that it never produces results, it only consumes input. Skippers are run in very specific places:

Whitespace skipping can be disabled using fcppt::parse::lexeme. Consider the following example: We declare a parser that parses two unsigned ints in succession.

auto const parser{uint_p{} >> uint_p{}};

Without whitespace skipping, this parser can never succeed, since the first uint parser will always consume as many digits as it can, leaving nothing for the second uint parser. In the following example, the first uint parser reads 10, stops at the space character, and then the second parser fails.

fcppt::parse::parse_string(parser, std::string{"10 20"}), on_failure, on_success);

However, if we use whitespace skipping, then the first uint parser reads 10, stops at the space character, then the sequence (>>) parser runs the skipper, which consumes the space character, and then the second uint parser reads 20. The skipper we use here consumes as many space characters as possible.

parser, std::string{"10 20"}, *fcppt::parse::skipper::literal{' '}),
on_failure,
on_success);

Note that the implementation of fcppt::parse::parse runs fcppt::parse::phrase_parse internally, using the skipper fcppt::parse::skipper::epsilon, which does nothing.

Recursive Parsers

Consider a language where we want to parse lists of the form {E_1, ..., E_n}, where E_1, ..., E_n are of the form name = L (where we allow names to consist of the characters a, b and c) and L is again a list. First, we need to create a C++ data type that represents such a list, which we declare as follows:

struct list;
struct list { std::vector<entry> elements; };

We would like to create a parser for lists and a parser for entries. The parser for lists needs the parser for entries in its definition and vice versa. To deal with (mutually) recursive definitions, we do the following:

In our example, we declare the class as follows:

class grammar : public grammar_base
{
FCPPT_NONMOVABLE(grammar);
public:
grammar();
~grammar() = default;
private:
grammar_base::base_type<list> list_p;
grammar_base::base_type<entry> entry_p;
};

First, fcppt::parse::grammar is a helper class that the actual grammars derive from. It selects the result type produced by the start rule, the character type of the input and the skipper type that is being used. Here, we use fcppt::parse::skipper::epsilon, which implies that no skipping is done. To actually implement the grammar, we have to define its constructor. Here, we have to pass a reference to one of our parsers to the base class, which defines the start nonterminal of the grammar. We also have to pass an implementation of the skipper type, which in this case simply is the epsilon skipper.

grammar::grammar()
: grammar_base{fcppt::make_cref(list_p), fcppt::parse::skipper::epsilon{}},
list_p{grammar_base::make_base(fcppt::parse::construct<list>(fcppt::parse::list{
fcppt::make_cref(entry_p),
fcppt::parse::literal{'}'}}))},
entry_p{grammar_base::make_base(
+fcppt::parse::char_set{'a', 'b', 'c'} >> fcppt::parse::literal{'='} >>
{
}

To use the grammar for parsing, we call fcppt::parse::grammar_parse_string. This internally uses fcppt::parse::phrase_parse_string, passing the start symbol and the skipper of the grammar.

fcppt::parse::grammar_parse_string(std::string{"{ab={c={}},b={}}"},grammar{}),
on_failure,
on_success);

Fatal Errors

The parser implementation makes use of so-called backtracking, which means that certain parsers are expected to fail, and if they do, the input stream is set to a previous position and another parser is tried instead. For example, the alternative parser a | b first tries a and then b. Suppose that a fails on the current input. Internally, the parser a | b first saves the current position p, runs a and after it fails, resets the position to p and runs b. However, depending on why a fails, we know that b cannot succeed. Consider the following example:

using lit = fcppt::parse::literal;
auto const a{lit{'{'} >> lit{'}'}};
auto const b{lit{'['} >> lit{']'}};
auto const p{fcppt::make_cref(a) | fcppt::make_cref(b)};

The parser a fails if the input is {], but still the parser b is tried even though it cannot succeed. This is fine in most cases, but in some this may lead to excessive backtracking. In addition, the parser a | b will produce an error message of the form

{ Line 1:3: Expected }, got ] OR Line 1:2: Expected [, got { }.

Since we know that b cannot succeed if a fails after reading {, we can make the part after { fatal.

using lit = fcppt::parse::literal;
auto const a{lit{'{'} >> fcppt::parse::make_fatal(lit{'}'})};
auto const b{lit{'['} >> lit{']'}};
auto const p{fcppt::make_cref(a) | fcppt::make_cref(b)};

Then the parser a | b does not try b on input {]. Instead, it aborts immediately, and produces an error message of the form

Line 1:3: Expected }, got ].

Warning
Consider fatal errors as an optimization both to parsing and to error messages. Be careful not to place fatal errors in the wrong place. For example, if we made the whole parser a fatal, then the parser b would never be tried! Using too many fatal errors can make parsers really hard to understand.

Parser and Skipper Overview

Parsers

The following tables gives a quick overview over all available parsers. In the type column, we write that a parser P has type (T_1,...,T_n) -> U, which means that if P is constructed from parsers that produce T_1, ..., T_n, then P produces U.

Parser Type

Description

fcppt::parse::alternative (L,R) -> fcppt::parse::alternative_result<L,R>

Returns the result of the first matching parser.

fcppt::parse::as_struct fcppt::tuple::object<T_1,...,T_n> -> struct { T_1 t_1; ... ; T_n t_n }

Converts a tuple to a struct.

fcppt::parse::basic_char, fcppt::parse::char_ Char

Parses any character.

fcppt::parse::basic_char_set, fcppt::parse::char_set Char

Parses a set of characters.

fcppt::parse::basic_literal, fcppt::parse::literal fcppt::unit

Parses a specific character.

fcppt::parse::basic_string, fcppt::parse::string fcppt::unit

Parses a specific string.

fcppt::parse::complement fcppt::unit -> fcppt::unit

Complements a fcppt::parse::basic_char_set parser.

fcppt::parse::construct T -> U

Constructs U from T.

fcppt::parse::convert T -> U

Converts T to U using a function.

fcppt::parse::convert_const fcppt::unit -> U

Converts to U.

fcppt::parse::convert_if T -> U

Converts T to U using a function. Can fail.

fcppt::parse::epsilon fcppt::unit

Parses the empty string.

fcppt::parse::exclude (T,fcppt::unit) -> T

Matches only if another parser fails.

fcppt::parse::fail fcppt::unit

Always fails.

fcppt::parse::float_ Float

Parses floats.

fcppt::parse::ignore T -> fcppt::unit

Ignores a result.

fcppt::parse::int_ Signed Int

Parses signed integers.

fcppt::parse::lexeme T -> T

Disables skipping.

fcppt::parse::list (fcppt::unit, T, fcppt::unit, fcppt::unit) -> std::vector<T>

Parses a list of delimited values with opening and closing parentheses.

fcppt::parse::named T -> T

Gives a parser a name, improving error messages.

fcppt::parse::not_ fcppt::unit -> fcppt::unit

Reverses a parser.

fcppt::parse::optional T -> fcppt::optional::object<T>

Creates a parser that may fail.

fcppt::parse::recursive T -> fcppt::recursive<T>

Wraps a type in fcppt::recursive.

fcppt::parse::repetition T -> fcppt::parse::repetition_result<T>

Repeats a parser as long as possible.

fcppt::parse::repetition_plus T -> fcppt::parse::repetition_result<T>

Repeats a parser as long as possible. Only accepts nonempty results.

fcppt::parse::separator (T,fcppt::unit) -> std::vector<T>

Parses a list of delimited values.

fcppt::parse::sequence (L,R) -> fcppt::parse::sequence_result<L,R>

Uses two parsers in succession.

fcppt::parse::uint Unsigned Int

Parses unsigned integers.

Skippers

The following table shows a list of available skippers.

Skipper

Description

fcppt::parse::skipper::basic_char_set, fcppt::parse::skipper::char_set

Skips a set of characters.

fcppt::parse::skipper::basic_literal, fcppt::parse::skipper::literal

Skips a specific character.

fcppt::parse::skipper::epsilon

Skips nothing.

fcppt::parse::skipper::repetition

Repeats a skipper as long as possible.

fcppt::parse::skipper::sequence

Runs two skippers in succession.

Parser definition

A parser is an object with the following properties:

A skipper is an object with the following properties:

Classes

class  fcppt::parse::alternative< Left, Right >
 Tries the left parser, and if that fails also the right parser. Uses the result of the first one that does not fail. More...
 
class  fcppt::parse::base< Result, Ch, Skipper >
 Base class for a parser. More...
 
class  fcppt::parse::basic_char< Ch >
 Parses a single character and returns it. More...
 
class  fcppt::parse::basic_char_set< Ch >
 Parses a set of characters and returns which one has matched. More...
 
class  fcppt::parse::basic_literal< Ch >
 Parses a specific character and returns nothing. More...
 
class  fcppt::parse::basic_stream< Ch >
 The stream class used while parsing. More...
 
class  fcppt::parse::basic_string< Ch >
 Parses a specific string and returns nothing. More...
 
class  fcppt::parse::complement< Parser >
 Builds the complement of a fcppt::parse::basic_char_set parser. More...
 
class  fcppt::parse::convert_const< Parser, Result >
 Replaces the success value of a parser with a constant. More...
 
class  fcppt::parse::convert< Parser, Result >
 Converts the success value of a parser into another success value. More...
 
class  fcppt::parse::convert_if< Ch, Parser, Result >
 Converts the success value of a parser into either another success value or an error. More...
 
class  fcppt::parse::epsilon
 Parses the empty string, returns nothing. More...
 
class  fcppt::parse::error< Ch >
 The error type. More...
 
class  fcppt::parse::exclude< Parser, Exclude >
 Matches only if another parser does not match. More...
 
class  fcppt::parse::fail< Result >
 Always fails. More...
 
class  fcppt::parse::fatal< Parser >
 Makes all error fatal. More...
 
class  fcppt::parse::float_< Type >
 Parses floating-point numbers. More...
 
class  fcppt::parse::grammar< Result, Ch, Skipper >
 Base class for grammars. More...
 
class  fcppt::parse::ignore< Parser >
 Ignores the result of a parser. More...
 
class  fcppt::parse::int_< Type >
 Parses signed integers. More...
 
class  fcppt::parse::lexeme< Parser >
 Disables the skipper. More...
 
class  fcppt::parse::list< Start, Inner, Sep, End >
 Parses lists, e.g., [a_1,...,a_n]. More...
 
class  fcppt::parse::named< Ch, Parser >
 Gives a parser a name, improving error messages. More...
 
class  fcppt::parse::not_< Parser >
 Negates the result of a parser, returns nothing. More...
 
class  fcppt::parse::optional< Parser >
 Makes a parser optional. More...
 
class  fcppt::parse::position< Ch >
 The position of an fcppt::parse::basic_stream. More...
 
class  fcppt::parse::recursive< Parser >
 Wraps a type in fcppt::recursive. More...
 
class  fcppt::parse::repetition< Parser >
 Tries a parser repeatedly, producing a vector of results. More...
 
class  fcppt::parse::repetition_plus< Parser >
 Tries a parser repeatedly, producing a vector of results. Must produce at least one element. More...
 
class  fcppt::parse::separator< Inner, Ch >
 Parses a list of elements, delimited by a separator, e.g., a_1,...,a_n. More...
 
class  fcppt::parse::sequence< Left, Right >
 Tries two parsers in succession. Produces a tuple of both results if both parsers do not fail. More...
 
class  fcppt::parse::skipper::alternative< Left, Right >
 Tries the left skipper, and if that fails also the right skipper. More...
 
class  fcppt::parse::skipper::any
 Skips a single character. More...
 
class  fcppt::parse::skipper::basic_char_set< Ch >
 Skips all characters from a set. More...
 
class  fcppt::parse::skipper::basic_literal< Ch >
 Skips a specific character. More...
 
class  fcppt::parse::skipper::epsilon
 Skips nothing. More...
 
class  fcppt::parse::skipper::not_< Skipper >
 Negates the result of a skipper. More...
 
class  fcppt::parse::skipper::repetition< Parser >
 Skips characters repeatedly. More...
 
class  fcppt::parse::skipper::sequence< Left, Right >
 Tries two skippers in succession. More...
 
struct  fcppt::parse::skipper::tag
 The tag skippers derive from. More...
 
struct  fcppt::parse::tag
 The tag parsers derive from. More...
 
class  fcppt::parse::uint< Type >
 Parses unsigned integers. More...
 

Typedefs

template<typename Left , typename Right >
using fcppt::parse::alternative_result
 The result type of an alternative parser.
 
template<typename Result , typename Ch , typename Skipper >
using fcppt::parse::base_unique_ptr = fcppt::unique_ptr<fcppt::parse::base<Result, Ch, Skipper>>
 unique_ptr to fcppt::parse::base
 
template<typename Ch >
using fcppt::parse::basic_char_set_container = std::unordered_set<Ch>
 The character set type.
 
using fcppt::parse::char_ = fcppt::parse::basic_char<char>
 
using fcppt::parse::char_set = fcppt::parse::basic_char_set<char>
 
using fcppt::parse::column = fcppt::strong_typedef< std::uint64_t ,_>
 The column type of a position.
 
template<typename Parser >
using fcppt::parse::deref_type = std::remove_cvref_t<fcppt::deref_type<Parser const>>
 The dereferenced type of a parser.
 
template<typename Type >
using fcppt::parse::is_char = std::disjunction<std::is_same<Type, char>, std::is_same<Type, wchar_t>>
 The allowed char types, currently char and wchar_t.
 
template<typename Type >
using fcppt::parse::is_parser = std::is_base_of<fcppt::parse::tag, Type>
 Checks if a type is a parser.A type is a parser if and only if it derives from fcppt::parse::tag.
 
template<typename Type >
using fcppt::parse::is_valid_argument
 Checks if a parameter is a valid parser type.
 
using fcppt::parse::line = fcppt::strong_typedef< std::uint64_t ,_>
 The line type of a position.
 
using fcppt::parse::literal = fcppt::parse::basic_literal<char>
 
template<typename Type >
using fcppt::parse::repetition_result
 The result type of a repetition parser.
 
template<typename Ch , typename Type >
using fcppt::parse::result = fcppt::either::object<fcppt::parse::error<Ch>, Type>
 The result type when parsing streams of Ch, producing values of Type.The result is an fcppt::either::object of fcppt::parse::error<Ch> and Type.
 
template<typename Parser >
using fcppt::parse::result_of = typename fcppt::parse::deref_type<Parser>::result_type
 The result type of a parser.
 
template<typename Left , typename Right >
using fcppt::parse::sequence_result
 The result of a sequence parser.
 
using fcppt::parse::skipper::char_set = fcppt::parse::skipper::basic_char_set<char>
 
template<typename Type >
using fcppt::parse::skipper::is_skipper = std::is_base_of<fcppt::parse::skipper::tag, Type>
 Checks if a type is a skipper.A type is a skipper if and only if it derives from fcppt::parse::skipper::tag.
 
template<typename Type >
using fcppt::parse::skipper::is_valid_argument
 Checks if a parameter is a valid skipper type.
 
using fcppt::parse::skipper::literal = fcppt::parse::skipper::basic_literal<char>
 
template<typename Ch >
using fcppt::parse::skipper::result = fcppt::either::error<fcppt::parse::error<Ch>>
 The result type when skipping streams of Ch.The result is an fcppt::either::error of fcppt::parse::error<Ch>.
 
using fcppt::parse::skipper::string = fcppt::parse::skipper::basic_string<char>
 
using fcppt::parse::string = fcppt::parse::basic_string<char>
 

Functions

template<typename Result , typename Parser >
requires (fcppt::tuple::is_object<fcppt::parse::result_of<Parser>>::value)
fcppt::parse::convert< std::remove_cvref_t< Parser >, Result > fcppt::parse::as_struct (Parser &&_parser)
 Creates a parser that converts a tuple into a struct.
 
fcppt::parse::char_set fcppt::parse::blank ()
 Parser that parses blank characters.
 
template<typename Ch >
fcppt::parse::basic_char_set_container< Ch > fcppt::parse::blank_set ()
 The set of blank characters.
 
template<typename Result , typename Parser >
fcppt::parse::convert< std::remove_cvref_t< Parser >, Result > fcppt::parse::construct (Parser &&_parser)
 Applies a constructor to the result of a parser.
 
template<typename Parser >
fcppt::parse::deref_type< Parser > const & fcppt::parse::deref (Parser const &_parser)
 Dereferences a parser.
 
template<typename Ch >
fcppt::parse::basic_char_set< Ch > fcppt::parse::digits ()
 The char set of digits.
 
template<typename Ch >
fcppt::optional::object< Ch > fcppt::parse::get_char (fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state)
 The next character in a stream.
 
template<typename Ch >
fcppt::parse::position< Ch > fcppt::parse::get_position (fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state)
 The current position of a stream.
 
template<typename Result , typename Ch , typename Skipper >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, Result > fcppt::parse::grammar_parse_stream (std::basic_istream< Ch > &_stream, fcppt::parse::grammar< Result, Ch, Skipper > const &_grammar)
 Parse a stream using a grammar.
 
template<typename Result , typename Ch , typename Skipper >
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, Result > fcppt::parse::grammar_parse_string (std::basic_string< Ch > &&_string, fcppt::parse::grammar< Result, Ch, Skipper > const &_grammar)
 Parse a string using a grammar.
 
template<typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::parse::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::parse::location const &_loc)
 Outputs a location to a stream.
 
template<typename Ch , typename Skipper , typename Parser >
fcppt::parse::base_unique_ptr< fcppt::parse::result_of< Parser >, Ch, Skipper > fcppt::parse::make_base (Parser &&_parser)
 Hides the type of a parser, turning it into an fcppt::parse::base_unique_ptr.
 
template<typename Parser , typename Convert >
fcppt::parse::convert< std::remove_cvref_t< Parser >, std::invoke_result_t< Convert, fcppt::parse::result_of< Parser > && > > fcppt::parse::make_convert (Parser &&_parser, Convert &&_convert)
 Creates an fcppt::parse::convert parser out of a lambda.
 
template<typename Ch , typename Parser , typename Convert >
fcppt::parse::convert_if< Ch, std::remove_cvref_t< Parser >, fcppt::either::success_type< std::invoke_result_t< Convert, fcppt::parse::position< Ch >, fcppt::parse::result_of< Parser > && > > > fcppt::parse::make_convert_if (Parser &&_parser, Convert &&_convert)
 Creates an fcppt::parse::convert_if parser out of a lambda.
 
template<typename Parser >
fcppt::parse::fatal< std::remove_cvref_t< Parser > > fcppt::parse::make_fatal (Parser &&_parser)
 Creates an fcppt::parse::fatal parser.
 
template<typename Parser >
fcppt::parse::ignore< std::remove_cvref_t< Parser > > fcppt::parse::make_ignore (Parser &&_parser)
 Creates an fcppt::parse::ignore parser.
 
template<typename Parser >
fcppt::parse::lexeme< std::remove_cvref_t< Parser > > fcppt::parse::make_lexeme (Parser &&_parser)
 Creates an fcppt::parse::lexeme parser.
 
template<typename Ch >
fcppt::parse::basic_literal< Ch > fcppt::parse::make_literal (Ch const _ch)
 Creates an fcppt::parse::basic_literal parser.
 
template<typename Ch , typename Success >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, std::remove_cvref_t< Success > > fcppt::parse::make_parse_stream_success (Success &&_success)
 Creates a success value with a parse_stream failure type.
 
template<typename Ch , typename Success >
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, std::remove_cvref_t< Success > > fcppt::parse::make_parse_string_success (Success &&_success)
 Creates a success value with a parse_string failure type.
 
template<typename Parser >
fcppt::parse::recursive< std::remove_cvref_t< Parser > > fcppt::parse::make_recursive (Parser &&_parser)
 Creates an fcppt::parse::recursive parser.
 
template<typename Ch , typename Success >
fcppt::parse::result< Ch, std::remove_cvref_t< Success > > fcppt::parse::make_success (Success &&_success)
 Creates an fcppt::parse::result from a success value.
 
template<typename Parser >
fcppt::parse::with_location< std::remove_cvref_t< Parser > > fcppt::parse::make_with_location (Parser &&_parser)
 Creates an fcppt::parse::with_location parser.
 
template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::alternative< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator| (Left &&_left, Right &&_right)
 Creates an fcppt::parse::alternative parser.
 
template<typename Parser >
requires (fcppt::parse::detail::is_char_set<fcppt::parse::deref_type<Parser>>::value)
auto fcppt::parse::operator~ (Parser &&_parser)
 Creates an fcppt::parse::complement parser.
 
template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::exclude< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator- (Left &&_left, Right &&_right)
 Creates an fcppt::parse::exclude parser.
 
template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::not_< std::remove_cvref_t< Parser > > fcppt::parse::operator! (Parser &&_parser)
 Creates an fcppt::parse::not_ parser.
 
template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::optional< std::remove_cvref_t< Parser > > fcppt::parse::operator- (Parser &&_parser)
 Creates an fcppt::parse::optional parser.
 
template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::repetition< std::remove_cvref_t< Parser > > fcppt::parse::operator* (Parser &&_parser)
 Creates an fcppt::parse::repetition parser.
 
template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::repetition_plus< std::remove_cvref_t< Parser > > fcppt::parse::operator+ (Parser &&_parser)
 Creates an fcppt::parse::repetition_plus parser.
 
template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::sequence< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator>> (Left &&_left, Right &&_right)
 Creates an fcppt::parse::sequence parser.
 
template<typename Ch , typename Parser >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse (Parser const &_parser, fcppt::parse::basic_stream< Ch > &_input)
 Parses without whitespace skipping.
 
template<typename Ch , typename Parser >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse_stream (Parser const &_parser, std::basic_istream< Ch > &_input)
 Parses a std::basic_istream without whitespace skipping.
 
template<typename Ch , typename Parser >
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse_string (Parser const &_parser, std::basic_string< Ch > &&_string)
 Parses a std::basic_string without whitespace skipping.
 
template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse (Parser const &_parser, fcppt::parse::basic_stream< Ch > &_input, Skipper const &_skipper)
 The basic parse function.
 
template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse_stream (Parser const &_parser, std::basic_istream< Ch > &_input, Skipper const &_skipper)
 Parses a std::basic_istream, using whitespace skipping.
 
template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse_string (Parser const &_parser, std::basic_string< Ch > &&_string, Skipper const &_skipper)
 Parses a std::basic_string, using whitespace skipping.
 
template<typename Ch >
bool fcppt::parse::operator== (fcppt::parse::position< Ch > const &_left, fcppt::parse::position< Ch > const &_right)
 Compares two positions for equality.
 
template<typename Ch >
std::basic_ostream< Ch > & fcppt::parse::operator<< (std::basic_ostream< Ch > &_stream, fcppt::parse::position< Ch > const &_pos)
 Outputs a position to a stream.
 
template<typename Ch >
void fcppt::parse::set_position (fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state, fcppt::parse::position< Ch > const _pos)
 Sets the current position of a stream.
 
template<typename Ch >
auto fcppt::parse::skipper::basic_space ()
 Skips all characters from fcppt::parse::space_set.
 
template<typename Ch >
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::make_failure (fcppt::parse::error< Ch > &&_error)
 Creates a skipper result from an fcppt::parse::error.
 
template<typename Ch >
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::make_success ()
 Creates a skipper success result.
 
template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::skipper::is_valid_argument<Left>, fcppt::parse::skipper::is_valid_argument<Right>>)
fcppt::parse::skipper::alternative< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::skipper::operator| (Left &&_left, Right &&_right)
 Creates an fcppt::parse::skipper::alternative skipper.
 
template<typename Skipper >
requires (fcppt::parse::skipper::is_valid_argument<Skipper>::value)
fcppt::parse::skipper::not_< std::remove_cvref_t< Skipper > > fcppt::parse::skipper::operator! (Skipper &&_skipper)
 Creates an fcppt::parse::skipper::not_ skipper.
 
template<typename Parser >
requires (fcppt::parse::skipper::is_valid_argument<Parser>::value)
fcppt::parse::skipper::repetition< std::remove_cvref_t< Parser > > fcppt::parse::skipper::operator* (Parser &&_parser)
 Creates an fcppt::parse::skipper::repetition.
 
template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::skipper::is_valid_argument<Left>, fcppt::parse::skipper::is_valid_argument<Right>>)
fcppt::parse::skipper::sequence< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::skipper::operator>> (Left &&_left, Right &&_right)
 Creates an fcppt::parse::skipper::sequence.
 
template<typename Ch , typename Skipper >
requires (fcppt::parse::skipper::is_skipper_v<Skipper>)
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::run (Skipper const &_skipper, fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state)
 Runs a skipper on a stream.
 
auto fcppt::parse::skipper::space ()
 The skipper basic_space<char>.
 
fcppt::parse::char_set fcppt::parse::space ()
 The char set parser using fcppt::parse::space_set<char>.
 
template<typename Ch >
fcppt::parse::basic_char_set_container< Ch > fcppt::parse::space_set ()
 The char set of spaces.Returns the set containing the whitespace, newline and tab characters.
 

Variables

template<typename Type >
constexpr bool fcppt::parse::skipper::is_skipper_v = fcppt::parse::skipper::is_skipper<Type>::value
 Checks if a type is a skipper.
 

Typedef Documentation

◆ alternative_result

template<typename Left , typename Right >
using fcppt::parse::alternative_result
Initial value:
fcppt::parse::detail::alternative_result<fcppt::mpl::list::unique<fcppt::mpl::list::append<
fcppt::parse::detail::alternative_list<Left>,
fcppt::parse::detail::alternative_list<Right>>>>

The result type of an alternative parser.

Let V<T> for a type T be the function that adds a variant type around T if T is not a variant already, or more formally:

Let variant<L_1,...,L_n> and variant<R_1,...,R_m> be the results of applying V to Left and Right.

  • If n+m=1 and m=0, then alternative_result<Left,Right> is L_1.
  • If n+m=1 and n=0, then alternative_result<Left,Right> is R_1.
  • If n+m>1, then alternative_result<Left,Right> is variant<L_1,...,L_n,R_1,...,R_m>.

◆ base_unique_ptr

template<typename Result , typename Ch , typename Skipper >
using fcppt::parse::base_unique_ptr = fcppt::unique_ptr<fcppt::parse::base<Result, Ch, Skipper>>

◆ basic_char_set_container

template<typename Ch >
using fcppt::parse::basic_char_set_container = std::unordered_set<Ch>

The character set type.

◆ char_

◆ char_set [1/2]

◆ char_set [2/2]

◆ column

using fcppt::parse::column = fcppt::strong_typedef< std::uint64_t ,_>

The column type of a position.

◆ deref_type

template<typename Parser >
using fcppt::parse::deref_type = std::remove_cvref_t<fcppt::deref_type<Parser const>>

The dereferenced type of a parser.

See also
fcppt::deref_type

◆ is_char

template<typename Type >
using fcppt::parse::is_char = std::disjunction<std::is_same<Type, char>, std::is_same<Type, wchar_t>>

The allowed char types, currently char and wchar_t.

◆ is_parser

template<typename Type >
using fcppt::parse::is_parser = std::is_base_of<fcppt::parse::tag, Type>

Checks if a type is a parser.A type is a parser if and only if it derives from fcppt::parse::tag.

◆ is_skipper

template<typename Type >
using fcppt::parse::skipper::is_skipper = std::is_base_of<fcppt::parse::skipper::tag, Type>

Checks if a type is a skipper.A type is a skipper if and only if it derives from fcppt::parse::skipper::tag.

◆ is_valid_argument [1/2]

template<typename Type >
using fcppt::parse::is_valid_argument
Initial value:

Checks if a parameter is a valid parser type.

Parsers can be passed as-is, by fcppt::reference or by fcppt::unique_ptr.

◆ is_valid_argument [2/2]

template<typename Type >
using fcppt::parse::skipper::is_valid_argument
Initial value:

Checks if a parameter is a valid skipper type.

Skippers can be passed as-is, by fcppt::reference or by fcppt::unique_ptr.

◆ line

using fcppt::parse::line = fcppt::strong_typedef< std::uint64_t ,_>

The line type of a position.

◆ literal [1/2]

◆ literal [2/2]

◆ repetition_result

template<typename Type >
using fcppt::parse::repetition_result
Initial value:
std::conditional_t<
std::basic_string<Type>,
std::vector<Type>>

The result type of a repetition parser.

If Type is a character type (see fcppt::parse::is_char), then the result is std::basic_string<Type>. Otherwise, it is std::vector<Type>.

◆ result [1/2]

template<typename Ch , typename Type >
using fcppt::parse::result = fcppt::either::object<fcppt::parse::error<Ch>, Type>

The result type when parsing streams of Ch, producing values of Type.The result is an fcppt::either::object of fcppt::parse::error<Ch> and Type.

◆ result [2/2]

The result type when skipping streams of Ch.The result is an fcppt::either::error of fcppt::parse::error<Ch>.

◆ result_of

template<typename Parser >
using fcppt::parse::result_of = typename fcppt::parse::deref_type<Parser>::result_type

The result type of a parser.

◆ sequence_result

template<typename Left , typename Right >
using fcppt::parse::sequence_result
Initial value:
decltype(fcppt::parse::detail::sequence_result(std::declval<Left>(), std::declval<Right>()))

The result of a sequence parser.

Let V<T> for a type T be the function that adds a tuple type around T if T is not a tuple already, or more formally:

The result type is computed as follows:

  • If Left is fcppt::unit, then the result is Right.
  • If Right is fcppt::unit, then the result is Left.
  • Now let tuple<L_1,...,L_n> and tuple<R_1,...,R_m> be the results of applying V to Left and Right. Then the result is tuple<L_1,...,L_n,R_1,...,R_m>.

◆ string [1/2]

◆ string [2/2]

Function Documentation

◆ as_struct()

template<typename Result , typename Parser >
requires (fcppt::tuple::is_object<fcppt::parse::result_of<Parser>>::value)
fcppt::parse::convert< std::remove_cvref_t< Parser >, Result > fcppt::parse::as_struct ( Parser && _parser)

Creates a parser that converts a tuple into a struct.

If Parser returns an fcppt::tuple::object<T_1,...,T_n>{t_1,...,t_n}, then Result{t_1,...,t_n} is returned. This implies that Result must be constructible from T_1,...,T_n.

Template Parameters
ParserA parser whose result is an fcppt::tuple::object.

◆ basic_space()

template<typename Ch >
auto fcppt::parse::skipper::basic_space ( )
inline

Skips all characters from fcppt::parse::space_set.

◆ blank()

fcppt::parse::char_set fcppt::parse::blank ( )
inline

Parser that parses blank characters.

◆ blank_set()

template<typename Ch >
fcppt::parse::basic_char_set_container< Ch > fcppt::parse::blank_set ( )
inline

The set of blank characters.

Space and tab characters are considered to be blank characters.

◆ construct()

template<typename Result , typename Parser >
fcppt::parse::convert< std::remove_cvref_t< Parser >, Result > fcppt::parse::construct ( Parser && _parser)

Applies a constructor to the result of a parser.

If the parser p returns s on success, then construct(p) returns Result{s} on success. Errors remain unchanged.

◆ deref()

template<typename Parser >
fcppt::parse::deref_type< Parser > const & fcppt::parse::deref ( Parser const & _parser)
inline

Dereferences a parser.

See also
fcppt::deref

◆ digits()

template<typename Ch >
fcppt::parse::basic_char_set< Ch > fcppt::parse::digits ( )

The char set of digits.

Returns the char set of {0,...,9}.

◆ get_char()

template<typename Ch >
fcppt::optional::object< Ch > fcppt::parse::get_char ( fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state)

The next character in a stream.

◆ get_position()

template<typename Ch >
fcppt::parse::position< Ch > fcppt::parse::get_position ( fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state)

The current position of a stream.

◆ grammar_parse_stream()

template<typename Result , typename Ch , typename Skipper >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, Result > fcppt::parse::grammar_parse_stream ( std::basic_istream< Ch > & _stream,
fcppt::parse::grammar< Result, Ch, Skipper > const & _grammar )
nodiscard

Parse a stream using a grammar.

◆ grammar_parse_string()

template<typename Result , typename Ch , typename Skipper >
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, Result > fcppt::parse::grammar_parse_string ( std::basic_string< Ch > && _string,
fcppt::parse::grammar< Result, Ch, Skipper > const & _grammar )

Parse a string using a grammar.

◆ make_base()

template<typename Ch , typename Skipper , typename Parser >
fcppt::parse::base_unique_ptr< fcppt::parse::result_of< Parser >, Ch, Skipper > fcppt::parse::make_base ( Parser && _parser)

Hides the type of a parser, turning it into an fcppt::parse::base_unique_ptr.

Note that a parser is usually polymorphic over character types and skipper types. However, when converting a parser to a base type, the character type Ch and the skipper type Skipper have to be committed, e.g. fcppt::parse::make_base<char,fcppt::parse::skipper::epsilon>(my_parser).

◆ make_convert()

template<typename Parser , typename Convert >
fcppt::parse::convert< std::remove_cvref_t< Parser >, std::invoke_result_t< Convert, fcppt::parse::result_of< Parser > && > > fcppt::parse::make_convert ( Parser && _parser,
Convert && _convert )

Creates an fcppt::parse::convert parser out of a lambda.

Parameters
_parserThe parser to convert from.
_convertThe lambda function to use as conversion.

◆ make_convert_if()

template<typename Ch , typename Parser , typename Convert >
fcppt::parse::convert_if< Ch, std::remove_cvref_t< Parser >, fcppt::either::success_type< std::invoke_result_t< Convert, fcppt::parse::position< Ch >, fcppt::parse::result_of< Parser > && > > > fcppt::parse::make_convert_if ( Parser && _parser,
Convert && _convert )

Creates an fcppt::parse::convert_if parser out of a lambda.

Parameters
_parserThe parser to convert from.
_convertThe lambda function to use as conversion. TODO(philipp): Can we get rid of the Ch parameter?

◆ make_failure()

template<typename Ch >
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::make_failure ( fcppt::parse::error< Ch > && _error)

Creates a skipper result from an fcppt::parse::error.

◆ make_fatal()

template<typename Parser >
fcppt::parse::fatal< std::remove_cvref_t< Parser > > fcppt::parse::make_fatal ( Parser && _parser)

Creates an fcppt::parse::fatal parser.

◆ make_ignore()

template<typename Parser >
fcppt::parse::ignore< std::remove_cvref_t< Parser > > fcppt::parse::make_ignore ( Parser && _parser)

Creates an fcppt::parse::ignore parser.

◆ make_lexeme()

template<typename Parser >
fcppt::parse::lexeme< std::remove_cvref_t< Parser > > fcppt::parse::make_lexeme ( Parser && _parser)

Creates an fcppt::parse::lexeme parser.

◆ make_literal()

template<typename Ch >
fcppt::parse::basic_literal< Ch > fcppt::parse::make_literal ( Ch const _ch)

Creates an fcppt::parse::basic_literal parser.

◆ make_parse_stream_success()

template<typename Ch , typename Success >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, std::remove_cvref_t< Success > > fcppt::parse::make_parse_stream_success ( Success && _success)
inline

Creates a success value with a parse_stream failure type.

The character type Ch of the error value has to be specified explicitly.

◆ make_parse_string_success()

template<typename Ch , typename Success >
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, std::remove_cvref_t< Success > > fcppt::parse::make_parse_string_success ( Success && _success)
inline

Creates a success value with a parse_string failure type.

The character type Ch of the error value has to be specified explicitly.

◆ make_recursive()

template<typename Parser >
fcppt::parse::recursive< std::remove_cvref_t< Parser > > fcppt::parse::make_recursive ( Parser && _parser)

Creates an fcppt::parse::recursive parser.

◆ make_success() [1/2]

template<typename Ch , typename Success >
fcppt::parse::result< Ch, std::remove_cvref_t< Success > > fcppt::parse::make_success ( Success && _success)
inline

Creates an fcppt::parse::result from a success value.

The character type Ch of the error value has to be specified explicitly.

◆ make_success() [2/2]

template<typename Ch >
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::make_success ( )

Creates a skipper success result.

◆ make_with_location()

template<typename Parser >
fcppt::parse::with_location< std::remove_cvref_t< Parser > > fcppt::parse::make_with_location ( Parser && _parser)

Creates an fcppt::parse::with_location parser.

◆ operator!() [1/2]

template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::not_< std::remove_cvref_t< Parser > > fcppt::parse::operator! ( Parser && _parser)
inline

Creates an fcppt::parse::not_ parser.

◆ operator!() [2/2]

template<typename Skipper >
requires (fcppt::parse::skipper::is_valid_argument<Skipper>::value)
fcppt::parse::skipper::not_< std::remove_cvref_t< Skipper > > fcppt::parse::skipper::operator! ( Skipper && _skipper)
inlinenodiscard

Creates an fcppt::parse::skipper::not_ skipper.

◆ operator*() [1/2]

template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::repetition< std::remove_cvref_t< Parser > > fcppt::parse::operator* ( Parser && _parser)
inline

Creates an fcppt::parse::repetition parser.

◆ operator*() [2/2]

template<typename Parser >
requires (fcppt::parse::skipper::is_valid_argument<Parser>::value)
fcppt::parse::skipper::repetition< std::remove_cvref_t< Parser > > fcppt::parse::skipper::operator* ( Parser && _parser)

◆ operator+()

template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::repetition_plus< std::remove_cvref_t< Parser > > fcppt::parse::operator+ ( Parser && _parser)
inline

Creates an fcppt::parse::repetition_plus parser.

◆ operator-() [1/2]

template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::exclude< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator- ( Left && _left,
Right && _right )
inline

Creates an fcppt::parse::exclude parser.

◆ operator-() [2/2]

template<typename Parser >
requires (fcppt::parse::is_valid_argument<Parser>::value)
fcppt::parse::optional< std::remove_cvref_t< Parser > > fcppt::parse::operator- ( Parser && _parser)
inline

Creates an fcppt::parse::optional parser.

◆ operator<<() [1/2]

template<typename Ch >
std::basic_ostream< Ch > & fcppt::parse::operator<< ( std::basic_ostream< Ch > & _stream,
fcppt::parse::position< Ch > const & _pos )

Outputs a position to a stream.

◆ operator<<() [2/2]

template<typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::parse::operator<< ( std::basic_ostream< Ch, Traits > & _stream,
fcppt::parse::location const & _loc )

Outputs a location to a stream.

◆ operator==()

template<typename Ch >
bool fcppt::parse::operator== ( fcppt::parse::position< Ch > const & _left,
fcppt::parse::position< Ch > const & _right )

Compares two positions for equality.

◆ operator>>() [1/2]

template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::sequence< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator>> ( Left && _left,
Right && _right )
inline

Creates an fcppt::parse::sequence parser.

◆ operator>>() [2/2]

template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::skipper::is_valid_argument<Left>, fcppt::parse::skipper::is_valid_argument<Right>>)
fcppt::parse::skipper::sequence< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::skipper::operator>> ( Left && _left,
Right && _right )

◆ operator|() [1/2]

template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::is_valid_argument<Left>, fcppt::parse::is_valid_argument<Right>>)
fcppt::parse::alternative< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::operator| ( Left && _left,
Right && _right )
inline

Creates an fcppt::parse::alternative parser.

◆ operator|() [2/2]

template<typename Left , typename Right >
requires (std::conjunction_v< fcppt::parse::skipper::is_valid_argument<Left>, fcppt::parse::skipper::is_valid_argument<Right>>)
fcppt::parse::skipper::alternative< std::remove_cvref_t< Left >, std::remove_cvref_t< Right > > fcppt::parse::skipper::operator| ( Left && _left,
Right && _right )
inline

◆ operator~()

template<typename Parser >
requires (fcppt::parse::detail::is_char_set<fcppt::parse::deref_type<Parser>>::value)
auto fcppt::parse::operator~ ( Parser && _parser)
inline

Creates an fcppt::parse::complement parser.

Template Parameters
ParserMust be an fcppt::parse::basic_char_set

◆ parse()

template<typename Ch , typename Parser >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse ( Parser const & _parser,
fcppt::parse::basic_stream< Ch > & _input )
inlinenodiscard

Parses without whitespace skipping.

Calls fcppt::parse::phrase_parse with fcppt::parse::skipper::epsilon.

◆ parse_stream()

template<typename Ch , typename Parser >
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse_stream ( Parser const & _parser,
std::basic_istream< Ch > & _input )
inlinenodiscard

Parses a std::basic_istream without whitespace skipping.

Calls fcppt::parse::phrase_parse_stream with fcppt::parse::skipper::epsilon.

◆ parse_string()

template<typename Ch , typename Parser >
fcppt::either:: object< fcppt::parse::parse_string_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::parse_string ( Parser const & _parser,
std::basic_string< Ch > && _string )
inlinenodiscard

Parses a std::basic_string without whitespace skipping.

Calls fcppt::parse::phrase_parse_string with fcppt::parse::skipper::epsilon.

◆ phrase_parse()

template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse ( Parser const & _parser,
fcppt::parse::basic_stream< Ch > & _input,
Skipper const & _skipper )
inlinenodiscard

The basic parse function.

First, the skipper _skipper is called. If this succeeds, then the result of parsing _input with _parser and _skipper is returned. This function also catches all exceptions produced by _input and returns them as an error.

◆ phrase_parse_stream()

template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_stream_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse_stream ( Parser const & _parser,
std::basic_istream< Ch > & _input,
Skipper const & _skipper )
nodiscard

Parses a std::basic_istream, using whitespace skipping.

See also
fcppt::parse::phrase_parse

◆ phrase_parse_string()

template<typename Ch , typename Parser , typename Skipper >
requires (std::conjunction_v< fcppt::parse::is_parser<Parser>, fcppt::parse::skipper::is_skipper<Skipper>>)
fcppt::either::object< fcppt::parse::parse_string_error< Ch >, fcppt::parse::result_of< Parser > > fcppt::parse::phrase_parse_string ( Parser const & _parser,
std::basic_string< Ch > && _string,
Skipper const & _skipper )
nodiscard

Parses a std::basic_string, using whitespace skipping.

See also
fcppt::parse::phrase_parse

◆ run()

template<typename Ch , typename Skipper >
requires (fcppt::parse::skipper::is_skipper_v<Skipper>)
fcppt::parse::skipper::result< Ch > fcppt::parse::skipper::run ( Skipper const & _skipper,
fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state )
nodiscard

Runs a skipper on a stream.

◆ set_position()

template<typename Ch >
void fcppt::parse::set_position ( fcppt::reference< fcppt::parse::basic_stream< Ch > > const _state,
fcppt::parse::position< Ch > const _pos )

Sets the current position of a stream.

◆ space() [1/2]

auto fcppt::parse::skipper::space ( )
inline

The skipper basic_space<char>.

◆ space() [2/2]

fcppt::parse::char_set fcppt::parse::space ( )
inline

The char set parser using fcppt::parse::space_set<char>.

◆ space_set()

template<typename Ch >
fcppt::parse::basic_char_set_container< Ch > fcppt::parse::space_set ( )
inline

The char set of spaces.Returns the set containing the whitespace, newline and tab characters.

Variable Documentation

◆ is_skipper_v

template<typename Type >
bool fcppt::parse::skipper::is_skipper_v = fcppt::parse::skipper::is_skipper<Type>::value
inlineconstexpr

Checks if a type is a skipper.

See also
fcppt::parse::skipper::is_skipper