Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
Syntax< PAR > Class Template Reference

#include "lib/parse.hpp"

Description

template<class PAR>
class util::parse::Syntax< PAR >

A Syntax clause with a parser and result state.

An instance of this class embodies a (possibly complex) expected syntactical structure; the parse function analyses a given input text for compliance with this expected structure. After the parse, result state has been set

  • indicating if the parse was successful
  • possibly with an failure message (TODO 1/25)
  • the number of characters covered by this match
  • a Result Model, as a structured term holding result components from each part / sub-clause

Definition at line 782 of file parse.hpp.

Public Types

using Connex = PAR::Connex
 
using Result = PAR::Result
 
- Public Types inherited from Eval< PAR::Result >
using Result = PAR::Result
 

Public Member Functions

 Syntax ()
 
 Syntax (PAR &&parser)
 
 operator bool () const
 
 operator Connex & ()
 
 operator Connex const & () const
 
bool success () const
 
bool hasResult () const
 
bool canInvoke () const
 
size_t consumed () const
 
ResultgetResult ()
 
Result && extractResult ()
 
Syntax && parse (StrView toParse)
 Core API : parse against this syntax clause.
 
template<class PX >
Syntaxoperator= (Syntax< PX > refSyntax)
 
template<typename SPEC >
auto seq (SPEC &&clauseDef)
 ===== Syntax clause builder DSL =====
 
template<typename SPEC >
auto alt (SPEC &&clauseDef)
 Combinator: extend this Syntax by adding an alternative branch.
 
template<typename SPEC >
auto opt (SPEC &&clauseDef)
 Combinator: extend this Syntax with a further sequenced sub-clause, which however is only optional and the match succeed without it.
 
template<typename SPEC1 , typename SPEC2 >
auto repeat (uint min, uint max, SPEC1 &&delimDef, SPEC2 &&clauseDef)
 Combinator: extend this Syntax with a further sequenced sub-clause, which in this case accepts a repeated sequence, with delimiter.
 
template<typename SPEC1 , typename SPEC2 >
auto repeat (uint cnt, SPEC1 &&delimDef, SPEC2 &&clauseDef)
 
template<typename SPEC1 , typename SPEC2 >
auto repeat (SPEC1 &&delimDef, SPEC2 &&clauseDef)
 
template<typename SPEC >
auto repeat (SPEC &&clauseDef)
 
template<typename SPEC1 , typename SPEC2 , typename SPEC3 >
auto bracket (SPEC1 &&openDef, SPEC2 &&closeDef, SPEC3 &&bodyDef)
 Combinator: extend this Syntax with a further sequenced sub-clause in brackets.
 
template<typename SPEC >
auto bracket (string bracketSpec, SPEC &&bodyDef)
 
template<typename SPEC >
auto bracket (SPEC &&bodyDef)
 
template<typename SPEC >
auto bracketOpt (string bracketSpec, SPEC &&bodyDef)
 
template<typename SPEC >
auto bracketOpt (SPEC &&bodyDef)
 
template<class FUN >
auto bind (FUN &&modelAdapt)
 
auto bindMatch (uint group=0)
 

Private Member Functions

Eval< Result > & eval ()
 

Private Attributes

PAR parse_
 

Additional Inherited Members

- Public Attributes inherited from Eval< PAR::Result >
optional< PAR::Result > result
 
size_t consumed
 

Constructor & Destructor Documentation

◆ Syntax() [1/2]

template<class PAR >
Syntax ( )
inline

Definition at line 791 of file parse.hpp.

◆ Syntax() [2/2]

template<class PAR >
Syntax ( PAR &&  parser)
inlineexplicit

Definition at line 796 of file parse.hpp.

Member Typedef Documentation

◆ Connex

template<class PAR >
using Connex = PAR::Connex

Definition at line 788 of file parse.hpp.

◆ Result

template<class PAR >
using Result = PAR::Result

Definition at line 789 of file parse.hpp.

Member Function Documentation

◆ operator bool()

