Contains definition of the
proto::matches<>
metafunction for determining if a given expression matches a given pattern.
proto::transform<_>
A wildcard grammar element that matches any expression, and a transform that returns
the current expression unchanged.
The wildcard type, proto::_, is a grammar element such
that proto::matches<E, proto::_>::value
is true for any expression type E.
The wildcard can also be used as a stand-in for a template argument when matching terminals.
For instance, the following is a grammar that will match any
std::complex<> terminal:BOOST_MPL_ASSERT((
proto::matches<
proto::terminal<std::complex<double> >::type,
proto::terminal<std::complex< proto::_ > >
>
));
When used as a transform, proto::_ returns the current expression
unchanged. For instance, in the following, proto::_ is used with
the proto::fold<>
transform to fold the children of a node:struct CountChildren :
proto::or_<
// Terminals have no children
proto::when<proto::terminal<proto::_>, mpl::int_<0>()>,
// Use proto::fold<> to count the children of non-terminals
proto::otherwise<
proto::fold<
proto::_, // <-- fold the current expression
mpl::int_<0>(),
mpl::plus<proto::_state, mpl::int_<1> >()
>
>
>
{};
proto::transform_impl<Expr, State, Data>
Expr
Expr
typename impl::expr_param
An expression
typename impl::state_param
typename impl::data_param
expr
_
proto::transform<not_<Grammar> >
Inverts the set of expressions matched by a grammar. When used as a transform,
proto::not_<> returns the current expression unchanged.
If an expression type E does not match a grammar
G, then E does
match proto::not_<G>. For example,
proto::not_<proto::terminal<proto::_> >
will match any non-terminal.
proto::transform_impl<Expr, State, Data>
Expr
Expr
typename impl::expr_param
An expression
typename impl::state_param
typename impl::data_param
proto::matches<Expr, proto::not_>::value
is true.
expr
not_
proto::_
proto::not_<proto::_>
proto::transform<if_<If, Then, Else> >
Used to select one grammar or another based on the result of a compile-time Boolean.
When used as a transform, proto::if_<> selects between two
transforms based on a compile-time Boolean.
When proto::if_<If, Then, Else> is used as a grammar,
If must be a Proto transform and
Then and Else must be grammars.
An expression type E matches
proto::if_<If, Then, Else> if
boost::result_of<proto::when<proto::_, If>(E)>::type::value
is true and
E matches Then; or, if
boost::result_of<proto::when<proto::_, If>(E)>::type::value
is false and E matches Else.
The template parameter Then defaults to proto::_
and Else defaults to
proto::not_<proto::_>,
so an expression type E will match
proto::if_<If> if and only if
boost::result_of<proto::when<proto::_, If>(E)>::type::value
is true.
// A grammar that only matches integral terminals,
// using is_integral<> from Boost.Type_traits.
struct IsIntegral :
proto::and_<
proto::terminal<proto::_>,
proto::if_< boost::is_integral<proto::_value>()>
>
{};
When proto::if_<If, Then, Else> is used as a transform,
If, Then and
Else must be Proto transforms. When applying the transform to
an expression E, state S and
data V, if
boost::result_of<proto::when<proto::_, If>(E,S,V)>::type::value
is true then the Then transform
is applied; otherwise the Else transform is applied.
// Match a terminal. If the terminal is integral, return
// mpl::true_; otherwise, return mpl::false_.
struct IsIntegral2 :
proto::when<
proto::terminal<_>,
proto::if_<
boost::is_integral<proto::_value>(),
mpl::true_(),
mpl::false_()
>
>
{};
proto::transform_impl< Expr, State, Data >
typename mpl::if_<
typename boost::result_of<proto::when<proto::_, If>(Expr, State, Data)>::type,
typename boost::result_of<proto::when<proto::_, Then>(Expr, State, Data)>::type,
typename boost::result_of<proto::when<proto::_, Else>(Expr, State, Data)>::type
>::type
result_type
typename impl::expr_param
An expression
typename impl::state_param
The current state
typename impl::data_param
A data of arbitrary type
proto::when<proto::_, Then-or-Else>()(expr, state, data)
if_
proto::transform<or_<G...> >
For matching one of a set of alternate grammars. Alternates are tried in order to avoid ambiguity.
When used as a transform, proto::or_<> applies the transform
associated with the first grammar that matches the expression.
An expression type E matches
proto::or_<G0,G1,...Gn>
if E matches any Gx for
x in [0,n].
When applying
proto::or_<G0,G1,...Gn>
as a transform with an expression e of type E,
state s and data d, it is equivalent to
Gx()(e, s, d), where
x is the lowest number such that
proto::matches<E, Gx>::value
is true.
The maximun number of template arguments proto::or_<> accepts
is controlled by the BOOST_PROTO_MAX_LOGICAL_ARITY
macro.
proto::transform_impl< Expr, State, Data >
unspecified
result_type
typename impl::expr_param
An expression
typename impl::state_param
The current state
typename impl::data_param
A data of arbitrary type
Gx()(expr, state, data)
, where
x is the lowest number such that
proto::matches<Expr, Gx>::value
is true.
or_
proto::transform<and_<G...> >
For matching all of a set of grammars. When used as a transform,
proto::and_<> applies the transform associated
with each grammar in the set and returns the result of the last.
An expression type E matches
proto::and_<G0,G1,...Gn>
if E matches all Gx
for x in [0,n].
When applying
proto::and_<G0,G1,...Gn>
as a transform with an expression e, state
s and data d, it is equivalent
to (G0()(e, s, d),G1()(e, s, d),...Gn()(e, s, d)).
The maximun number of template arguments proto::and_<> accepts
is controlled by the BOOST_PROTO_MAX_LOGICAL_ARITY
macro.
proto::transform_impl< Expr, State, Data >
typename boost::result_of<Gn(Expr, State, Data)>::type
result_type
typename impl::expr_param
An expression
typename impl::state_param
The current state
typename impl::data_param
A data of arbitrary type
(G0()(expr, state, data),G1()(expr, state, data),...Gn()(expr, state, data))
and_
proto::transform<switch_<Cases, Transform> >
For matching one of a set of alternate grammars, which are looked up based on
the result type of the transform passed in second template parameter.
If no transform is passed, the default one is proto::tag_of<proto::_>()
so the default matching is based on the expression's tag type. When used as a transform,
proto::switch_<> applies the transform associated
with the sub-grammar that matches the expression.
An expression type E matches
proto::switch_<C,T> if
E matches
C::case_<boost::result_of<proto::when<proto::_,T>(E)>::type>.
When applying proto::switch_<C,T> as a
transform with an expression e of type
E, state s of
type S and data d
of type D, it is equivalent to
C::case_<boost::result_of<proto::when<proto::_,T>(E,S,D)>::type>()(e, s, d).
Cases::template case_<
typename when<_, Transform>::template impl<Expr, State, Data>::result_type
>::template impl<Expr, State, Data>
switch_
For forcing exact matches of terminal types.
By default, matching terminals ignores references and cv-qualifiers. For instance,
a terminal expression of type
proto::terminal<int const &>::type
will match the grammar proto::terminal<int>.
If that is not desired, you can force an exact match with
proto::terminal<proto::exact<int> >.
This will only match integer terminals where the terminal is held by value.
For matching terminals that are convertible to a type.
Use proto::convertible_to<> to match a terminal that is
convertible to some type. For example, the grammar
proto::terminal<proto::convertible_to<int> >
will match any terminal whose argument is convertible to an integer.
For matching a Grammar to a variable number of sub-expressions.
An expression type proto::basic_expr<AT,
proto::listN<A0,...An,U0,...Um> >
matches a grammar proto::basic_expr<BT,
proto::listM<B0,...Bn,proto::vararg<V> > >
if BT is proto::_
or AT, and if
Ax matches
Bx
for each x in [0,n]
and if Ux matches
V for each x in [0,m].
For example:
// Match any function call expression, regardless
// of the number of function arguments:
struct Function :
proto::function< proto::vararg<proto::_> >
{};
When used as a transform, proto::vararg<G>
applies G's transform.
A Boolean metafunction that evaluates whether a given expression type matches a grammar.
proto::matches<Expr, Grammar> inherits from
mpl::true_ if
Expr::proto_grammar matches
Grammar::proto_grammar, and from
mpl::false_ otherwise.
Non-terminal expressions are matched against a grammar according to the following rules:
The wildcard pattern,
proto::_
, matches any expression.
An expression
proto::basic_expr<AT,
proto::listN
<A0,...An>
>
matches a grammar
proto::basic_expr<BT,
proto::listN
<B0,...Bn>
>
if
BT is
proto::_
or
AT, and if
Ax
matches
Bx
for each x in [0,n].
An expression
proto::basic_expr<AT,
proto::listN
<A0,...An,U0,...Um>
>
matches a grammar
proto::basic_expr<BT,
proto::listM
<B0,...Bn,proto::vararg<V>
> >
if
BT is
proto::_
or
AT, and if
Ax
matches
Bx
for each
x in [0,n] and if
Ux
matches
V for each x in
[0,m].
An expression E matches
proto::or_<B0,...Bn>
if
E matches some
Bx
for
x in [0,n].
An expression E matches
proto::and_<B0,...Bn>
if
E matches all
Bx
for
x in [0,n].
An expression E matches
proto::if_<T,U,V>
if:
boost::result_of<proto::when<proto::_,T>(E)>::type::value
is true and
E matches
U, or
boost::result_of<proto::when<proto::_,T>(E)>::type::value
is false and E matches
V.
Note: U defaults to
proto::_
and V defaults to
proto::not_<proto::_>
.
An expression E matches
proto::not_<T>
if
E does not match T.
An expression E matches
proto::switch_<C, T>
if
E matches C::case_<boost::result_of<proto::when<proto::_,T>(E)>::type>.
Note: T defaults to proto::tag_of<proto::_>()
A terminal expression can trivially match the grammar proto::_. In addition,
a terminal expression
proto::basic_expr<AT,
proto::term<A> >
matches a grammar
proto::basic_expr<BT, proto::term<B> >
if BT is proto::_
or AT and one of the following is true:
B is the wildcard pattern,
proto::_
A is B
A is B &
A is B const &
B is
proto::exact<A>
B is
proto::convertible_to<X>
and boost::is_convertible<A,X>::value is
true.
A is X[M] or
X(&)[M] and
B is
X[proto::N]
.
A is X(&)[M]
and B is
X(&)[proto::N]
.
A is X[M] or
X(&)[M] and B is
X*.
B lambda-matches
A (see below).
A type B lambda-matches
A if one of the following is true:
B is A
B is the wildcard pattern,
proto::_
B is
T<B0,...Bn>
and A is
T<A0,...An>
and for each x in [0,n],
Ax and
Bx are types such that
Ax lambda-matches
Bx
mpl::bool_<true-or-false>