4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt::parse::list< Start, Inner, Sep, End > Class Template Reference

Detailed Description

template<typename Start, typename Inner, typename Sep, typename End>
class fcppt::parse::list< Start, Inner, Sep, End >

Parses lists, e.g., [a_1,...,a_n].

A list parser consists of a start parser Start, an end parser End, a separator parser Sep and an inner parser Inner. The purpose of this parser is to parse lists like [a_1,...,a_n], where Start recognizes '[', End recognizes ']', Sep recognizes ',' and Inner recognizes the a_i, producing the results r_1, ..., r_n. The result of the list parser is then vector{r_1,...,r_n}.

This is implemented as follows: The start parser is tried first and parses the beginning of the list. Then, the end parser is tried, which parses the end of the list. If this succeeds, the list is empty and the result is the empty vector. Otherwise, the list is nonempty and the inner parser is tried. If this succeeds, this provides the first element r_1 of the result. Then, the separator parser is tried, followed by the inner parser. This is done as long as possible, giving the remaining elements r_2, ..., r_n of the result, which are again taken from the inner parser. Lastly, the end parser is tried and if it succeeds, the result is vector{r_1,...,r_n}.

Equivalent to:

Start >> (End | (fcppt::parse::separator{Inner,Sep} >> End))
Template Parameters
StartA parser with result type unit.
EndA parser with result type unit.
SepA parser with result type unit.
Inheritance diagram for fcppt::parse::list< Start, Inner, Sep, End >:
fcppt::parse::tag

Public Types

using result_type = std::vector<fcppt::parse::result_of<Inner>>
 

Public Member Functions

 list (Start &&, Inner &&, Sep &&, End &&)
 
template<typename Ch , typename Skipper >
fcppt::parse::result< Ch, result_typeparse (fcppt::reference< fcppt::parse::basic_stream< Ch > >, Skipper const &) const
 

Member Typedef Documentation

◆ result_type

template<typename Start , typename Inner , typename Sep , typename End >
using fcppt::parse::list< Start, Inner, Sep, End >::result_type = std::vector<fcppt::parse::result_of<Inner>>

Constructor & Destructor Documentation

◆ list()

template<typename Start , typename Inner , typename Sep , typename End >
fcppt::parse::list< Start, Inner, Sep, End >::list ( Start && ,
Inner && ,
Sep && ,
End &&  )

Member Function Documentation

◆ parse()

template<typename Start , typename Inner , typename Sep , typename End >
template<typename Ch , typename Skipper >
fcppt::parse::result< Ch, result_type > fcppt::parse::list< Start, Inner, Sep, End >::parse ( fcppt::reference< fcppt::parse::basic_stream< Ch > > ,
Skipper const &  ) const
nodiscard