template<class PAR >
operator bool ( ) const
inlineexplicit

Definition at line 801 of file parse.hpp.

References Syntax< PAR >::success().

+ Here is the call graph for this function:

◆ operator Connex &()

template<class PAR >
operator Connex & ( )
inline

Definition at line 803 of file parse.hpp.

References Syntax< PAR >::parse_.

◆ operator Connex const &()

template<class PAR >
operator Connex const & ( ) const
inline

Definition at line 804 of file parse.hpp.

References Syntax< PAR >::parse_.

◆ success()

template<class PAR >
bool success ( ) const
inline

Definition at line 806 of file parse.hpp.

Referenced by Syntax< PAR >::operator bool().

+ Here is the caller graph for this function:

◆ hasResult()

template<class PAR >
bool hasResult ( ) const
inline

Definition at line 807 of file parse.hpp.

◆ canInvoke()

template<class PAR >
bool canInvoke ( ) const
inline

Definition at line 808 of file parse.hpp.

References Syntax< PAR >::parse_.

◆ consumed()

template<class PAR >
size_t consumed ( ) const
inline

Definition at line 809 of file parse.hpp.

◆ getResult()

template<class PAR >
Result & getResult ( )
inline

Definition at line 810 of file parse.hpp.

Referenced by Syntax< PAR >::extractResult().

+ Here is the caller graph for this function:

◆ extractResult()

template<class PAR >
Result && extractResult ( )
inline

Definition at line 811 of file parse.hpp.

References Syntax< PAR >::getResult().

+ Here is the call graph for this function:

◆ parse()

template<class PAR >
Syntax && parse ( StrView  toParse)
inline

Core API : parse against this syntax clause.

Definition at line 818 of file parse.hpp.

References Syntax< PAR >::eval(), and Syntax< PAR >::parse_.

Referenced by util::parse::buildConnex(), and Syntax< PAR >::operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

template<class PAR >
template<class PX >
Syntax & operator= ( Syntax< PX >  refSyntax)
inline

Definition at line 827 of file parse.hpp.

References Syntax< PAR >::parse(), and Syntax< PAR >::parse_.

+ Here is the call graph for this function:

◆ seq()

template<class PAR >
template<typename SPEC >
auto seq ( SPEC &&  clauseDef)
inline

===== Syntax clause builder DSL =====

Combinator: extend this Syntax clause by expecting a further sub-clause behind the part of the input matched by the already defined part of this Syntax.

The result model will be a SeqModel, which essentially is a tuple of the result models of all sequenced parts.

Returns
Syntax clause instance accepting the extended structure.
Warning
the old syntax is invalidated by moving the parse-function out.

Definition at line 1074 of file parse.hpp.

References util::parse::accept(), and util::parse::sequenceConnex().

+ Here is the call graph for this function:

◆ alt()

template<class PAR >
template<typename SPEC >
auto alt ( SPEC &&  clauseDef)
inline

Combinator: extend this Syntax by adding an alternative branch.

So either the already defined part of this Syntax matches the input, or the alternative clause is probed from the start of the input. At least one branch must match for the parse to be successful; however, further branches are not tested after finding a matching branch (short-circuit). The result model is a Sum Type, implemented as a custom variant record of type SubModel. It provides a branch selector field to detect which branch of the syntax did match. And it allows to retrieve the result model of this successful branch — which however requires that the invoking code precisely knows the model type to expect.

Definition at line 1096 of file parse.hpp.

References util::parse::accept(), and util::parse::branchedConnex().

+ Here is the call graph for this function:

◆ opt()

template<class PAR >
template<typename SPEC >
auto opt ( SPEC &&  clauseDef)
inline

Combinator: extend this Syntax with a further sequenced sub-clause, which however is only optional and the match succeed without it.

The result model is (as always for seq ) a tuple; the result from the optional part is packaged into a std::optional.

Definition at line 1112 of file parse.hpp.

References util::parse::accept_opt().

+ Here is the call graph for this function:

◆ repeat() [1/4]

template<class PAR >
template<typename SPEC1 , typename SPEC2 >
auto repeat ( uint  min,
uint  max,
SPEC1 &&  delimDef,
SPEC2 &&  clauseDef 
)
inline

Combinator: extend this Syntax with a further sequenced sub-clause, which in this case accepts a repeated sequence, with delimiter.

See also
accept_sequenced()

Definition at line 1125 of file parse.hpp.

References util::parse::accept_repeated(), util::max(), and util::min().

+ Here is the call graph for this function:

◆ repeat() [2/4]

template<class PAR >
template<typename SPEC1 , typename SPEC2 >
auto repeat ( uint  cnt,
SPEC1 &&  delimDef,
SPEC2 &&  clauseDef 
)
inline

Definition at line 1135 of file parse.hpp.

References util::parse::accept_repeated().

+ Here is the call graph for this function:

◆ repeat() [3/4]

template<class PAR >
template<typename SPEC1 , typename SPEC2 >
auto repeat ( SPEC1 &&  delimDef,
SPEC2 &&  clauseDef 
)
inline

Definition at line 1145 of file parse.hpp.

References util::parse::accept_repeated().

+ Here is the call graph for this function:

◆ repeat() [4/4]

template<class PAR >
template<typename SPEC >
auto repeat ( SPEC &&  clauseDef)
inline

Definition at line 1154 of file parse.hpp.

References util::parse::accept_repeated().

+ Here is the call graph for this function:

◆ bracket() [1/3]

template<class PAR >
template<typename SPEC1 , typename SPEC2 , typename SPEC3 >
auto bracket ( SPEC1 &&  openDef,
SPEC2 &&  closeDef,
SPEC3 &&  bodyDef 
)
inline

Combinator: extend this Syntax with a further sequenced sub-clause in brackets.

See also
accept_bracket()

Definition at line 1166 of file parse.hpp.

References util::parse::accept_bracket().

+ Here is the call graph for this function:

◆ bracket() [2/3]

template<class PAR >
template<typename SPEC >
auto bracket ( string  bracketSpec,
SPEC &&  bodyDef 
)
inline

Definition at line 1176 of file parse.hpp.

References util::parse::accept_bracket().

+ Here is the call graph for this function:

◆ bracket() [3/3]

template<class PAR >
template<typename SPEC >
auto bracket ( SPEC &&  bodyDef)
inline

Definition at line 1185 of file parse.hpp.

References util::parse::accept_bracket().

+ Here is the call graph for this function:

◆ bracketOpt() [1/2]

template<class PAR >
template<typename SPEC >
auto bracketOpt ( string  bracketSpec,
SPEC &&  bodyDef 
)
inline

Definition at line 1193 of file parse.hpp.

References util::parse::accept_bracketOpt().

+ Here is the call graph for this function:

◆ bracketOpt() [2/2]

template<class PAR >
template<typename SPEC >
auto bracketOpt ( SPEC &&  bodyDef)
inline

Definition at line 1202 of file parse.hpp.

References util::parse::accept_bracketOpt().

+ Here is the call graph for this function:

◆ bind()

template<class PAR >
template<class FUN >
auto bind ( FUN &&  modelAdapt)
inline

Definition at line 1210 of file parse.hpp.

References util::parse::accept(), and util::parse::adaptConnex().

+ Here is the call graph for this function:

◆ bindMatch()

template<class PAR >
auto bindMatch ( uint  group = 0)
inline

Definition at line 1219 of file parse.hpp.

References util::parse::accept(), and util::parse::toStringConnex().

+ Here is the call graph for this function:

◆ eval()

template<class PAR >
Eval< Result > & eval ( )
inlineprivate

Definition at line 880 of file parse.hpp.

Referenced by Syntax< PAR >::parse().

+ Here is the caller graph for this function:

Member Data Documentation

◆ parse_

+ Inheritance diagram for Syntax< PAR >:
+ Collaboration diagram for Syntax< PAR >:

The documentation for this class was generated from the following file: