Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
util::parse Namespace Reference

Namespaces

namespace  anonymous_namespace{parse.hpp}
 

Typedefs

using StrView = std::string_view
 
template<class RES >
using OpaqueConnex = Connex< std::function< Eval< RES >(StrView)> >
 special setup to be pre-declared and then used recursively
 
template<class RES >
using ForwardConnex = Connex< std::function< Eval< RES >(StrView)> & >
 
using NulP = decltype(buildConnex(Nil()))
 
using Term = decltype(buildConnex(std::declval< regex >()))
 
template<typename SPEC >
using if_acceptableSpec = lib::meta::enable_if< is_usableSpec< SPEC > >
 
template<typename SPEC1 , typename SPEC2 >
using if_acceptableSpecs = lib::meta::enable_if< is_usableSpec< SPEC1 >,lib::meta::enable_if< is_usableSpec< SPEC2 > > >
 

Classes

struct  _Join
 Standard case : combinator of two model branches. More...
 
struct  _Join< TAG, R1, SubModel< R2 > >
 
struct  _Join< TAG, SubModel< R1 >, R2 >
 Special Case : absorb sub-expression without flattening. More...
 
struct  _Join< TAG, SubModel< R1 >, SubModel< R2 > >
 
struct  _Join< TAG, TAG< RS... >, R2 >
 Generic case : extend a structured model by further branch. More...
 
struct  AltModel
 Sum Model : results from a disjunction of parsing clauses, which are are tested and accepted as alternatives, one at least. More...
 
struct  Connex
 Building block: parser function definition and connection element. More...
 
struct  Eval
 Parse evaluation result. More...
 
struct  is_usableSpec
 
struct  is_usableSpec< SPEC, std::void_t< decltype(Parser{std::declval< SPEC >()})> >
 
struct  IterModel
 Special case Product Model to represent iterative sequence. More...
 
class  Parser
 A Parser function to match and accept some syntax. More...
 
struct  SeqModel
 Product Model : results from a conjunction of parsing clauses, which are to be accepted in sequence, one after the other. More...
 
struct  SubModel
 Marker-Tag for the result from a sub-expression, not to be joined. More...
 
class  Syntax
 A Syntax clause with a parser and result state. More...
 

Functions

auto buildConnex (Nil)
 »Null-Connex« which always successfully accepts the empty sequence
 
auto buildConnex (regex rex)
 Foundation: build a Connex to accept a terminal symbol.
 
Term buildConnex (string const &rexDef)
 build from a string with Regular-Epression spec
 
template<class FUN >
auto buildConnex (Connex< FUN > const &anchor)
 copy-builder from an existing parser function
 
template<class FUN >
auto buildConnex (Connex< FUN > &&anchor)
 
template<class PAR >
auto buildConnex (Syntax< PAR > const &anchor)
 
template<class RES >
auto buildConnex (Syntax< Parser< OpaqueConnex< RES > > > &refClause)
 special setup to attach to a pre-defined clause for recursive syntax
 
template<class CON , class BIND >
auto adaptConnex (CON &&connex, BIND &&modelBinding)
 Adapt by applying a result-transforming function after a successful parse.
 
template<class CON >
auto toStringConnex (CON &&connex, uint part)
 
template<class C1 , class C2 >
auto sequenceConnex (C1 &&connex1, C2 &&connex2)
 accept sequence of two parse functions
 
template<class C1 , class C2 >
auto branchedConnex (C1 &&connex1, C2 &&connex2)
 accept either one of two alternative parse functions
 
template<class C1 , class C2 >
auto repeatedConnex (uint min, uint max, C1 &&delimConnex, C2 &&bodyConnex)
 repeatedly accept parse-function, optionally delimited.
 
template<class CNX >
auto optionalConnex (CNX &&connex)
 try to accept parse-function, backtracking if not successful.
 
template<class C1 , class C2 , class C3 >
auto bracketedConnex (C1 &&openingConnex, C2 &&closingConnex, C3 &&bodyConnex, bool isOptional)
 accept some structure enclosed into a bracketing construct.
 
 Parser (Nil) -> Parser< NulP >
 
 Parser (regex &&) -> Parser< Term >
 
 Parser (regex const &) -> Parser< Term >
 
 Parser (string const &) -> Parser< Term >
 
template<class FUN >
 Parser (Connex< FUN >) -> Parser< Connex< FUN > >
 
