Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_FEBRUARY_05_2007_1153AM)
#define SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/detail/alternative_function.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/detail/what_function.hpp>
#include <boost/spirit/home/support/unused.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/fusion/include/any.hpp>
#include <boost/fusion/include/mpl.hpp>
#include <boost/fusion/include/for_each.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::bitwise_or> // enables |
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::bitwise_or> // flattens |
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Elements>
struct alternative : nary_parser<alternative<Elements> >
{
template <typename Context, typename Iterator>
struct attribute
{
// Put all the element attributes in a tuple
typedef typename traits::build_attribute_sequence<
Elements, Context, traits::alternative_attribute_transform
, Iterator, qi::domain
>::type all_attributes;
// Ok, now make a variant over the attribute sequence. Note that
// build_variant makes sure that 1) all attributes in the variant
// are unique 2) puts the unused attribute, if there is any, to
// the front and 3) collapses single element variants, variant<T>
// to T.
typedef typename
traits::build_variant<all_attributes>::type
type;
};
alternative(Elements const& elements_)
: elements(elements_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
detail::alternative_function<Iterator, Context, Skipper, Attribute>
f(first, last, context, skipper, attr_);
// return true if *any* of the parsers succeed
return fusion::any(elements, f);
}
template <typename Context>
info what(Context& context) const
{
info result("alternative");
fusion::for_each(elements,
spirit::detail::what_function<Context>(result, context));
return result;
}
Elements elements;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::bitwise_or, Elements, Modifiers>
: make_nary_composite<Elements, alternative>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Elements>
struct has_semantic_action<qi::alternative<Elements> >
: nary_has_semantic_action<Elements> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::alternative<Elements>, Attribute, Context
, Iterator>
: nary_handles_container<Elements, Attribute, Context, Iterator> {};
}}}
#endif

View File

@@ -0,0 +1,92 @@
/*=============================================================================
Copyright (c) 2001-2011 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
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/fusion/include/at.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::address_of> // enables &p
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Subject>
struct and_predicate : unary_parser<and_predicate<Subject> >
{
typedef Subject subject_type;
template <typename Context, typename Iterator>
struct attribute
{
typedef unused_type type;
};
and_predicate(Subject const& subject_)
: subject(subject_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& /*attr*/) const
{
Iterator i = first;
return subject.parse(i, last, context, skipper, unused);
}
template <typename Context>
info what(Context& context) const
{
return info("and-predicate", subject.what(context));
}
Subject subject;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::address_of, Elements, Modifiers>
: make_unary_composite<Elements, and_predicate>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct has_semantic_action<qi::and_predicate<Subject> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::and_predicate<Subject>, Attribute, Context
, Iterator>
: unary_handles_container<Subject, Attribute, Context, Iterator> {};
}}}
#endif

View File

@@ -0,0 +1,112 @@
/*=============================================================================
Copyright (c) 2001-2011 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_FEBRUARY_11_2007_1250PM)
#define SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/fusion/include/at.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::minus> // enables -
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Left, typename Right>
struct difference : binary_parser<difference<Left, Right> >
{
typedef Left left_type;
typedef Right right_type;
template <typename Context, typename Iterator>
struct attribute
{
typedef typename
traits::attribute_of<left_type, Context, Iterator>::type
type;
};
difference(Left const& left_, Right const& right_)
: left(left_), right(right_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
// 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 (right.parse(first, last, context, skipper, unused))
{
// RHS succeeds, we fail.
first = start;
return false;
}
// RHS fails, now try LHS
return left.parse(first, last, context, skipper, attr_);
}
template <typename Context>
info what(Context& context) const
{
return info("difference",
std::make_pair(left.what(context), right.what(context)));
}
Left left;
Right right;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::minus, Elements, Modifiers>
: make_binary_composite<Elements, difference>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Left, typename Right>
struct has_semantic_action<qi::difference<Left, Right> >
: binary_has_semantic_action<Left, Right> {};
///////////////////////////////////////////////////////////////////////////
template <typename Left, typename Right, typename Attribute
, typename Context, typename Iterator>
struct handles_container<qi::difference<Left, Right>, Attribute, Context
, Iterator>
: binary_handles_container<Left, Right, Attribute, Context, Iterator> {};
}}}
#endif

View File

@@ -0,0 +1,103 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_EXPECT_APRIL_29_2007_0445PM)
#define SPIRIT_EXPECT_APRIL_29_2007_0445PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/operator/sequence_base.hpp>
#include <boost/spirit/home/qi/detail/expect_function.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <stdexcept>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::greater> // enables >
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::greater> // flattens >
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Iterator>
struct expectation_failure : std::runtime_error
{
expectation_failure(Iterator first_, Iterator last_, info const& what)
: std::runtime_error("boost::spirit::qi::expectation_failure")
, first(first_), last(last_), what_(what)
{}
~expectation_failure() throw() {}
Iterator first;
Iterator last;
info what_;
};
template <typename Elements>
struct expect : sequence_base<expect<Elements>, Elements>
{
friend struct sequence_base<expect<Elements>, Elements>;
expect(Elements const& elements)
: sequence_base<expect<Elements>, Elements>(elements) {}
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);
}
std::string id() const { return "expect"; }
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::greater, Elements, Modifiers>
: make_nary_composite<Elements, expect>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Elements>
struct has_semantic_action<qi::expect<Elements> >
: nary_has_semantic_action<Elements> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::expect<Elements>, Attribute, Context
, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,134 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_KLEENE_JANUARY_07_2007_0818AM)
#define SPIRIT_KLEENE_JANUARY_07_2007_0818AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/qi/detail/fail_function.hpp>
#include <boost/spirit/home/qi/detail/pass_container.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
//[composite_parsers_kleene_enable_
template <>
struct use_operator<qi::domain, proto::tag::dereference> // enables *p
: mpl::true_ {};
//]
}}
namespace boost { namespace spirit { namespace qi
{
//[composite_parsers_kleene
template <typename Subject>
struct kleene : unary_parser<kleene<Subject> >
{
typedef Subject subject_type;
template <typename Context, typename Iterator>
struct attribute
{
// Build a std::vector from the subject's attribute. Note
// that build_std_vector may return unused_type if the
// subject's attribute is an unused_type.
typedef typename
traits::build_std_vector<
typename traits::
attribute_of<Subject, Context, Iterator>::type
>::type
type;
};
kleene(Subject const& subject_)
: subject(subject_) {}
template <typename F>
bool parse_container(F f) const
{
while (!f (subject))
;
return true;
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
// ensure the attribute is actually a container type
traits::make_container(attr_);
typedef detail::fail_function<Iterator, Context, Skipper>
fail_function;
Iterator iter = first;
fail_function f(iter, last, context, skipper);
parse_container(detail::make_pass_container(f, attr_));
first = f.first;
return true;
}
template <typename Context>
info what(Context& context) const
{
return info("kleene", subject.what(context));
}
Subject subject;
};
//]
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
//[composite_parsers_kleene_generator
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::dereference, Elements, Modifiers>
: make_unary_composite<Elements, kleene>
{};
//]
// ///////////////////////////////////////////////////////////////////////////
// // Define what attributes are compatible with a kleene
// template <typename Attribute, typename Subject, typename Context, typename Iterator>
// struct is_attribute_compatible<Attribute, kleene<Subject>, Context, Iterator>
// : traits::is_container_compatible<qi::domain, Attribute
// , kleene<Subject>, Context, Iterator>
// {};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct has_semantic_action<qi::kleene<Subject> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::kleene<Subject>, Attribute
, Context, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,135 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_LIST_MARCH_24_2007_1031AM)
#define SPIRIT_LIST_MARCH_24_2007_1031AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/qi/detail/fail_function.hpp>
#include <boost/spirit/home/qi/detail/pass_container.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <vector>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::modulus> // enables p % d
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Left, typename Right>
struct list : binary_parser<list<Left, Right> >
{
typedef Left left_type;
typedef Right right_type;
template <typename Context, typename Iterator>
struct attribute
{
// Build a std::vector from the LHS's attribute. Note
// that build_std_vector may return unused_type if the
// subject's attribute is an unused_type.
typedef typename
traits::build_std_vector<
typename traits::
attribute_of<Left, Context, Iterator>::type
>::type
type;
};
list(Left const& left_, Right const& right_)
: left(left_), right(right_) {}
template <typename F>
bool parse_container(F f) const
{
// in order to succeed we need to match at least one element
if (f (left))
return false;
typename F::iterator_type save = f.f.first;
while (right.parse(f.f.first, f.f.last, f.f.context, f.f.skipper, unused)
&& !f (left))
{
save = f.f.first;
}
f.f.first = save;
return true;
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
typedef detail::fail_function<Iterator, Context, Skipper>
fail_function;
// ensure the attribute is actually a container type
traits::make_container(attr_);
Iterator iter = first;
fail_function f(iter, last, context, skipper);
if (!parse_container(detail::make_pass_container(f, attr_)))
return false;
first = f.first;
return true;
}
template <typename Context>
info what(Context& context) const
{
return info("list",
std::make_pair(left.what(context), right.what(context)));
}
Left left;
Right right;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::modulus, Elements, Modifiers>
: make_binary_composite<Elements, list>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Left, typename Right>
struct has_semantic_action<qi::list<Left, Right> >
: binary_has_semantic_action<Left, Right> {};
///////////////////////////////////////////////////////////////////////////
template <typename Left, typename Right, typename Attribute
, typename Context, typename Iterator>
struct handles_container<qi::list<Left, Right>, Attribute, Context
, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,91 @@
/*=============================================================================
Copyright (c) 2001-2011 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
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::logical_not> // enables !p
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Subject>
struct not_predicate : unary_parser<not_predicate<Subject> >
{
typedef Subject subject_type;
template <typename Context, typename Iterator>
struct attribute
{
typedef unused_type type;
};
not_predicate(Subject const& subject_)
: subject(subject_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& /*attr*/) const
{
Iterator i = first;
return !subject.parse(i, last, context, skipper, unused);
}
template <typename Context>
info what(Context& context) const
{
return info("not-predicate", subject.what(context));
}
Subject subject;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::logical_not, Elements, Modifiers>
: make_unary_composite<Elements, not_predicate>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct has_semantic_action<qi::not_predicate<Subject> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::not_predicate<Subject>, Attribute
, Context, Iterator>
: unary_handles_container<Subject, Attribute, Context, Iterator> {};
}}}
#endif

View File

@@ -0,0 +1,135 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_OPTIONAL_MARCH_23_2007_1117PM)
#define SPIRIT_OPTIONAL_MARCH_23_2007_1117PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/unused.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
#include <boost/optional.hpp>
#include <vector>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::negate> // enables -p
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Subject>
struct optional : unary_parser<optional<Subject> >
{
typedef Subject subject_type;
template <typename Context, typename Iterator>
struct attribute
{
// Build a boost::optional from the subject's attribute. Note
// that boost::optional may return unused_type if the
// subject's attribute is an unused_type.
typedef typename
traits::build_optional<
typename traits::
attribute_of<Subject, Context, Iterator>::type
>::type
type;
};
optional(Subject const& subject_)
: subject(subject_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_, mpl::false_) const
{
// create a local value if Attribute is not unused_type
typename spirit::result_of::optional_value<Attribute>::type val =
typename spirit::result_of::optional_value<Attribute>::type();
if (subject.parse(first, last, context, skipper, val))
{
// assign the parsed value into our attribute
spirit::traits::assign_to(val, attr_);
}
return true;
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_, mpl::true_) const
{
subject.parse(first, last, context, skipper, attr_);
return true;
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
typedef typename spirit::result_of::optional_value<Attribute>::type
attribute_type;
return parse_impl(first, last, context, skipper, attr_
, traits::is_container<attribute_type>());
}
template <typename Context>
info what(Context& context) const
{
return info("optional", subject.what(context));
}
Subject subject;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::negate, Elements, Modifiers>
: make_unary_composite<Elements, optional>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct has_semantic_action<qi::optional<Subject> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::optional<Subject>, Attribute
, Context, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,146 @@
/*=============================================================================
Copyright (c) 2001-2011 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
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/permute_function.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/algorithm/any_if_ns.hpp>
#include <boost/spirit/home/support/detail/what_function.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/fusion/include/size.hpp>
#include <boost/optional.hpp>
#include <boost/foreach.hpp>
#include <boost/array.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::bitwise_xor> // enables ^
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::bitwise_xor> // flattens ^
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Elements>
struct permutation : nary_parser<permutation<Elements> >
{
template <typename Context, typename Iterator>
struct attribute
{
// Put all the element attributes in a tuple,
// wrapping each element in a boost::optional
typedef typename traits::build_attribute_sequence<
Elements, Context, traits::permutation_attribute_transform
, Iterator, qi::domain
>::type all_attributes;
// Now, build a fusion vector over the attributes. Note
// that build_fusion_vector 1) removes all unused attributes
// and 2) may return unused_type if all elements have
// unused_type(s).
typedef typename
traits::build_fusion_vector<all_attributes>::type
type;
};
permutation(Elements const& elements_)
: elements(elements_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
typedef traits::attribute_not_unused<Context, Iterator> predicate;
detail::permute_function<Iterator, Context, Skipper>
f(first, last, context, skipper);
boost::array<bool, fusion::result_of::size<Elements>::value> flags;
BOOST_FOREACH(bool& taken, flags)
{
taken = false;
}
// wrap the attribute in a tuple if it is not a tuple
typename traits::wrap_if_not_tuple<Attribute>::type attr_local(attr_);
// We have a bool array 'flags' 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 = flags.begin();
while (spirit::any_if_ns(elements, attr_local, f, predicate()))
{
f.taken = flags.begin();
result = true;
}
return result;
}
template <typename Context>
info what(Context& context) const
{
info result("permutation");
fusion::for_each(elements,
spirit::detail::what_function<Context>(result, context));
return result;
}
Elements elements;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::bitwise_xor, Elements, Modifiers>
: make_nary_composite<Elements, permutation>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
// We specialize this for permutation (see support/attributes.hpp).
// For permutation, we only wrap the attribute in a tuple IFF
// it is not already a fusion tuple.
template <typename Elements, typename Attribute>
struct pass_attribute<qi::permutation<Elements>, Attribute>
: wrap_if_not_tuple<Attribute> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements>
struct has_semantic_action<qi::permutation<Elements> >
: nary_has_semantic_action<Elements> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::permutation<Elements>, Attribute, Context
, Iterator>
: nary_handles_container<Elements, Attribute, Context, Iterator> {};
}}}
#endif

View File

@@ -0,0 +1,125 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_PLUS_MARCH_13_2007_0127PM)
#define SPIRIT_PLUS_MARCH_13_2007_0127PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/qi/detail/fail_function.hpp>
#include <boost/spirit/home/qi/detail/pass_container.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/support/info.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::unary_plus> // enables +p
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Subject>
struct plus : unary_parser<plus<Subject> >
{
typedef Subject subject_type;
template <typename Context, typename Iterator>
struct attribute
{
// Build a std::vector from the subject's attribute. Note
// that build_std_vector may return unused_type if the
// subject's attribute is an unused_type.
typedef typename
traits::build_std_vector<
typename traits::attribute_of<
Subject, Context, Iterator>::type
>::type
type;
};
plus(Subject const& subject_)
: subject(subject_) {}
template <typename F>
bool parse_container(F f) const
{
// in order to succeed we need to match at least one element
if (f (subject))
return false;
while (!f (subject))
;
return true;
}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
typedef detail::fail_function<Iterator, Context, Skipper>
fail_function;
// ensure the attribute is actually a container type
traits::make_container(attr_);
Iterator iter = first;
fail_function f(iter, last, context, skipper);
if (!parse_container(detail::make_pass_container(f, attr_)))
return false;
first = f.first;
return true;
}
template <typename Context>
info what(Context& context) const
{
return info("plus", subject.what(context));
}
Subject subject;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::unary_plus, Elements, Modifiers>
: make_unary_composite<Elements, plus>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct has_semantic_action<qi::plus<Subject> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::plus<Subject>, Attribute, Context
, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,96 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_SEQUENCE_APR_22_2006_0811AM)
#define SPIRIT_SEQUENCE_APR_22_2006_0811AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/operator/sequence_base.hpp>
#include <boost/spirit/home/qi/detail/fail_function.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::shift_right> // enables >>
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::shift_right> // flattens >>
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Elements>
struct sequence : sequence_base<sequence<Elements>, Elements>
{
friend struct sequence_base<sequence<Elements>, Elements>;
sequence(Elements const& elements)
: sequence_base<sequence<Elements>, Elements>(elements) {}
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);
}
std::string id() const { return "sequence"; }
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::shift_right, Elements, Modifiers>
: make_nary_composite<Elements, sequence>
{};
// ///////////////////////////////////////////////////////////////////////////
// // Define what attributes are compatible with a sequence
// template <typename Attribute, typename Elements, typename Context, typename Iterator>
// struct is_attribute_compatible<Attribute, sequence<Elements>, Context, Iterator>
// : mpl::or_<
// is_convertible<Attribute
// , typename traits::attribute_of<sequence<Elements>, Context, Iterator>::type>
// , traits::is_fusion_sequence_compatible<qi::domain, Attribute
// , sequence<Elements>, Context, Iterator>
// , traits::is_container_compatible<qi::domain, Attribute
// , sequence<Elements>, Context, Iterator>
// >
// {};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Elements>
struct has_semantic_action<qi::sequence<Elements> >
: nary_has_semantic_action<Elements> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::sequence<Elements>, Attribute, Context
, Iterator>
: mpl::true_ {};
}}}
#endif

View File

@@ -0,0 +1,140 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 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_SEQUENCE_BASE_APRIL_22_2006_0811AM)
#define SPIRIT_SEQUENCE_BASE_APRIL_22_2006_0811AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/detail/pass_container.hpp>
#include <boost/spirit/home/qi/detail/attributes.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/info.hpp>
#include <boost/spirit/home/support/sequence_base_id.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/fusion/include/as_vector.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/mpl/identity.hpp>
namespace boost { namespace spirit { namespace qi
{
template <typename Derived, typename Elements>
struct sequence_base // this class is shared by sequence and expect
: nary_parser<Derived>
{
typedef Elements elements_type;
struct sequence_base_id;
template <typename Context, typename Iterator>
struct attribute
{
// Put all the element attributes in a tuple
typedef typename traits::build_attribute_sequence<
Elements, Context, traits::sequence_attribute_transform
, Iterator, qi::domain
>::type all_attributes;
// Now, build a fusion vector over the attributes. Note
// that build_fusion_vector 1) removes all unused attributes
// and 2) may return unused_type if all elements have
// unused_type(s).
typedef typename
traits::build_fusion_vector<all_attributes>::type
type_;
// Finally, strip single element vectors into its
// naked form: vector1<T> --> T
typedef typename
traits::strip_single_element_vector<type_>::type
type;
};
sequence_base(Elements const& elements_)
: elements(elements_) {}
// standard case. Attribute is a fusion tuple
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_, mpl::false_) const
{
Iterator iter = first;
typedef traits::attribute_not_unused<Context, Iterator> predicate;
// wrap the attribute in a tuple if it is not a tuple or if the
// attribute of this sequence is a single element tuple
typedef typename attribute<Context, Iterator>::type_ attr_type_;
typename traits::wrap_if_not_tuple<Attribute
, typename mpl::and_<
traits::one_element_sequence<attr_type_>
, mpl::not_<traits::one_element_sequence<Attribute> >
>::type
>::type attr_local(attr_);
// return false if *any* of the parsers fail
if (spirit::any_if(elements, attr_local
, Derived::fail_function(iter, last, context, skipper), predicate()))
return false;
first = iter;
return true;
}
// Special case when Attribute is an stl container
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse_impl(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_, mpl::true_) const
{
// ensure the attribute is actually a container type
traits::make_container(attr_);
Iterator iter = first;
// return false if *any* of the parsers fail
if (fusion::any(elements
, detail::make_sequence_pass_container(
Derived::fail_function(iter, last, context, skipper), attr_))
)
return false;
first = iter;
return true;
}
// main parse function. Dispatches to parse_impl depending
// on the Attribute type.
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
return parse_impl(first, last, context, skipper, attr_
, traits::is_container<Attribute>());
}
template <typename Context>
info what(Context& context) const
{
info result(this->derived().id());
fusion::for_each(elements,
spirit::detail::what_function<Context>(result, context));
return result;
}
Elements elements;
};
}}}
#endif

View File

@@ -0,0 +1,127 @@
/*=============================================================================
Copyright (c) 2001-2011 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
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/pass_function.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/detail/what_function.hpp>
#include <boost/spirit/home/support/algorithm/any_if_ns.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/fusion/include/as_vector.hpp>
#include <boost/fusion/include/for_each.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_operator<qi::domain, proto::tag::logical_or> // enables ||
: mpl::true_ {};
template <>
struct flatten_tree<qi::domain, proto::tag::logical_or> // flattens ||
: mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
template <typename Elements>
struct sequential_or : nary_parser<sequential_or<Elements> >
{
template <typename Context, typename Iterator>
struct attribute
{
// Put all the element attributes in a tuple,
// wrapping each element in a boost::optional
typedef typename traits::build_attribute_sequence<
Elements, Context, traits::sequential_or_attribute_transform
, Iterator, qi::domain
>::type all_attributes;
// Now, build a fusion vector over the attributes. Note
// that build_fusion_vector 1) removes all unused attributes
// and 2) may return unused_type if all elements have
// unused_type(s).
typedef typename
traits::build_fusion_vector<all_attributes>::type
type;
};
sequential_or(Elements const& elements_)
: elements(elements_) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr_) const
{
typedef traits::attribute_not_unused<Context, Iterator> predicate;
detail::pass_function<Iterator, Context, Skipper>
f(first, last, context, skipper);
// wrap the attribute in a tuple if it is not a tuple
typename traits::wrap_if_not_tuple<Attribute>::type attr_local(attr_);
// return true if *any* of the parsers succeed
// (we use the non-short-circuiting version: any_if_ns
// to force all elements to be tested)
return spirit::any_if_ns(elements, attr_local, f, predicate());
}
template <typename Context>
info what(Context& context) const
{
info result("sequential-or");
fusion::for_each(elements,
spirit::detail::what_function<Context>(result, context));
return result;
}
Elements elements;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Modifiers>
struct make_composite<proto::tag::logical_or, Elements, Modifiers>
: make_nary_composite<Elements, sequential_or>
{};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
// We specialize this for sequential_or (see support/attributes.hpp).
// For sequential_or, we only wrap the attribute in a tuple IFF
// it is not already a fusion tuple.
template <typename Elements, typename Attribute>
struct pass_attribute<qi::sequential_or<Elements>, Attribute>
: wrap_if_not_tuple<Attribute> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements>
struct has_semantic_action<qi::sequential_or<Elements> >
: nary_has_semantic_action<Elements> {};
///////////////////////////////////////////////////////////////////////////
template <typename Elements, typename Attribute, typename Context
, typename Iterator>
struct handles_container<qi::sequential_or<Elements>, Attribute, Context
, Iterator>
: nary_handles_container<Elements, Attribute, Context, Iterator> {};
}}}
#endif