RESTinio
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
restinio::easy_parser Namespace Reference

Namespaces

namespace  impl
 

Classes

class  digits_to_consume_t
 Limits for number of digits to be extracted during parsing of decimal numbers. More...
 
struct  nothing_t
 A special type to be used in the case where there is no need to store produced value. More...
 
class  parse_error_t
 Information about parsing error. More...
 
struct  result_value_wrapper
 A template with specializations for different kind of result values and for type nothing. More...
 
struct  result_value_wrapper< nothing_t >
 
struct  result_value_wrapper< std::array< T, S > >
 
struct  result_value_wrapper< std::basic_string< Char, Args... > >
 
struct  result_value_wrapper< std::map< K, V, Args... > >
 
struct  result_value_wrapper< std::vector< T, Args... > >
 
struct  result_wrapper_for
 A metafunction for detection of actual result_value_wrapper type for T. More...
 
struct  result_wrapper_for< impl::std_array_wrapper< T, S > >
 A specialization of result_wrapper_for metafunction for the case of std::array wrapper. More...
 

Typedefs

template<typename T >
using result_wrapper_for_t = typename result_wrapper_for<T>::type
 

Enumerations

enum class  error_reason_t {
  unexpected_character , unexpected_eof , no_appropriate_alternative , pattern_not_found ,
  unconsumed_input , illegal_value_found , force_only_this_alternative_failed
}
 Reason of parsing error. More...
 

Functions

constexpr digits_to_consume_t expected_digits (digits_to_consume_t::underlying_int_t total) noexcept
 Create a limit for number of digits to be extracted.
 
constexpr digits_to_consume_t expected_digits (digits_to_consume_t::underlying_int_t min, digits_to_consume_t::underlying_int_t max) noexcept
 Create a limit for number of digits to be extracted.
 
template<typename Target_Type , typename... Clauses>
auto produce (Clauses &&... clauses)
 A factory function to create a producer that creates an instance of the target type by using specified clauses.
 
template<typename... Clauses>
auto alternatives (Clauses &&... clauses)
 A factory function to create an alternatives clause.
 
template<typename... Clauses>
auto maybe (Clauses &&... clauses)
 A factory function to create an optional clause.
 
template<typename... Clauses>
auto not_clause (Clauses &&... clauses)
 A factory function to create a not_clause.
 
template<typename... Clauses>
auto and_clause (Clauses &&... clauses)
 A factory function to create an and_clause.
 
template<typename... Clauses>
auto sequence (Clauses &&... clauses)
 A factory function to create a sequence of subclauses.
 
template<typename... Clauses>
auto force_only_this_alternative (Clauses &&... clauses)
 An alternative that should be parsed correctly or the parsing of the whole alternatives clause should fail.
 
template<typename... Clauses>
auto repeat (std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
 A factory function to create repetitor of subclauses.
 
auto skip () noexcept
 A factory function to create a skip_consumer.
 
auto any_symbol_p () noexcept
 A factory function to create an any_symbol_producer.
 
auto symbol_p (char expected) noexcept
 A factory function to create a symbol_producer.
 
auto any_symbol_if_not_p (char sentinel) noexcept
 A factory function to create a any_symbol_if_not_producer.
 
auto caseless_symbol_p (char expected) noexcept
 A factory function to create a caseless_symbol_producer.
 
auto symbol_from_range_p (char left, char right) noexcept
 A factory function to create a symbol_from_range_producer.
 
auto symbol (char expected) noexcept
 A factory function to create a clause that expects the speficied symbol, extracts it and then skips it.
 
auto caseless_symbol (char expected) noexcept
 A factory function to create a clause that expects the speficied symbol, extracts it and then skips it.
 
auto symbol_from_range (char left, char right) noexcept
 A factory function to create a clause that expects a symbol from specified range, extracts it and then skips it.
 
auto space_p () noexcept
 A factory function to create a space_producer.
 
auto space () noexcept
 A factory function to create a clause that expects a space, extracts it and then skips it.
 
auto digit_p () noexcept
 A factory function to create a digit_producer.
 
auto digit () noexcept
 A factory function to create a clause that expects a decimal digit, extracts it and then skips it.
 
auto hexdigit_p () noexcept
 A factory function to create a hexdigit_producer.
 
auto hexdigit () noexcept
 A factory function to create a clause that expects a hexadecimal digit, extracts it and then skips it.
 
template<typename T >
auto non_negative_decimal_number_p () noexcept
 A factory function to create a non_negative_decimal_number_producer.
 
template<typename T >
auto non_negative_decimal_number_p (digits_to_consume_t digits_limit) noexcept
 A factory function to create a non_negative_decimal_number_producer.
 
template<typename T >
auto hexadecimal_number_p () noexcept
 A factory function to create a hexadecimal_number_producer.
 
template<typename T >
auto hexadecimal_number_p (digits_to_consume_t digits_limit) noexcept
 A factory function to create a hexadecimal_number_producer.
 
template<typename T >
auto decimal_number_p () noexcept
 A factory function to create a decimal_number_producer.
 
template<typename T >
auto decimal_number_p (digits_to_consume_t digits_limit) noexcept
 A factory function to create a decimal_number_producer.
 
auto as_result () noexcept
 A factory function to create a as_result_consumer.
 
template<typename F >
auto custom_consumer (F consumer)
 A factory function to create a custom_consumer.
 
auto to_container ()
 A factory function to create a to_container_consumer.
 
auto to_lower () noexcept
 A factory function to create a to_lower_transformer.
 
template<typename T >
auto just (T value) noexcept(noexcept(impl::just_value_transformer_t< T >{value}))
 A special transformer that replaces the produced value by a value specified by a user.
 
template<typename T >
auto just_result (T value) noexcept(noexcept(impl::just_result_consumer_t< T >{value}))
 A special consumer that replaces the produced value by a value specified by a user and sets that user-specified value as the result.
 
template<typename Converter >
auto convert (Converter &&converter)
 A factory function to create convert_transformer.
 
auto exact_p (string_view_t fragment)
 A factory function that creates an instance of exact_fragment_producer.
 
template<std::size_t Size>
auto exact_p (const char(&fragment)[Size])
 A factory function that creates an instance of exact_fragment_producer.
 
auto exact (string_view_t fragment)
 A factory function that creates an instance of exact_fragment clause.
 
template<std::size_t Size>
auto exact (const char(&fragment)[Size])
 A factory function that creates an instance of exact_fragment clause.
 
auto caseless_exact_p (string_view_t fragment)
 A factory function that creates an instance of caseless_exact_fragment_producer.
 
template<std::size_t Size>
auto caseless_exact_p (const char(&fragment)[Size])
 A factory function that creates an instance of caseless_exact_fragment_producer.
 
auto caseless_exact (string_view_t fragment)
 A factory function that creates an instance of caseless_exact_fragment clause.
 
template<std::size_t Size>
auto caseless_exact (const char(&fragment)[Size])
 A factory function that creates an instance of caseless_exact_fragment clause.
 
template<typename Producer >
expected_t< typename Producer::result_type, parse_error_ttry_parse (string_view_t from, Producer producer)
 Perform the parsing of the specified content by using specified value producer.
 
std::string make_error_description (const parse_error_t &error, string_view_t from)
 Make textual description of error returned by try_parse function.
 

Variables

constexpr std::size_t N = std::numeric_limits<std::size_t>::max()
 A special marker that means infinite repetitions.
 

Typedef Documentation

◆ result_wrapper_for_t

Definition at line 251 of file easy_parser.hpp.

Enumeration Type Documentation

◆ error_reason_t

Reason of parsing error.

Since
v.0.6.1
Enumerator
unexpected_character 

Unexpected character is found in the input.

unexpected_eof 

Unexpected end of input is encontered when some character expected.

no_appropriate_alternative 

None of alternatives was found in the input.

pattern_not_found 

Required pattern is not found in the input.

unconsumed_input 

There are some unconsumed non-whitespace characters in the input after the completion of parsing.

illegal_value_found 

Illegal value was found in the input.

Since
v.0.6.2
force_only_this_alternative_failed 

A failure of parsing an alternative marked as "force only this alternative".

This error code is intended for internal use for the implementation of alternatives() and force_only_this_alternative() stuff.

This error tells the parser that other alternatives should not be checked and the parsing of the whole alternatives clause should failed too.

Since
v.0.6.7

Definition at line 52 of file easy_parser.hpp.

Function Documentation

◆ alternatives()

template<typename... Clauses>
auto restinio::easy_parser::alternatives ( Clauses &&... clauses)

A factory function to create an alternatives clause.

Usage example:

sequence(symbol('v'), symbol('='), token_p() >> as_result()),
sequence(symbol('T'), symbol('/'), token_p() >> as_result())
)
);
auto symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
auto as_result() noexcept
A factory function to create a as_result_consumer.
auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
auto sequence(Clauses &&... clauses)
A factory function to create a sequence of subclauses.
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.

Please note the usage of sequence() inside the call to alternatives().

Template Parameters
Clausesthe list of clauses to be used as alternatives.
Since
v.0.6.1

Definition at line 3596 of file easy_parser.hpp.

◆ and_clause()

template<typename... Clauses>
auto restinio::easy_parser::and_clause ( Clauses &&... clauses)

A factory function to create an and_clause.

Usage example:

token_p() >> &std::pair<std::string, std::string>::first,
symbol(' '),
token_p() >> &std::pair<std::string, std::string>::second
and_clause(symbol(','), maybe(symbol(' ')), token_p() >> skip())
);
auto and_clause(Clauses &&... clauses)
A factory function to create an and_clause.
auto maybe(Clauses &&... clauses)
A factory function to create an optional clause.
auto skip() noexcept
A factory function to create a skip_consumer.

this expression corresponds the following rule:

T := token SP token &(',' [' '] token)
Template Parameters
Clausesthe list of clauses to be used as sequence to be checked.
Since
v.0.6.1

Definition at line 3719 of file easy_parser.hpp.

◆ any_symbol_if_not_p()

auto restinio::easy_parser::any_symbol_if_not_p ( char sentinel)
inlinenoexcept

A factory function to create a any_symbol_if_not_producer.

Returns
a producer that expects any character except sentinel in the input stream and returns it if that character is found.
Since
v.0.6.6

Definition at line 3974 of file easy_parser.hpp.

◆ any_symbol_p()

auto restinio::easy_parser::any_symbol_p ( )
inlinenoexcept

A factory function to create an any_symbol_producer.

Returns
a producer that expects any symbol in the input stream and returns it.
Since
v.0.6.6

Definition at line 3938 of file easy_parser.hpp.

◆ as_result()

auto restinio::easy_parser::as_result ( )
inlinenoexcept

A factory function to create a as_result_consumer.

Usage example:

symbol('v'),
symbol('='),
token_p() >> as_result(),
symbol('.')
);
Since
v.0.6.1

Definition at line 4451 of file easy_parser.hpp.

◆ caseless_exact() [1/2]

template<std::size_t Size>
auto restinio::easy_parser::caseless_exact ( const char(&) fragment[Size])

A factory function that creates an instance of caseless_exact_fragment clause.

Usage example:

produce<std::string>(caseless_exact("version="), token() >> as_result());
auto caseless_exact(string_view_t fragment)
A factory function that creates an instance of caseless_exact_fragment clause.
Attention
This version is dedicated to be used with string literals. Because of that the last byte from a literal will be ignored (it's assumed that this byte contains zero). But this behavior would lead to unexpected results in such cases:
const char prefix[]{ 'v', 'e', 'r', 's', 'i', 'o', 'n', '=' };
because the last byte with value '=' will be ignored by exact_producer. To avoid such behavior string_view_t should be used explicitely:
Since
v.0.6.9

Definition at line 4981 of file easy_parser.hpp.

◆ caseless_exact() [2/2]

auto restinio::easy_parser::caseless_exact ( string_view_t fragment)
inline

A factory function that creates an instance of caseless_exact_fragment clause.

Usage example:

produce<std::string>(caseless_exact("version="), token() >> as_result());
Since
v.0.6.9

Definition at line 4943 of file easy_parser.hpp.

◆ caseless_exact_p() [1/2]

template<std::size_t Size>
auto restinio::easy_parser::caseless_exact_p ( const char(&) fragment[Size])

A factory function that creates an instance of caseless_exact_fragment_producer.

Usage example:

caseless_exact_p("pro") >> just_result("Professional"),
caseless_exact_p("con") >> just_result("Consumer")
)
);
auto just_result(T value) noexcept(noexcept(impl::just_result_consumer_t< T >{value}))
A special consumer that replaces the produced value by a value specified by a user and sets that user...
auto caseless_exact_p(string_view_t fragment)
A factory function that creates an instance of caseless_exact_fragment_producer.
Attention
This version is dedicated to be used with string literals. Because of that the last byte from a literal will be ignored (it's assumed that this byte contains zero). But this behavior would lead to unexpected results in such cases:
const char prefix[]{ 'h', 'e', 'l', 'l', 'o' };
because the last byte with value 'o' will be ignored by exact_producer. To avoid such behavior string_view_t should be used explicitely:
Since
v.0.6.9

Definition at line 4922 of file easy_parser.hpp.

◆ caseless_exact_p() [2/2]

auto restinio::easy_parser::caseless_exact_p ( string_view_t fragment)
inline

A factory function that creates an instance of caseless_exact_fragment_producer.

Usage example:

caseless_exact_p("pro") >> just_result("Professional"),
caseless_exact_p("con") >> just_result("Consumer")
)
);
Since
v.0.6.9

Definition at line 4878 of file easy_parser.hpp.

◆ caseless_symbol()

auto restinio::easy_parser::caseless_symbol ( char expected)
inlinenoexcept

A factory function to create a clause that expects the speficied symbol, extracts it and then skips it.

This clause performs caseless comparison of characters.

The call to ‘caseless_symbol('a’)‘ function is an equivalent of:

caseless_symbol_p('a&rsquo;) >> skip()
auto caseless_symbol_p(char expected) noexcept
A factory function to create a caseless_symbol_producer.
Since
v.0.6.6

Definition at line 4056 of file easy_parser.hpp.

◆ caseless_symbol_p()

auto restinio::easy_parser::caseless_symbol_p ( char expected)
inlinenoexcept

A factory function to create a caseless_symbol_producer.

This producer performs caseless comparison of characters.

Returns
a producer that expects expected in the input stream and returns it if that character is found.
Since
v.0.6.6

Definition at line 3994 of file easy_parser.hpp.

◆ convert()

template<typename Converter >
auto restinio::easy_parser::convert ( Converter && converter)

A factory function to create convert_transformer.

Usage example:

// Parser for:
// size := DIGIT+ [multiplier]
// multiplier := ('b'|'B') | ('k'|'K') | ('m'|'M')
struct tmp_size { std::uint32_t c_{1u}; std::uint32_t m_{1u}; };
caseless_symbol_p('m') >> just_result(1024u*1024u)
)
) >> &tmp_size::m_
)
)
>> convert( [](const tmp_size & ts) { return std::uint64_t{ts.c_} * ts.m_; } )
>> as_result()
);
auto convert(Converter &&converter)
A factory function to create convert_transformer.
Note
Since v.0.6.11 a conversion function can have two formats. The first one is:
result_type fn(input_type source_val);
for example:
convert([](const std::string & from) -> int {...})
in that case a conversion error can only be reported via an exception. The second one is:
nonstd::expected< T, E > expected_t
Definition expected.hpp:18
for example:
convert([](const std::string & from) -> expected_t<int, error_reason_t> {...})
in that case a converion error can be reported also via returning value. For example, let's assume that in the code snippet shown above the result value should be greater than 0. It can be checked in the conversion function that way:
const auto r = std::uint64_t{ts.c_} * ts.m_;
if( r )
return r;
else
return make_unexpected(error_reason_t::illegal_value_found);
}
@ illegal_value_found
Illegal value was found in the input.
Since
v.0.6.6

Definition at line 4718 of file easy_parser.hpp.

◆ custom_consumer()

template<typename F >
auto restinio::easy_parser::custom_consumer ( F consumer)

A factory function to create a custom_consumer.

Usage example:

std::string name_;
std::string value_;
public:
composed_value() = default;
void set_name(std::string name) { name_ = std::move(name); }
void set_value(std::string value) { value_ = std::move(value); }
...
};
[](composed_value & to, std::string && what) {
to.set_name(std::move(what));
} ),
symbol('='),
[](composed_value & to, std::string && what) {
to.set_value(std::move(what));
} ),
symbol('.')
);
auto custom_consumer(F consumer)
A factory function to create a custom_consumer.
auto token_p() noexcept
A factory function to create a token_producer.
Definition basics.hpp:987
Note
A custom consumer should be a function/lambda/function objects with the following prototype:
Since
v.0.6.1

Definition at line 4497 of file easy_parser.hpp.

◆ decimal_number_p() [1/2]

template<typename T >
auto restinio::easy_parser::decimal_number_p ( )
inlinenoexcept

A factory function to create a decimal_number_producer.

Parses numbers in the form:

number := [sign] DIGIT+
sign   := '-' | '+'
Note
This parser consumes all digits until the first non-digit symbol will be found in the input. It means that in the case of -1111someword the leading minus sign and thefirst four digits (e.g. -1111) will be extracted from the input and the remaining part (e.g. someword) won't be consumed by this parser.
Attention
Can be used only for singed number types (e.g. short, int, long, std::int32_t and so on).
Returns
a producer that expects a decimal number in the input stream and returns it if a number is found.
Since
v.0.6.6

Definition at line 4368 of file easy_parser.hpp.

◆ decimal_number_p() [2/2]

template<typename T >
auto restinio::easy_parser::decimal_number_p ( digits_to_consume_t digits_limit)
inlinenoexcept

A factory function to create a decimal_number_producer.

Parses numbers in the form:

number := [sign] DIGIT+
sign   := '-' | '+'
Note
This parser consumes a number of digits with respect to digits_limit. The leading sign (if present) is not added to a number of extracted digits.

Usage example:

using namespace restinio::easy_parser;
short prefix_;
int suffix_;
};
>> &compound_number::prefix_,
>> &compound_number::suffix_
);
constexpr digits_to_consume_t expected_digits(digits_to_consume_t::underlying_int_t total) noexcept
Create a limit for number of digits to be extracted.
Attention
Can be used only for singed number types (e.g. short, int, long, std::int32_t and so on).
Returns
a producer that expects a decimal number in the input stream and returns it if a number is found.
Since
v.0.6.6

Definition at line 4421 of file easy_parser.hpp.

◆ digit()

auto restinio::easy_parser::digit ( )
inlinenoexcept

A factory function to create a clause that expects a decimal digit, extracts it and then skips it.

The call to digit() function is an equivalent of:

digit_p() >> skip()
auto digit_p() noexcept
A factory function to create a digit_producer.
Since
v.0.6.6

Definition at line 4155 of file easy_parser.hpp.

◆ digit_p()

auto restinio::easy_parser::digit_p ( )
inlinenoexcept

A factory function to create a digit_producer.

Returns
a producer that expects a decimal digit in the input stream and returns it if a decimal digit is found.
Since
v.0.6.1

Definition at line 4134 of file easy_parser.hpp.

◆ exact() [1/2]

template<std::size_t Size>
auto restinio::easy_parser::exact ( const char(&) fragment[Size])

A factory function that creates an instance of exact_fragment clause.

Usage example:

produce<std::string>(exact("version="), token() >> as_result());
auto exact(string_view_t fragment)
A factory function that creates an instance of exact_fragment clause.
Attention
This version is dedicated to be used with string literals. Because of that the last byte from a literal will be ignored (it's assumed that this byte contains zero). But this behavior would lead to unexpected results in such cases:
const char prefix[]{ 'v', 'e', 'r', 's', 'i', 'o', 'n', '=' };
because the last byte with value '=' will be ignored by exact_producer. To avoid such behavior string_view_t should be used explicitely:
Since
v.0.6.6

Definition at line 4852 of file easy_parser.hpp.

◆ exact() [2/2]

auto restinio::easy_parser::exact ( string_view_t fragment)
inline

A factory function that creates an instance of exact_fragment clause.

Usage example:

produce<std::string>(exact("version="), token() >> as_result());
Since
v.0.6.6

Definition at line 4814 of file easy_parser.hpp.

◆ exact_p() [1/2]

template<std::size_t Size>
auto restinio::easy_parser::exact_p ( const char(&) fragment[Size])

A factory function that creates an instance of exact_fragment_producer.

Usage example:

exact_p("pro") >> just_result("Professional"),
exact_p("con") >> just_result("Consumer")
)
);
auto exact_p(string_view_t fragment)
A factory function that creates an instance of exact_fragment_producer.
Attention
This version is dedicated to be used with string literals. Because of that the last byte from a literal will be ignored (it's assumed that this byte contains zero). But this behavior would lead to unexpected results in such cases:
const char prefix[]{ 'h', 'e', 'l', 'l', 'o' };
because the last byte with value 'o' will be ignored by exact_producer. To avoid such behavior string_view_t should be used explicitely:
Since
v.0.6.6

Definition at line 4793 of file easy_parser.hpp.

◆ exact_p() [2/2]

auto restinio::easy_parser::exact_p ( string_view_t fragment)
inline

A factory function that creates an instance of exact_fragment_producer.

Usage example:

exact_p("pro") >> just_result("Professional"),
exact_p("con") >> just_result("Consumer")
)
);
Since
v.0.6.6

Definition at line 4749 of file easy_parser.hpp.

◆ expected_digits() [1/2]

constexpr digits_to_consume_t restinio::easy_parser::expected_digits ( digits_to_consume_t::underlying_int_t min,
digits_to_consume_t::underlying_int_t max )
inlineconstexprnoexcept

Create a limit for number of digits to be extracted.

Makes a limit where min and max are specified separately.

Usage example:

Since
v.0.6.6

Definition at line 571 of file easy_parser.hpp.

◆ expected_digits() [2/2]

constexpr digits_to_consume_t restinio::easy_parser::expected_digits ( digits_to_consume_t::underlying_int_t total)
inlineconstexprnoexcept

Create a limit for number of digits to be extracted.

Makes a limit where min==max and both are equal to total.

Usage example:

Since
v.0.6.6

Definition at line 550 of file easy_parser.hpp.

◆ force_only_this_alternative()

template<typename... Clauses>
auto restinio::easy_parser::force_only_this_alternative ( Clauses &&... clauses)

An alternative that should be parsed correctly or the parsing of the whole alternatives clause should fail.

This special clause is intended to be used to avoid mistakes in grammars like that:

v = "key" '=' token
  | token '=' 1*VCHAR

If that grammar will be used for parsing a sentence like "key=123" then the second alternative will be selected. It's because the parsing of rule "key" '=' token fails at 123 and the second alternative will be tried. And "key" will be recognized as a token.

Before v.0.6.7 this mistake can be avoided by using rules like those:

v = "key" '=' token
  | !"key" token '=' 1*VCHAR

Since v.0.6.7 this mistake can be avoided by using force_only_this_alternative() function:

exact("key"),
symbol('='),
token() >> skip()
)
),
token() >> skip(),
symbol('='),
repeat(1, N, vchar_symbol_p() >> skip())
)
);
auto force_only_this_alternative(Clauses &&... clauses)
An alternative that should be parsed correctly or the parsing of the whole alternatives clause should...
constexpr std::size_t N
A special marker that means infinite repetitions.
auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
Since
v.0.6.7

Definition at line 3822 of file easy_parser.hpp.

◆ hexadecimal_number_p() [1/2]

template<typename T >
auto restinio::easy_parser::hexadecimal_number_p ( )
inlinenoexcept

A factory function to create a hexadecimal_number_producer.

Note
This parser consumes all digits until the first non-digit symbol will be found in the input. It means that in the case of 1111someword the first four digits (e.g. 1111) will be extracted from the input and the remaining part (e.g. someword) won't be consumed by this parser.
Attention
T should be an unsigned type.
Returns
a producer that expects a positive hexadecimal number in the input stream and returns it if a number is found.
Since
v.0.6.6

Definition at line 4288 of file easy_parser.hpp.

◆ hexadecimal_number_p() [2/2]

template<typename T >
auto restinio::easy_parser::hexadecimal_number_p ( digits_to_consume_t digits_limit)
inlinenoexcept

A factory function to create a hexadecimal_number_producer.

Note
This parser consumes a number of digits with respect to digits_limit.

Usage example:

using namespace restinio::easy_parser;
short prefix_;
int suffix_;
};
>> &compound_number::prefix_,
>> &compound_number::suffix_
);
Attention
T should be an unsigned type.
Returns
a producer that expects a positive hexadecimal number in the input stream and returns it if a number is found.
Since
v.0.6.6

Definition at line 4330 of file easy_parser.hpp.

◆ hexdigit()

auto restinio::easy_parser::hexdigit ( )
inlinenoexcept

A factory function to create a clause that expects a hexadecimal digit, extracts it and then skips it.

The call to hexdigit() function is an equivalent of:

auto hexdigit_p() noexcept
A factory function to create a hexdigit_producer.
Since
v.0.6.6

Definition at line 4194 of file easy_parser.hpp.

◆ hexdigit_p()

auto restinio::easy_parser::hexdigit_p ( )
inlinenoexcept

A factory function to create a hexdigit_producer.

Returns
a producer that expects a hexadecimal digit in the input stream and returns it if a hexadecimal digit is found.
Since
v.0.6.6

Definition at line 4173 of file easy_parser.hpp.

◆ just()

template<typename T >
auto restinio::easy_parser::just ( T value)
noexcept

A special transformer that replaces the produced value by a value specified by a user.

Usage example:

symbol('b') >> just(1u) >> as_result(),
symbol('k') >> just(1024u) >> as_result(),
symbol('m') >> just(1024u*1024u) >> as_result()
)
);
auto just(T value) noexcept(noexcept(impl::just_value_transformer_t< T >{value}))
A special transformer that replaces the produced value by a value specified by a user.
Since
v.0.6.6

Definition at line 4616 of file easy_parser.hpp.

◆ just_result()

template<typename T >
auto restinio::easy_parser::just_result ( T value)
noexcept

A special consumer that replaces the produced value by a value specified by a user and sets that user-specified value as the result.

Usage example:

symbol('b') >> just_result(1u),
symbol('k') >> just_result(1024u),
symbol('m') >> just_result(1024u*1024u)
)
);
Since
v.0.6.6

Definition at line 4645 of file easy_parser.hpp.

◆ make_error_description()

std::string restinio::easy_parser::make_error_description ( const parse_error_t & error,
string_view_t from )
inline

Make textual description of error returned by try_parse function.

Note
The format of textual description is not specified and can be changed in some future versions without notice.

Usage example:

const char * content = "first,Second;Third;Four";
const auto tokens = try_parse(
produce<std::vector<std::string>>(
token_p() >> to_lower() >> to_container(),
repeat( 0, N,
alternatives(symbol(','), symbol(';')),
token_p() >> to_lower() >> to_container()
)
)
);
if(tokens)
{
for(const auto & v: *tokens)
std::cout << v << std::endl;
}
else
std::cerr << make_error_description(tokens.error(), content) << std::endl;
auto to_container()
A factory function to create a to_container_consumer.
expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
std::string make_error_description(const parse_error_t &error, string_view_t from)
Make textual description of error returned by try_parse function.
auto to_lower() noexcept
A factory function to create a to_lower_transformer.
auto produce(Clauses &&... clauses)
A factory function to create a producer that creates an instance of the target type by using specifie...
Since
v.0.6.1

Definition at line 5084 of file easy_parser.hpp.

◆ maybe()

template<typename... Clauses>
auto restinio::easy_parser::maybe ( Clauses &&... clauses)

A factory function to create an optional clause.

Usage example:

token_p() >> &std::pair<std::string, std::string>::first,
symbol('='),
token_p() >> &std::pair<std::string, std::string>::second
)
);
Template Parameters
Clausesthe list of clauses to be used as optional sequence.
Since
v.0.6.1

Definition at line 3635 of file easy_parser.hpp.

◆ non_negative_decimal_number_p() [1/2]

template<typename T >
auto restinio::easy_parser::non_negative_decimal_number_p ( )
inlinenoexcept

A factory function to create a non_negative_decimal_number_producer.

Note
This parser consumes all digits until the first non-digit symbol will be found in the input. It means that in the case of 1111someword the first four digits (e.g. 1111) will be extracted from the input and the remaining part (e.g. someword) won't be consumed by this parser.
Returns
a producer that expects a positive decimal number in the input stream and returns it if a number is found.
Since
v.0.6.2

Definition at line 4219 of file easy_parser.hpp.

◆ non_negative_decimal_number_p() [2/2]

template<typename T >
auto restinio::easy_parser::non_negative_decimal_number_p ( digits_to_consume_t digits_limit)
inlinenoexcept

A factory function to create a non_negative_decimal_number_producer.

Note
This parser consumes a number of digits with respect to digits_limit.

Usage example:

using namespace restinio::easy_parser;
short prefix_;
int suffix_;
};
>> &compound_number::prefix_,
>> &compound_number::suffix_
);
Returns
a producer that expects a positive decimal number in the input stream and returns it if a number is found.
Since
v.0.6.2

Definition at line 4258 of file easy_parser.hpp.

◆ not_clause()

template<typename... Clauses>
auto restinio::easy_parser::not_clause ( Clauses &&... clauses)

A factory function to create a not_clause.

Usage example:

token_p() >> &std::pair<std::string, std::string>::first,
symbol(' '),
token_p() >> &std::pair<std::string, std::string>::second
);
auto not_clause(Clauses &&... clauses)
A factory function to create a not_clause.

this expression corresponds the following rule:

T := token SP token !'.'
Template Parameters
Clausesthe list of clauses to be used as sequence to be checked.
Since
v.0.6.1

Definition at line 3677 of file easy_parser.hpp.

◆ produce()

template<typename Target_Type , typename... Clauses>
auto restinio::easy_parser::produce ( Clauses &&... clauses)

A factory function to create a producer that creates an instance of the target type by using specified clauses.

Usage example:

produce<std::string>(symbol('v'), symbol('='), token_p() >> as_result());
Template Parameters
Target_Typethe type of value to be produced.
Clausesthe list of clauses to be used for a new value.
Since
v.0.6.1

Definition at line 3555 of file easy_parser.hpp.

◆ repeat()

template<typename... Clauses>
auto restinio::easy_parser::repeat ( std::size_t min_occurences,
std::size_t max_occurences,
Clauses &&... clauses )

A factory function to create repetitor of subclauses.

Usage example:

using str_pair = std::pair<std::string, std::string>;
token_p() >> &str_pair::first,
symbol('='),
token_p() >> &str_pair::second
) >> to_container(),
repeat(0, N,
symbol(','),
token_p() >> &str_pair::first,
symbol('='),
token_p() >> &str_pair::second
) >> to_container()
)
);

this expression corresponds to the following rule:

 T := token '=' token *(',' token '=' token)
Template Parameters
Clausesthe list of clauses to be used as the sequence to be repeated.
Since
v.0.6.1
Parameters
min_occurencesMinimal occurences of the sequences in the repetition.
max_occurencesMaximal occurences of the sequences in the repetition.
Note
The repetition will be stopped when that numer of repetitions will be reached.
Parameters
clausesThe sequence of clauses to be repeated.

Definition at line 3877 of file easy_parser.hpp.

◆ sequence()

template<typename... Clauses>
auto restinio::easy_parser::sequence ( Clauses &&... clauses)

A factory function to create a sequence of subclauses.

Usage example:

sequence(symbol('v'), symbol('='), token_p() >> as_result()),
sequence(symbol('T'), symbol('/'), token_p() >> as_result())
)
);

Please note the usage of sequence() inside the call to alternatives().

Template Parameters
Clausesthe list of clauses to be used as the sequence.
Since
v.0.6.1

Definition at line 3759 of file easy_parser.hpp.

◆ skip()

auto restinio::easy_parser::skip ( )
inlinenoexcept

A factory function to create a skip_consumer.

Usage example:

token_p() >> as_result(),
not_clause(symbol('='), token_p() >> skip())
);
Since
v.0.6.1

Definition at line 3923 of file easy_parser.hpp.

◆ space()

auto restinio::easy_parser::space ( )
inlinenoexcept

A factory function to create a clause that expects a space, extracts it and then skips it.

The call to space() function is an equivalent of:

space_p() >> skip()
auto space_p() noexcept
A factory function to create a space_producer.
Since
v.0.6.4

Definition at line 4116 of file easy_parser.hpp.

◆ space_p()

auto restinio::easy_parser::space_p ( )
inlinenoexcept

A factory function to create a space_producer.

Returns
a producer that expects space character in the input stream and returns it if that character is found.
Since
v.0.6.4

Definition at line 4095 of file easy_parser.hpp.

◆ symbol()

auto restinio::easy_parser::symbol ( char expected)
inlinenoexcept

A factory function to create a clause that expects the speficied symbol, extracts it and then skips it.

The call to ‘symbol('a’)‘ function is an equivalent of:

symbol_p('a&rsquo;) >> skip()
auto symbol_p(char expected) noexcept
A factory function to create a symbol_producer.
Since
v.0.6.1

Definition at line 4033 of file easy_parser.hpp.

◆ symbol_from_range()

auto restinio::easy_parser::symbol_from_range ( char left,
char right )
inlinenoexcept

A factory function to create a clause that expects a symbol from specified range, extracts it and then skips it.

The call to ‘symbol_from_range('a’, 'z')‘ function is an equivalent of:

symbol_from_range_p('a&rsquo;, 'z') >> skip()
auto symbol_from_range_p(char left, char right) noexcept
A factory function to create a symbol_from_range_producer.
Since
v.0.6.9

Definition at line 4077 of file easy_parser.hpp.

◆ symbol_from_range_p()

auto restinio::easy_parser::symbol_from_range_p ( char left,
char right )
inlinenoexcept

A factory function to create a symbol_from_range_producer.

Returns
a producer that expects a symbol from [left, right] range in the input stream and returns it if that character is found.
Since
v.0.6.9

Definition at line 4012 of file easy_parser.hpp.

◆ symbol_p()

auto restinio::easy_parser::symbol_p ( char expected)
inlinenoexcept

A factory function to create a symbol_producer.

Returns
a producer that expects expected in the input stream and returns it if that character is found.
Since
v.0.6.1

Definition at line 3956 of file easy_parser.hpp.

◆ to_container()

auto restinio::easy_parser::to_container ( )
inline

A factory function to create a to_container_consumer.

Usage example:

using str_pair = std::pair<std::string, std::string>;
token_p() >> &str_pair::first,
symbol('='),
token_p() >> &str_pair::second
) >> to_container(),
repeat(0, N,
symbol(','),
token_p() >> &str_pair::first,
symbol('='),
token_p() >> &str_pair::second
) >> to_container()
)
);
Since
v.0.6.1

Definition at line 4564 of file easy_parser.hpp.

◆ to_lower()

auto restinio::easy_parser::to_lower ( )
inlinenoexcept

A factory function to create a to_lower_transformer.

Usage example:

symbol('T'), symbol(':'),
token_p() >> to_lower() >> as_result()
);
...
// Since v.0.6.6 to_lower can also be used for a single character.
produce<char>(
exact("I="), any_symbol_p() >> to_lower() >> as_result() );
auto any_symbol_p() noexcept
A factory function to create an any_symbol_producer.
Since
v.0.6.1

Definition at line 4591 of file easy_parser.hpp.

◆ try_parse()

template<typename Producer >
expected_t< typename Producer::result_type, parse_error_t > restinio::easy_parser::try_parse ( string_view_t from,
Producer producer )

Perform the parsing of the specified content by using specified value producer.

Note
The whole content of from should be consumed. There can be whitespace remaining in @from after the return from Producer::try_parser. But if there will be some non-whitespace symbol the failure will be reported. (As a side note: since v.0.6.7 all trailing spaces are removed from @from before the parsing starts.)

Usage example

const auto tokens = try_parse(
"first,Second;Third;Four",
produce<std::vector<std::string>>(
token_p() >> to_lower() >> to_container(),
repeat( 0, N,
alternatives(symbol(','), symbol(';')),
token_p() >> to_lower() >> to_container()
)
)
);
if(tokens)
for(const auto & v: *tokens)
std::cout << v << std::endl;
Since
v.0.6.1

Definition at line 5023 of file easy_parser.hpp.

Variable Documentation

◆ N

constexpr std::size_t restinio::easy_parser::N = std::numeric_limits<std::size_t>::max()
constexpr

A special marker that means infinite repetitions.

Since
v.0.6.1

Definition at line 456 of file easy_parser.hpp.