template<class PAR >
 Parser (Syntax< PAR >) -> Parser< typename PAR::Connex >
 
template<class RES >
 Parser (Syntax< Parser< OpaqueConnex< RES > > >) -> Parser< ForwardConnex< RES > >
 
template<typename SPEC >
auto accept (SPEC &&clauseDef)
 ===== Syntax clause builder DSL =====
 
auto accept ()
 empty Syntax clause to start further definition
 
template<typename SPEC >
auto accept_opt (SPEC &&clauseDef)
 start Syntax clause with an optional syntax part
 
template<typename SPEC1 , typename SPEC2 >
auto accept_repeated (uint min, uint max, SPEC1 &&delimDef, SPEC2 &&clauseDef)
 Start Syntax clause with a repeated sub-clause, with separator and repetition limit; repetitions ∊ [min..max] The separator will be expected between instances of the repeated sub-clause and will by itself produce no model.
 
template<typename SPEC1 , typename SPEC2 , typename = if_acceptableSpecs<SPEC1,SPEC2>>
auto accept_repeated (uint cnt, SPEC1 &&delimDef, SPEC2 &&clauseDef)
 
template<typename SPEC1 , typename SPEC2 , typename = if_acceptableSpecs<SPEC1,SPEC2>>
auto accept_repeated (SPEC1 &&delimDef, SPEC2 &&clauseDef)
 start Syntax with an arbitrarily repeated sub-clause, with separator
 
template<typename SPEC >
auto accept_repeated (uint min, uint max, SPEC &&clauseDef)
 
template<typename SPEC >
auto accept_repeated (uint cnt, SPEC &&clauseDef)
 
template<typename SPEC >
auto accept_repeated (SPEC &&clauseDef)
 
template<typename SPEC1 , typename SPEC2 , typename SPEC3 >
auto accept_bracket (SPEC1 &&openDef, SPEC2 &&closeDef, SPEC3 &&bodyDef)
 Start Syntax with a sub-clause enclosed into a bracketing construct.
 
template<typename SPEC >
auto accept_bracket (string bracketSpec, SPEC &&bodyDef)
 Start Syntax with a bracketed sub-clause, with given single-char delimiters.
 
template<typename SPEC >
auto accept_bracket (SPEC &&bodyDef)
 Start Syntax with a sub-clause enclosed in parentheses.
 
template<typename SPEC >
auto accept_bracketOpt (string bracketSpec, SPEC &&bodyDef)
 Start Syntax with a sub-clause, optionally enclosed into brackets.
 
template<typename SPEC >
auto accept_bracketOpt (SPEC &&bodyDef)
 
template<typename RES >
auto expectResult ()
 Setup an assignable, recursive Syntax clause, initially empty.
 

Typedef Documentation

◆ StrView

using StrView = std::string_view

Definition at line 174 of file parse.hpp.

◆ OpaqueConnex

template<class RES >
using OpaqueConnex = Connex<std::function<Eval<RES>(StrView)> >

special setup to be pre-declared and then used recursively

Definition at line 215 of file parse.hpp.

◆ ForwardConnex

template<class RES >
using ForwardConnex = Connex<std::function<Eval<RES>(StrView)>&>

Definition at line 218 of file parse.hpp.

◆ NulP

using NulP = decltype(buildConnex (Nil()))

Definition at line 233 of file parse.hpp.

◆ Term

using Term = decltype(buildConnex (std::declval<regex>()))

Definition at line 257 of file parse.hpp.

◆ if_acceptableSpec

template<typename SPEC >
using if_acceptableSpec = lib::meta::enable_if<is_usableSpec<SPEC> >

Definition at line 760 of file parse.hpp.

◆ if_acceptableSpecs

template<typename SPEC1 , typename SPEC2 >
using if_acceptableSpecs = lib::meta::enable_if<is_usableSpec<SPEC1> ,lib::meta::enable_if<is_usableSpec<SPEC2> >>

Definition at line 763 of file parse.hpp.


Class Documentation

◆ util::parse::_Join

struct util::parse::_Join
Class Members
typedef TAG< R1, R2 > Result
+ Collaboration diagram for _Join< TAG, R1, R2 >:

◆ util::parse::_Join< TAG, R1, SubModel< R2 > >

struct util::parse::_Join< TAG, R1, SubModel< R2 > >
Class Members
typedef TAG< R1, R2 > Result
+ Collaboration diagram for _Join< TAG, R1, SubModel< R2 > >:

