Imported existing code
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
Copyright (c) 2001-2009 Hartmut Kaiser
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_ALTERNATIVE_FEB_05_2007_1153AM)
|
||||
#define SPIRIT_ALTERNATIVE_FEB_05_2007_1153AM
|
||||
|
||||
#include <boost/spirit/home/qi/detail/alternative_function.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/as_variant.hpp>
|
||||
#include <boost/fusion/include/any.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
#include <boost/fusion/include/mpl.hpp>
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
#include <boost/fusion/include/push_front.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/end.hpp>
|
||||
#include <boost/mpl/find_if.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct alternative
|
||||
{
|
||||
template <typename T>
|
||||
struct transform_child : mpl::identity<T> {};
|
||||
|
||||
template <typename All, typename Filtered>
|
||||
struct build_container
|
||||
{
|
||||
// if the original attribute list does not contain any unused
|
||||
// attributes it is used, otherwise a single unused_type is
|
||||
// pushed to the front the list. This is to make sure that if
|
||||
// there is an unused in the list it is the first one.
|
||||
typedef typename
|
||||
mpl::find_if<All, is_same<mpl::_, unused_type> >::type
|
||||
unused_;
|
||||
|
||||
typedef typename
|
||||
mpl::eval_if<
|
||||
is_same<unused_, typename mpl::end<All>::type>,
|
||||
mpl::identity<All>,
|
||||
fusion::result_of::push_front<Filtered, unused_type>
|
||||
>::type
|
||||
attribute_sequence;
|
||||
|
||||
// Ok, now make a variant over the attribute_sequence. It's
|
||||
// a pity that make_variant_over does not support forward MPL
|
||||
// sequences. We use our own conversion metaprogram (as_variant).
|
||||
typedef typename
|
||||
as_variant<attribute_sequence>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_fusion_sequence<alternative, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
detail::alternative_function<Iterator, Context, Skipper, Attribute>
|
||||
f(first, last, context, skipper, attr);
|
||||
|
||||
// return true if *any* of the parsers succeed
|
||||
return fusion::any(component.elements, f);
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "alternatives[";
|
||||
fusion::for_each(component.elements,
|
||||
spirit::detail::what_function<Context>(result, ctx));
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_AND_PREDICATE_MARCH_23_2007_0617PM)
|
||||
#define SPIRIT_AND_PREDICATE_MARCH_23_2007_0617PM
|
||||
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct and_predicate
|
||||
{
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute
|
||||
{
|
||||
typedef unused_type type;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& /*attr*/)
|
||||
{
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
Iterator i = first;
|
||||
return director::parse(
|
||||
subject(component), i, last, context, skipper, unused);
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "and-predicate[";
|
||||
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
result += director::what(subject(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_DIFFERENCE_FEB_11_2007_1250PM)
|
||||
#define SPIRIT_DIFFERENCE_FEB_11_2007_1250PM
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/attribute_of.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct difference
|
||||
{
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute
|
||||
{
|
||||
typedef typename
|
||||
result_of::left<Component>::type
|
||||
left_type;
|
||||
|
||||
typedef typename
|
||||
traits::attribute_of<
|
||||
qi::domain, left_type, Context, Iterator>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef typename
|
||||
result_of::left<Component>::type::director
|
||||
ldirector;
|
||||
|
||||
typedef typename
|
||||
result_of::right<Component>::type::director
|
||||
rdirector;
|
||||
|
||||
// Unlike classic Spirit, with this version of difference, the rule
|
||||
// lit("policeman") - "police" will always fail to match.
|
||||
|
||||
// Spirit2 does not count the matching chars while parsing and
|
||||
// there is no reliable and fast way to check if the LHS matches
|
||||
// more than the RHS.
|
||||
|
||||
// Try RHS first
|
||||
Iterator start = first;
|
||||
if (rdirector::parse(spirit::right(component), first, last, context,
|
||||
skipper, unused))
|
||||
{
|
||||
// RHS succeeds, we fail.
|
||||
first = start;
|
||||
return false;
|
||||
}
|
||||
// RHS fails, now try LHS
|
||||
return ldirector::parse(spirit::left(component), first, last,
|
||||
context, skipper, attr);
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "difference[";
|
||||
|
||||
typedef typename
|
||||
result_of::left<Component>::type::director
|
||||
ldirector;
|
||||
|
||||
typedef typename
|
||||
result_of::right<Component>::type::director
|
||||
rdirector;
|
||||
|
||||
result += ldirector::what(spirit::left(component), ctx);
|
||||
result += ", ";
|
||||
result += rdirector::what(spirit::right(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
49
libraries/include/boost/spirit/home/qi/operator/expect.hpp
Normal file
49
libraries/include/boost/spirit/home/qi/operator/expect.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_EXPECT_APRIL_29_2007_0445PM)
|
||||
#define SPIRIT_EXPECT_APRIL_29_2007_0445PM
|
||||
|
||||
#include <boost/spirit/home/qi/operator/sequence_base.hpp>
|
||||
#include <boost/spirit/home/qi/detail/expect_function.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
template <typename Iterator>
|
||||
struct expectation_failure
|
||||
{
|
||||
Iterator first;
|
||||
Iterator last;
|
||||
std::string what;
|
||||
};
|
||||
|
||||
struct expect : sequence_base<expect>
|
||||
{
|
||||
friend struct sequence_base<expect>;
|
||||
|
||||
private:
|
||||
|
||||
template <typename Iterator, typename Context, typename Skipper>
|
||||
static detail::expect_function<
|
||||
Iterator, Context, Skipper
|
||||
, expectation_failure<Iterator> >
|
||||
fail_function(
|
||||
Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper)
|
||||
{
|
||||
return detail::expect_function<
|
||||
Iterator, Context, Skipper, expectation_failure<Iterator> >
|
||||
(first, last, context, skipper);
|
||||
}
|
||||
|
||||
static std::string what_()
|
||||
{
|
||||
return "expect[";
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
85
libraries/include/boost/spirit/home/qi/operator/kleene.hpp
Normal file
85
libraries/include/boost/spirit/home/qi/operator/kleene.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_KLEENE_JAN_07_2007_0818AM)
|
||||
#define SPIRIT_KLEENE_JAN_07_2007_0818AM
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/detail/container.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct kleene
|
||||
{
|
||||
template <typename T>
|
||||
struct build_attribute_container
|
||||
{
|
||||
typedef std::vector<T> type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_container<kleene, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef typename
|
||||
result_of::subject<Component>::type
|
||||
subject_type;
|
||||
typedef typename
|
||||
traits::attribute_of<
|
||||
qi::domain, subject_type, Context, Iterator>::type
|
||||
attr_type;
|
||||
typedef typename subject_type::director director;
|
||||
|
||||
// create a value if Attribute is not unused_type
|
||||
typename mpl::if_<
|
||||
is_same<typename remove_const<Attribute>::type, unused_type>
|
||||
, unused_type
|
||||
, attr_type>::type
|
||||
val;
|
||||
|
||||
while(
|
||||
director::parse(
|
||||
subject(component)
|
||||
, first, last, context, skipper, val)
|
||||
)
|
||||
{
|
||||
container::push_back(attr, val);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "kleene[";
|
||||
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
result += director::what(subject(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
97
libraries/include/boost/spirit/home/qi/operator/list.hpp
Normal file
97
libraries/include/boost/spirit/home/qi/operator/list.hpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_LIST_MARCH_24_2007_1031AM)
|
||||
#define SPIRIT_LIST_MARCH_24_2007_1031AM
|
||||
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/detail/container.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct list
|
||||
{
|
||||
template <typename T>
|
||||
struct build_attribute_container
|
||||
{
|
||||
typedef std::vector<T> type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_container<list, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef typename
|
||||
result_of::left<Component>::type::director
|
||||
ldirector;
|
||||
|
||||
typedef typename
|
||||
result_of::right<Component>::type::director
|
||||
rdirector;
|
||||
|
||||
typename container::result_of::value<Attribute>::type val;
|
||||
if (ldirector::parse(
|
||||
spirit::left(component)
|
||||
, first, last, context, skipper, val)
|
||||
)
|
||||
{
|
||||
container::push_back(attr, val);
|
||||
Iterator i = first;
|
||||
while(
|
||||
rdirector::parse(
|
||||
spirit::right(component)
|
||||
, i, last, context, skipper, unused)
|
||||
&& ldirector::parse(
|
||||
spirit::left(component)
|
||||
, i, last, context, skipper, val)
|
||||
)
|
||||
{
|
||||
container::push_back(attr, val);
|
||||
first = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "list[";
|
||||
|
||||
typedef typename
|
||||
result_of::left<Component>::type::director
|
||||
ldirector;
|
||||
|
||||
typedef typename
|
||||
result_of::right<Component>::type::director
|
||||
rdirector;
|
||||
|
||||
result += ldirector::what(spirit::left(component), ctx);
|
||||
result += ", ";
|
||||
result += rdirector::what(spirit::right(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
146
libraries/include/boost/spirit/home/qi/operator/meta_grammar.hpp
Normal file
146
libraries/include/boost/spirit/home/qi/operator/meta_grammar.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_META_GRAMMAR_FEB_02_2007_0620PM)
|
||||
#define BOOST_SPIRIT_META_GRAMMAR_FEB_02_2007_0620PM
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/meta_grammar.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// forwards
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct sequence;
|
||||
struct expect;
|
||||
struct alternative;
|
||||
struct sequential_or;
|
||||
struct permutation;
|
||||
struct difference;
|
||||
struct list;
|
||||
struct optional;
|
||||
struct kleene;
|
||||
struct plus;
|
||||
struct and_predicate;
|
||||
struct not_predicate;
|
||||
struct main_meta_grammar;
|
||||
|
||||
template <typename Expr, typename Enable>
|
||||
struct is_valid_expr;
|
||||
|
||||
template <typename Expr, typename Enable>
|
||||
struct expr_transform;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// operator meta-grammars
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct binary_meta_grammar
|
||||
: proto::or_<
|
||||
// a >> b
|
||||
meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::shift_right, sequence
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a + b
|
||||
, meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::plus, sequence
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a > b
|
||||
, meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::greater, expect
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a | b
|
||||
, meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::bitwise_or, alternative
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a || b
|
||||
, meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::logical_or, sequential_or
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a ^ b
|
||||
, meta_grammar::binary_rule_flat<
|
||||
qi::domain, proto::tag::bitwise_xor, permutation
|
||||
, main_meta_grammar
|
||||
>
|
||||
// a - b
|
||||
, meta_grammar::binary_rule<
|
||||
qi::domain, proto::tag::minus, difference
|
||||
, main_meta_grammar, main_meta_grammar
|
||||
>
|
||||
// a % b
|
||||
, meta_grammar::binary_rule<
|
||||
qi::domain, proto::tag::modulus, list
|
||||
, main_meta_grammar, main_meta_grammar
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
struct unary_meta_grammar
|
||||
: proto::or_<
|
||||
// -a
|
||||
meta_grammar::unary_rule<
|
||||
qi::domain, proto::tag::negate, optional
|
||||
, main_meta_grammar
|
||||
>
|
||||
// *a
|
||||
, meta_grammar::unary_rule<
|
||||
qi::domain, proto::tag::dereference, kleene
|
||||
, main_meta_grammar
|
||||
>
|
||||
// +a
|
||||
, meta_grammar::unary_rule<
|
||||
qi::domain, proto::tag::unary_plus, plus
|
||||
, main_meta_grammar
|
||||
>
|
||||
// &a
|
||||
, meta_grammar::unary_rule<
|
||||
qi::domain, proto::tag::address_of, and_predicate
|
||||
, main_meta_grammar
|
||||
>
|
||||
// !a
|
||||
, meta_grammar::unary_rule<
|
||||
qi::domain, proto::tag::logical_not, not_predicate
|
||||
, main_meta_grammar
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
struct operator_meta_grammar
|
||||
: proto::or_<
|
||||
binary_meta_grammar
|
||||
, unary_meta_grammar
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// These specializations non-intrusively hooks into the RD meta-grammar.
|
||||
// (see qi/meta_grammar.hpp)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Expr>
|
||||
struct is_valid_expr<Expr
|
||||
, typename enable_if<proto::matches<Expr, operator_meta_grammar> >::type>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Expr>
|
||||
struct expr_transform<Expr
|
||||
, typename enable_if<proto::matches<Expr, operator_meta_grammar> >::type>
|
||||
: mpl::identity<operator_meta_grammar>
|
||||
{
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_NOT_PREDICATE_MARCH_23_2007_0618PM)
|
||||
#define SPIRIT_NOT_PREDICATE_MARCH_23_2007_0618PM
|
||||
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct not_predicate
|
||||
{
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute
|
||||
{
|
||||
typedef unused_type type;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& /*attr*/)
|
||||
{
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
Iterator i = first;
|
||||
return !director::parse(
|
||||
subject(component), i, last, context, skipper, unused);
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "not-predicate[";
|
||||
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
result += director::what(subject(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
86
libraries/include/boost/spirit/home/qi/operator/optional.hpp
Normal file
86
libraries/include/boost/spirit/home/qi/operator/optional.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_OPTIONAL_MARCH_23_2007_1117PM)
|
||||
#define SPIRIT_OPTIONAL_MARCH_23_2007_1117PM
|
||||
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/qi/detail/assign_to.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct optional
|
||||
{
|
||||
template <typename T>
|
||||
struct build_attribute_container
|
||||
{
|
||||
typedef boost::optional<T> type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_container<optional, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef typename
|
||||
result_of::subject<Component>::type
|
||||
subject_type;
|
||||
|
||||
typedef typename
|
||||
traits::attribute_of<
|
||||
qi::domain, subject_type, Context, Iterator>::type
|
||||
attr_type;
|
||||
|
||||
typedef typename subject_type::director director;
|
||||
|
||||
// create a value if Attribute is not unused_type
|
||||
typename mpl::if_<
|
||||
is_same<typename remove_const<Attribute>::type, unused_type>
|
||||
, unused_type
|
||||
, attr_type>::type
|
||||
val;
|
||||
|
||||
if (director::parse(
|
||||
subject(component), first, last, context, skipper, val))
|
||||
{
|
||||
qi::detail::assign_to(val, attr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "optional[";
|
||||
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
result += director::what(subject(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_PERMUTATION_OR_MARCH_13_2007_1145PM)
|
||||
#define SPIRIT_PERMUTATION_OR_MARCH_13_2007_1145PM
|
||||
|
||||
#include <boost/spirit/home/qi/detail/permute_function.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <boost/spirit/home/support/algorithm/any.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
#include <boost/fusion/include/as_vector.hpp>
|
||||
#include <boost/fusion/include/size.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct permutation
|
||||
{
|
||||
template <typename T>
|
||||
struct transform_child
|
||||
{
|
||||
typedef boost::optional<T> type;
|
||||
};
|
||||
|
||||
template <typename All, typename Filtered>
|
||||
struct build_container
|
||||
{
|
||||
typedef
|
||||
typename fusion::result_of::as_vector<Filtered>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_fusion_sequence<permutation, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
detail::permute_function<Iterator, Context, Skipper>
|
||||
f(first, last, context, skipper);
|
||||
|
||||
boost::array<
|
||||
bool
|
||||
, fusion::result_of::size<typename Component::elements_type>::value
|
||||
>
|
||||
slots;
|
||||
|
||||
BOOST_FOREACH(bool& taken, slots)
|
||||
{
|
||||
taken = false;
|
||||
}
|
||||
|
||||
// We have a bool array 'slots' with one flag for each parser.
|
||||
// permute_function sets the slot to true when the corresponding
|
||||
// parser successful matches. We loop until there are no more
|
||||
// successful parsers.
|
||||
|
||||
bool result = false;
|
||||
f.taken = slots.begin();
|
||||
while (spirit::any_ns(component.elements, attr, f))
|
||||
{
|
||||
f.taken = slots.begin();
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "permutation[";
|
||||
fusion::for_each(component.elements,
|
||||
spirit::detail::what_function<Context>(result, ctx));
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
92
libraries/include/boost/spirit/home/qi/operator/plus.hpp
Normal file
92
libraries/include/boost/spirit/home/qi/operator/plus.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_PLUS_MARCH_13_2007_0127PM)
|
||||
#define SPIRIT_PLUS_MARCH_13_2007_0127PM
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/component.hpp>
|
||||
#include <boost/spirit/home/support/detail/container.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct plus
|
||||
{
|
||||
template <typename T>
|
||||
struct build_attribute_container
|
||||
{
|
||||
typedef std::vector<T> type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_container<plus, Component, Iterator, Context>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef typename
|
||||
result_of::subject<Component>::type
|
||||
subject_type;
|
||||
typedef typename
|
||||
traits::attribute_of<
|
||||
qi::domain, subject_type, Context, Iterator>::type
|
||||
attr_type;
|
||||
typedef typename subject_type::director director;
|
||||
|
||||
// create a value if Attribute is not unused_type
|
||||
typename mpl::if_<
|
||||
is_same<typename remove_const<Attribute>::type, unused_type>
|
||||
, unused_type
|
||||
, attr_type>::type
|
||||
val;
|
||||
|
||||
if (director::parse(
|
||||
subject(component)
|
||||
, first, last, context, skipper, val)
|
||||
)
|
||||
{
|
||||
container::push_back(attr, val);
|
||||
while(director::parse(
|
||||
subject(component)
|
||||
, first, last, context, skipper, val)
|
||||
)
|
||||
{
|
||||
container::push_back(attr, val);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "plus[";
|
||||
|
||||
typedef typename
|
||||
result_of::subject<Component>::type::director
|
||||
director;
|
||||
|
||||
result += director::what(subject(component), ctx);
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
38
libraries/include/boost/spirit/home/qi/operator/sequence.hpp
Normal file
38
libraries/include/boost/spirit/home/qi/operator/sequence.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_SEQUENCE_APR_22_2006_0811AM)
|
||||
#define SPIRIT_SEQUENCE_APR_22_2006_0811AM
|
||||
|
||||
#include <boost/spirit/home/qi/operator/sequence_base.hpp>
|
||||
#include <boost/spirit/home/qi/detail/fail_function.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct sequence : sequence_base<sequence>
|
||||
{
|
||||
friend struct sequence_base<sequence>;
|
||||
|
||||
private:
|
||||
|
||||
template <typename Iterator, typename Context, typename Skipper>
|
||||
static detail::fail_function<Iterator, Context, Skipper>
|
||||
fail_function(
|
||||
Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper)
|
||||
{
|
||||
return detail::fail_function<Iterator, Context, Skipper>
|
||||
(first, last, context, skipper);
|
||||
}
|
||||
|
||||
static std::string what_()
|
||||
{
|
||||
return "sequence[";
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_SEQUENCE_BASE_APR_22_2006_0811AM)
|
||||
#define SPIRIT_SEQUENCE_BASE_APR_22_2006_0811AM
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <boost/spirit/home/support/algorithm/any_if.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/detail/values.hpp>
|
||||
#include <boost/fusion/include/as_vector.hpp>
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
template <typename Derived>
|
||||
struct sequence_base // this class is shared by sequence and expect
|
||||
{
|
||||
template <typename T>
|
||||
struct transform_child : mpl::identity<T> {};
|
||||
|
||||
template <typename All, typename Filtered>
|
||||
struct build_container
|
||||
{
|
||||
typedef
|
||||
typename fusion::result_of::as_vector<Filtered>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_fusion_sequence<
|
||||
sequence_base<Derived>, Component, Iterator, Context
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Iterator, typename Context>
|
||||
struct attribute_not_unused
|
||||
{
|
||||
template <typename Component>
|
||||
struct apply
|
||||
: spirit::traits::is_not_unused<typename
|
||||
traits::attribute_of<
|
||||
qi::domain, Component, Context, Iterator>::type
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
Iterator iter = first;
|
||||
typedef attribute_not_unused<Iterator, Context> predicate;
|
||||
|
||||
// return false if *any* of the parsers fail
|
||||
if (spirit::any_if(
|
||||
component.elements, attr
|
||||
, Derived::fail_function(iter, last, context, skipper), predicate()))
|
||||
return false;
|
||||
first = iter;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = Derived::what_();
|
||||
fusion::for_each(component.elements,
|
||||
spirit::detail::what_function<Context>(result, ctx));
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(SPIRIT_SEQUENTIAL_OR_MARCH_12_2007_1130PM)
|
||||
#define SPIRIT_SEQUENTIAL_OR_MARCH_12_2007_1130PM
|
||||
|
||||
#include <boost/spirit/home/qi/detail/pass_function.hpp>
|
||||
#include <boost/spirit/home/support/attribute_transform.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/spirit/home/support/algorithm/any_ns.hpp>
|
||||
#include <boost/fusion/include/as_vector.hpp>
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
struct sequential_or
|
||||
{
|
||||
template <typename T>
|
||||
struct transform_child
|
||||
{
|
||||
typedef boost::optional<T> type;
|
||||
};
|
||||
|
||||
template <typename All, typename Filtered>
|
||||
struct build_container
|
||||
{
|
||||
typedef
|
||||
typename fusion::result_of::as_vector<Filtered>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute :
|
||||
build_fusion_sequence<
|
||||
sequential_or, Component, Iterator, Context
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& component
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& context, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
qi::detail::pass_function<Iterator, Context, Skipper>
|
||||
f(first, last, context, skipper);
|
||||
|
||||
// return true if *any* of the parsers succeed
|
||||
// (we use the non-short-circuiting version: any_ns
|
||||
// to force all elements to be tested)
|
||||
return spirit::any_ns(component.elements, attr, f);
|
||||
}
|
||||
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
std::string result = "sequential-or[";
|
||||
fusion::for_each(component.elements,
|
||||
spirit::detail::what_function<Context>(result, ctx));
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user