◆ util::parse::_Join< TAG, SubModel< R1 >, R2 >

struct util::parse::_Join< TAG, SubModel< R1 >, R2 >
Class Members
typedef TAG< R1, R2 > Result
+ Collaboration diagram for _Join< TAG, SubModel< R1 >, R2 >:

◆ util::parse::_Join< TAG, SubModel< R1 >, SubModel< R2 > >

struct util::parse::_Join< TAG, SubModel< R1 >, SubModel< R2 > >
Class Members
typedef TAG< R1, R2 > Result
+ Collaboration diagram for _Join< TAG, SubModel< R1 >, SubModel< R2 > >:

◆ util::parse::_Join< TAG, TAG< RS... >, R2 >

struct util::parse::_Join< TAG, TAG< RS... >, R2 >
Class Members
typedef TAG< RS..., R2 > Result
+ Collaboration diagram for _Join< TAG, TAG< RS... >, R2 >:

◆ util::parse::Eval

struct util::parse::Eval
Class Members
typedef RES Result
Class Members
optional< RES > result
size_t consumed {0}
+ Inheritance diagram for Eval< RES >:
+ Collaboration diagram for Eval< RES >:

◆ util::parse::SubModel

struct util::parse::SubModel
+ Collaboration diagram for SubModel< RES >:

Function Documentation

◆ buildConnex() [1/7]

auto buildConnex ( Nil  )
inline

»Null-Connex« which always successfully accepts the empty sequence

Definition at line 226 of file parse.hpp.

Referenced by buildConnex().

+ Here is the caller graph for this function:

◆ buildConnex() [2/7]

auto buildConnex ( regex  rex)
inline

Foundation: build a Connex to accept a terminal symbol.

the actual parsing is delegated to a Regular Expression, which must match against the beginning of the input sequence, possibly after skipping some whitespace. The defined parser returns an Eval context, to hold a Result Model and the number of characters matched by this terminal symbol.

Definition at line 245 of file parse.hpp.

References util::leadingWhitespace(), and util::matchAtStart().

+ Here is the call graph for this function:

◆ buildConnex() [3/7]

Term buildConnex ( string const &  rexDef)
inline

build from a string with Regular-Epression spec

Definition at line 261 of file parse.hpp.

References buildConnex().

+ Here is the call graph for this function:

◆ buildConnex() [4/7]

template<class FUN >
auto buildConnex ( Connex< FUN > const &  anchor)
inline

copy-builder from an existing parser function

Definition at line 269 of file parse.hpp.

◆ buildConnex() [5/7]

template<class FUN >
auto buildConnex ( Connex< FUN > &&  anchor)
inline

Definition at line 275 of file parse.hpp.

◆ buildConnex() [6/7]

template<class PAR >
auto buildConnex ( Syntax< PAR > const &  anchor)
inline

Definition at line 282 of file parse.hpp.

◆ buildConnex() [7/7]

template<class RES >
auto buildConnex ( Syntax< Parser< OpaqueConnex< RES > > > &  refClause)
inline

special setup to attach to a pre-defined clause for recursive syntax

Note
works in concert with the Parser deduction guide, so that the resulting ForwardConnex holds a reference to std::function, and thus gets to see the full definition reassigned later.

Definition at line 294 of file parse.hpp.

References Syntax< PAR >::parse().

+ Here is the call graph for this function:

◆ adaptConnex()

template<class CON , class BIND >
auto adaptConnex ( CON &&  connex,
BIND &&  modelBinding 
)
inline

Adapt by applying a result-transforming function after a successful parse.

Remarks
the purpose is to extract a custom data model immediately from the result; binding functors can be applied at any level of a Syntax, and thus the parse can be configured to produce custom result data.

Definition at line 337 of file parse.hpp.

References Eval< RES >::consumed.

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

+ Here is the caller graph for this function:

◆ toStringConnex()

template<class CON >
auto toStringConnex ( CON &&  connex,
uint  part 
)
inline

Definition at line 358 of file parse.hpp.

References util::leadingWhitespace(), and Eval< RES >::result.

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

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

◆ sequenceConnex()

template<class C1 , class C2 >
auto sequenceConnex ( C1 &&  connex1,
C2 &&  connex2 
)
inline

accept sequence of two parse functions

Definition at line 525 of file parse.hpp.

References Connex< FUN >::parse.

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

+ Here is the caller graph for this function:

◆ branchedConnex()

template<class C1 , class C2 >
auto branchedConnex ( C1 &&  connex1,
C2 &&  connex2 
)
inline

accept either one of two alternative parse functions

Definition at line 559 of file parse.hpp.

References Connex< FUN >::parse.

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

+ Here is the caller graph for this function:

◆ repeatedConnex()

template<class C1 , class C2 >
auto repeatedConnex ( uint  min,
uint  max,
C1 &&  delimConnex,
C2 &&  bodyConnex 
)
inline

repeatedly accept parse-function, optionally delimited.

Definition at line 594 of file parse.hpp.

References util::max(), util::min(), and Connex< FUN >::parse.

Referenced by accept_repeated().

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

◆ optionalConnex()

template<class CNX >
auto optionalConnex ( CNX &&  connex)
inline

try to accept parse-function, backtracking if not successful.

Definition at line 637 of file parse.hpp.

References Connex< FUN >::parse.

Referenced by accept_opt().

+ Here is the caller graph for this function:

◆ bracketedConnex()

template<class C1 , class C2 , class C3 >
auto bracketedConnex ( C1 &&  openingConnex,
C2 &&  closingConnex,
C3 &&  bodyConnex,
bool  isOptional 
)
inline

accept some structure enclosed into a bracketing construct.

Parameters
isOptionalif the bracketing can be omitted

Definition at line 659 of file parse.hpp.

References Eval< RES >::consumed.

Referenced by accept_bracket(), accept_bracket(), and accept_bracketOpt().

+ Here is the caller graph for this function:

◆ Parser() [1/7]

Parser ( Nil  ) -> Parser< NulP >

◆ Parser() [2/7]

Parser ( regex &&  ) -> Parser< Term >

◆ Parser() [3/7]

Parser ( regex const &  ) -> Parser< Term >

◆ Parser() [4/7]

Parser ( string const &  ) -> Parser< Term >

◆ Parser() [5/7]

template<class FUN >
Parser ( Connex< FUN >  ) -> Parser< Connex< FUN > >

◆ Parser() [6/7]

template<class PAR >
Parser ( Syntax< PAR >  ) -> Parser< typename PAR::Connex >

◆ Parser() [7/7]

template<class RES >
Parser ( Syntax< Parser< OpaqueConnex< RES > > >  ) -> Parser< ForwardConnex< RES > >

◆ accept() [1/2]

template<typename SPEC >
auto accept ( SPEC &&  clauseDef)
inline

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

build a Syntax clause from anything usable as parser-spec.

Definition at line 891 of file parse.hpp.

◆ accept() [2/2]

auto accept ( )
inline

empty Syntax clause to start further definition

Definition at line 897 of file parse.hpp.

Referenced by accept_bracket(), accept_bracket(), accept_bracketOpt(), accept_opt(), accept_repeated(), Syntax< PAR >::alt(), Syntax< PAR >::bind(), Syntax< PAR >::bindMatch(), expectResult(), and Syntax< PAR >::seq().

+ Here is the caller graph for this function:

◆ accept_opt()

template<typename SPEC >
auto accept_opt ( SPEC &&  clauseDef)
inline

start Syntax clause with an optional syntax part

Definition at line 903 of file parse.hpp.

References accept(), accept_opt(), and optionalConnex().

Referenced by accept_opt(), and Syntax< PAR >::opt().

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

◆ accept_repeated() [1/6]

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

Start Syntax clause with a repeated sub-clause, with separator and repetition limit; repetitions ∊ [min..max] The separator will be expected between instances of the repeated sub-clause and will by itself produce no model.

The result model is an instance of IterModel, which implies it is a vector (uses heap storage); if min ≡ 0, the model can be empty.

Definition at line 919 of file parse.hpp.

References accept(), accept_repeated(), util::max(), util::min(), and repeatedConnex().

Referenced by accept_repeated(), accept_repeated(), accept_repeated(), accept_repeated(), accept_repeated(), accept_repeated(), Syntax< PAR >::repeat(), Syntax< PAR >::repeat(), Syntax< PAR >::repeat(), and Syntax< PAR >::repeat().

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

◆ accept_repeated() [2/6]

template<typename SPEC1 , typename SPEC2 , typename = if_acceptableSpecs<SPEC1,SPEC2>>
auto accept_repeated ( uint  cnt,
SPEC1 &&  delimDef,
SPEC2 &&  clauseDef 
)
inline
Parameters
cntexact number of repetitions expected

Definition at line 936 of file parse.hpp.

References accept_repeated().

+ Here is the call graph for this function:

◆ accept_repeated() [3/6]

template<typename SPEC1 , typename SPEC2 , typename = if_acceptableSpecs<SPEC1,SPEC2>>
auto accept_repeated ( SPEC1 &&  delimDef,
SPEC2 &&  clauseDef 
)
inline

start Syntax with an arbitrarily repeated sub-clause, with separator

Definition at line 944 of file parse.hpp.

References accept_repeated().

+ Here is the call graph for this function:

◆ accept_repeated() [4/6]

template<typename SPEC >
auto accept_repeated ( uint  min,
uint  max,
SPEC &&  clauseDef 
)
inline

Definition at line 951 of file parse.hpp.

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

+ Here is the call graph for this function:

◆ accept_repeated() [5/6]

template<typename SPEC >
auto accept_repeated ( uint  cnt,
SPEC &&  clauseDef 
)
inline

Definition at line 958 of file parse.hpp.

References accept_repeated().

+ Here is the call graph for this function:

◆ accept_repeated() [6/6]

template<typename SPEC >
auto accept_repeated ( SPEC &&  clauseDef)
inline

Definition at line 965 of file parse.hpp.

References accept_repeated().

+ Here is the call graph for this function:

◆ accept_bracket() [1/3]

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

Start Syntax with a sub-clause enclosed into a bracketing construct.

The »bracket« is defined as syntax for the open marker and close marker. These are consumed without generating model elements. The parse fails unless the full sequence open body close can be matched.

Definition at line 978 of file parse.hpp.

References accept(), accept_bracket(), and bracketedConnex().

Referenced by accept_bracket(), accept_bracket(), accept_bracket(), Syntax< PAR >::bracket(), Syntax< PAR >::bracket(), and Syntax< PAR >::bracket().

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

◆ accept_bracket() [2/3]

template<typename SPEC >
auto accept_bracket ( string  bracketSpec,
SPEC &&  bodyDef 
)
inline

Start Syntax with a bracketed sub-clause, with given single-char delimiters.

Parameters
bracketSpeca 2-char string, e.g. "{}" to expect curly braces.

Definition at line 994 of file parse.hpp.

References accept(), accept_bracket(), and bracketedConnex().

+ Here is the call graph for this function:

◆ accept_bracket() [3/3]

template<typename SPEC >
auto accept_bracket ( SPEC &&  bodyDef)
inline

Start Syntax with a sub-clause enclosed in parentheses.

Definition at line 1009 of file parse.hpp.

References accept_bracket().

+ Here is the call graph for this function:

◆ accept_bracketOpt() [1/2]

template<typename SPEC >
auto accept_bracketOpt ( string  bracketSpec,
SPEC &&  bodyDef 
)
inline

Start Syntax with a sub-clause, optionally enclosed into brackets.

Definition at line 1017 of file parse.hpp.

References accept(), and bracketedConnex().

Referenced by accept_bracketOpt(), Syntax< PAR >::bracketOpt(), and Syntax< PAR >::bracketOpt().

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

◆ accept_bracketOpt() [2/2]

template<typename SPEC >
auto accept_bracketOpt ( SPEC &&  bodyDef)
inline

Definition at line 1031 of file parse.hpp.

References accept_bracketOpt().

+ Here is the call graph for this function:

◆ expectResult()

template<typename RES >
auto expectResult ( )
inline

Setup an assignable, recursive Syntax clause, initially empty.

Remarks
this provides the foundation for recursive syntax clauses; initially, an empty std::function with the pre-declared return type is embedded. Together with a special Parser deduction guide, later on a full syntax clause can be built, taking a reference to this function; finally the definition prepared here should be re-assigned with the fully defined syntax, which is handled by the assignment operator in class Syntax to re-assign a working parser function into the std::function holder.
Template Parameters
RESthe result model type to be expected; it is necessary to augment the full definition explicitly by a model-binding to produce this type — which typically also involves writing actual code to deal with the possibly open structure enable through a recursive syntax definition
See also
Parse_test::verify_recursiveSyntax()

Definition at line 1056 of file parse.hpp.

References accept().

+ Here is the call graph for this function: