Added thirdparty: boost library

This commit is contained in:
Viacheslav Demydiuk
2024-01-06 19:55:56 +02:00
parent bf49f439e1
commit bccd1e7051
15683 changed files with 3239840 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
/*=============================================================================
Copyright (c) 2009 Chris Hoeppler
Copyright (c) 2014 Lee Clagett
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_X3_CONFIX_MAY_30_2014_1819PM)
#define BOOST_SPIRIT_X3_CONFIX_MAY_30_2014_1819PM
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
{
template<typename Prefix, typename Subject, typename Postfix>
struct confix_directive :
unary_parser<Subject, confix_directive<Prefix, Subject, Postfix>>
{
typedef unary_parser<
Subject, confix_directive<Prefix, Subject, Postfix>> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr confix_directive(Prefix const& prefix
, Subject const& subject
, Postfix const& postfix) :
base_type(subject),
prefix(prefix),
postfix(postfix)
{
}
template<typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(
Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
Iterator save = first;
if (!(prefix.parse(first, last, context, rcontext, unused) &&
this->subject.parse(first, last, context, rcontext, attr) &&
postfix.parse(first, last, context, rcontext, unused)))
{
first = save;
return false;
}
return true;
}
Prefix prefix;
Postfix postfix;
};
template<typename Prefix, typename Postfix>
struct confix_gen
{
template<typename Subject>
constexpr confix_directive<
Prefix, typename extension::as_parser<Subject>::value_type, Postfix>
operator[](Subject const& subject) const
{
return { prefix, as_parser(subject), postfix };
}
Prefix prefix;
Postfix postfix;
};
template<typename Prefix, typename Postfix>
constexpr confix_gen<typename extension::as_parser<Prefix>::value_type,
typename extension::as_parser<Postfix>::value_type>
confix(Prefix const& prefix, Postfix const& postfix)
{
return { as_parser(prefix), as_parser(postfix) };
}
}}}
#endif
+105
View File
@@ -0,0 +1,105 @@
/*=============================================================================
Copyright (c) 2001-2014 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_X3_EXPECT_MARCH_16_2012_1024PM)
#define BOOST_SPIRIT_X3_EXPECT_MARCH_16_2012_1024PM
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
#include <boost/config.hpp> // for BOOST_SYMBOL_VISIBLE
#include <boost/throw_exception.hpp>
#include <stdexcept>
namespace boost { namespace spirit { namespace x3
{
template <typename Iterator>
struct BOOST_SYMBOL_VISIBLE expectation_failure : std::runtime_error
{
public:
expectation_failure(Iterator where, std::string const& which)
: std::runtime_error("boost::spirit::x3::expectation_failure")
, where_(where), which_(which)
{}
~expectation_failure() {}
std::string which() const { return which_; }
Iterator const& where() const { return where_; }
private:
Iterator where_;
std::string which_;
};
template <typename Subject>
struct expect_directive : unary_parser<Subject, expect_directive<Subject>>
{
typedef unary_parser<Subject, expect_directive<Subject> > base_type;
static bool const is_pass_through_unary = true;
constexpr expect_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
bool r = this->subject.parse(first, last, context, rcontext, attr);
if (!r)
{
boost::throw_exception(
expectation_failure<Iterator>(
first, what(this->subject)));
}
return r;
}
};
struct expect_gen
{
template <typename Subject>
constexpr expect_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto expect = expect_gen{};
}}}
namespace boost { namespace spirit { namespace x3 { namespace detail
{
// Special case handling for expect expressions.
template <typename Subject, typename Context, typename RContext>
struct parse_into_container_impl<expect_directive<Subject>, Context, RContext>
{
template <typename Iterator, typename Attribute>
static bool call(
expect_directive<Subject> const& parser
, Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr)
{
bool r = parse_into_container(
parser.subject, first, last, context, rcontext, attr);
if (!r)
{
boost::throw_exception(
expectation_failure<Iterator>(
first, what(parser.subject)));
}
return r;
}
};
}}}}
#endif
+78
View File
@@ -0,0 +1,78 @@
/*=============================================================================
Copyright (c) 2001-2014 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_X3_LEXEME_MARCH_24_2007_0802AM)
#define BOOST_SPIRIT_X3_LEXEME_MARCH_24_2007_0802AM
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/skip_over.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>
namespace boost { namespace spirit { namespace x3
{
template <typename Subject>
struct lexeme_directive : unary_parser<Subject, lexeme_directive<Subject>>
{
typedef unary_parser<Subject, lexeme_directive<Subject> > base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr lexeme_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename enable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
x3::skip_over(first, last, context);
auto const& skipper = x3::get<skipper_tag>(context);
typedef unused_skipper<
typename remove_reference<decltype(skipper)>::type>
unused_skipper_type;
unused_skipper_type unused_skipper(skipper);
return this->subject.parse(
first, last
, make_context<skipper_tag>(unused_skipper, context)
, rcontext
, attr);
}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename disable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
// no need to pre-skip if skipper is unused
return this->subject.parse(
first, last
, context
, rcontext
, attr);
}
};
struct lexeme_gen
{
template <typename Subject>
constexpr lexeme_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto lexeme = lexeme_gen{};
}}}
#endif
+51
View File
@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2015 Mario Lang
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(BOOST_SPIRIT_HOME_X3_EXTENSIONS_MATCHES_HPP)
#define BOOST_SPIRIT_HOME_X3_EXTENSIONS_MATCHES_HPP
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/spirit/home/x3/support/traits/move_to.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>
namespace boost { namespace spirit { namespace x3
{
template <typename Subject>
struct matches_directive : unary_parser<Subject, matches_directive<Subject>>
{
using base_type = unary_parser<Subject, matches_directive<Subject>>;
static bool const has_attribute = true;
using attribute_type = bool;
constexpr matches_directive(Subject const& subject) : base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
bool const result = this->subject.parse(
first, last, context, rcontext, unused);
traits::move_to(result, attr);
return true;
}
};
struct matches_gen
{
template <typename Subject>
constexpr matches_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto matches = matches_gen{};
}}}
#endif
+54
View File
@@ -0,0 +1,54 @@
/*=============================================================================
Copyright (c) 2014 Thomas Bernard
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_X3_NO_CASE_SEPT_16_2014_0912PM)
#define BOOST_SPIRIT_X3_NO_CASE_SEPT_16_2014_0912PM
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/support/no_case.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
{
// propagate no_case information through the context
template <typename Subject>
struct no_case_directive : unary_parser<Subject, no_case_directive<Subject>>
{
typedef unary_parser<Subject, no_case_directive<Subject> > base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr no_case_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
return this->subject.parse(
first, last
, make_context<no_case_tag>(no_case_compare_, context)
, rcontext
, attr);
}
};
struct no_case_gen
{
template <typename Subject>
constexpr no_case_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto no_case = no_case_gen{};
}}}
#endif
+78
View File
@@ -0,0 +1,78 @@
/*=============================================================================
Copyright (c) 2001-2014 Joel de Guzman
Copyright (c) 2001-2011 Hartmut Kaiser
Copyright (c) 2013 Agustin Berge
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_X3_NO_SKIP_JAN_16_2010_0802PM)
#define BOOST_SPIRIT_X3_NO_SKIP_JAN_16_2010_0802PM
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/skip_over.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>
namespace boost { namespace spirit { namespace x3
{
// same as lexeme[], but does not pre-skip
template <typename Subject>
struct no_skip_directive : unary_parser<Subject, no_skip_directive<Subject>>
{
typedef unary_parser<Subject, no_skip_directive<Subject> > base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr no_skip_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename enable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
auto const& skipper = x3::get<skipper_tag>(context);
typedef unused_skipper<
typename remove_reference<decltype(skipper)>::type>
unused_skipper_type;
unused_skipper_type unused_skipper(skipper);
return this->subject.parse(
first, last
, make_context<skipper_tag>(unused_skipper, context)
, rcontext
, attr);
}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename disable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
return this->subject.parse(
first, last
, context
, rcontext
, attr);
}
};
struct no_skip_gen
{
template <typename Subject>
constexpr no_skip_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto no_skip = no_skip_gen{};
}}}
#endif
+51
View File
@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2001-2014 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_X3_OMIT_MARCH_24_2007_0802AM)
#define BOOST_SPIRIT_X3_OMIT_MARCH_24_2007_0802AM
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
{
///////////////////////////////////////////////////////////////////////////
// omit_directive forces the attribute of subject parser
// to be unused_type
///////////////////////////////////////////////////////////////////////////
template <typename Subject>
struct omit_directive : unary_parser<Subject, omit_directive<Subject>>
{
typedef unary_parser<Subject, omit_directive<Subject> > base_type;
typedef unused_type attribute_type;
static bool const has_attribute = false;
typedef Subject subject_type;
constexpr omit_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context, typename RContext>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, unused_type) const
{
return this->subject.parse(first, last, context, rcontext, unused);
}
};
struct omit_gen
{
template <typename Subject>
constexpr omit_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto omit = omit_gen{};
}}}
#endif
+86
View File
@@ -0,0 +1,86 @@
/*=============================================================================
Copyright (c) 2014 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)
=============================================================================*/
#ifndef BOOST_SPIRIT_X3_DIRECTIVE_RAW_HPP
#define BOOST_SPIRIT_X3_DIRECTIVE_RAW_HPP
#include <boost/spirit/home/x3/core/skip_over.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/spirit/home/x3/support/traits/move_to.hpp>
#include <boost/spirit/home/x3/support/traits/pseudo_attribute.hpp>
#include <boost/range/iterator_range_core.hpp>
namespace boost { namespace spirit { namespace x3
{
// this is a pseudo attribute type indicating that the parser wants the
// iterator range pointing to the [first, last) matching characters from
// the input iterators.
struct raw_attribute_type {};
template <typename Subject>
struct raw_directive : unary_parser<Subject, raw_directive<Subject>>
{
typedef unary_parser<Subject, raw_directive<Subject> > base_type;
typedef raw_attribute_type attribute_type;
static bool const handles_container = true;
typedef Subject subject_type;
constexpr raw_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
x3::skip_over(first, last, context);
Iterator i = first;
if (this->subject.parse(i, last, context, rcontext, unused))
{
traits::move_to(first, i, attr);
first = i;
return true;
}
return false;
}
template <typename Iterator, typename Context, typename RContext>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, unused_type) const
{
return this->subject.parse(first, last, context, rcontext, unused);
}
};
struct raw_gen
{
template <typename Subject>
constexpr raw_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto raw = raw_gen{};
namespace traits
{
template <typename Context, typename Iterator>
struct pseudo_attribute<Context, raw_attribute_type, Iterator>
{
using attribute_type = raw_attribute_type;
using type = boost::iterator_range<Iterator>;
static type call(Iterator& first, Iterator const& last, attribute_type)
{
return { first, last };
}
};
}
}}}
#endif
+154
View File
@@ -0,0 +1,154 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2011 Hartmut Kaiser
Copyright (c) 2014 Thomas Bernard
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)
==============================================================================*/
#ifndef BOOST_SPIRIT_X3_DIRECTIVE_REPEAT_HPP
#define BOOST_SPIRIT_X3_DIRECTIVE_REPEAT_HPP
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/spirit/home/x3/operator/kleene.hpp>
namespace boost { namespace spirit { namespace x3 { namespace detail
{
template <typename T>
struct exact_count // handles repeat(exact)[p]
{
typedef T type;
bool got_max(T i) const { return i >= exact_value; }
bool got_min(T i) const { return i >= exact_value; }
T const exact_value;
};
template <typename T>
struct finite_count // handles repeat(min, max)[p]
{
typedef T type;
bool got_max(T i) const { return i >= max_value; }
bool got_min(T i) const { return i >= min_value; }
T const min_value;
T const max_value;
};
template <typename T>
struct infinite_count // handles repeat(min, inf)[p]
{
typedef T type;
bool got_max(T /*i*/) const { return false; }
bool got_min(T i) const { return i >= min_value; }
T const min_value;
};
}}}}
namespace boost { namespace spirit { namespace x3
{
template<typename Subject, typename RepeatCountLimit>
struct repeat_directive : unary_parser<Subject, repeat_directive<Subject,RepeatCountLimit>>
{
typedef unary_parser<Subject, repeat_directive<Subject,RepeatCountLimit>> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = true;
constexpr repeat_directive(Subject const& subject, RepeatCountLimit const& repeat_limit_)
: base_type(subject)
, repeat_limit(repeat_limit_)
{}
template<typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(
Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
Iterator local_iterator = first;
typename RepeatCountLimit::type i{};
for (/**/; !repeat_limit.got_min(i); ++i)
{
if (!detail::parse_into_container(
this->subject, local_iterator, last, context, rcontext, attr))
return false;
}
first = local_iterator;
// parse some more up to the maximum specified
for (/**/; !repeat_limit.got_max(i); ++i)
{
if (!detail::parse_into_container(
this->subject, first, last, context, rcontext, attr))
break;
}
return true;
}
RepeatCountLimit repeat_limit;
};
// Infinite loop tag type
struct inf_type {};
constexpr inf_type inf = inf_type();
struct repeat_gen
{
template<typename Subject>
constexpr auto operator[](Subject const& subject) const
{
return *as_parser(subject);
}
template <typename T>
struct repeat_gen_lvl1
{
constexpr repeat_gen_lvl1(T&& repeat_limit_)
: repeat_limit(repeat_limit_)
{}
template<typename Subject>
constexpr repeat_directive< typename extension::as_parser<Subject>::value_type, T>
operator[](Subject const& subject) const
{
return { as_parser(subject),repeat_limit };
}
T repeat_limit;
};
template <typename T>
constexpr repeat_gen_lvl1<detail::exact_count<T>>
operator()(T const exact) const
{
return { detail::exact_count<T>{exact} };
}
template <typename T>
constexpr repeat_gen_lvl1<detail::finite_count<T>>
operator()(T const min_val, T const max_val) const
{
return { detail::finite_count<T>{min_val,max_val} };
}
template <typename T>
constexpr repeat_gen_lvl1<detail::infinite_count<T>>
operator()(T const min_val, inf_type const &) const
{
return { detail::infinite_count<T>{min_val} };
}
};
constexpr auto repeat = repeat_gen{};
}}}
namespace boost { namespace spirit { namespace x3 { namespace traits
{
template <typename Subject, typename RepeatCountLimit, typename Context>
struct attribute_of<x3::repeat_directive<Subject,RepeatCountLimit>, Context>
: build_container<typename attribute_of<Subject, Context>::type> {};
}}}}
#endif
+59
View File
@@ -0,0 +1,59 @@
/*=============================================================================
Copyright (c) 2011 Jamboree
Copyright (c) 2014 Lee Clagett
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_X3_SEEK_APRIL_13_2014_1920PM)
#define BOOST_SPIRIT_X3_SEEK_APRIL_13_2014_1920PM
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
{
template<typename Subject>
struct seek_directive : unary_parser<Subject, seek_directive<Subject>>
{
typedef unary_parser<Subject, seek_directive<Subject>> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr seek_directive(Subject const& subject) :
base_type(subject) {}
template<typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(
Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
for (Iterator current(first);; ++current)
{
if (this->subject.parse(current, last, context, rcontext, attr))
{
first = current;
return true;
}
// fail only after subject fails & no input
if (current == last)
return false;
}
}
};
struct seek_gen
{
template<typename Subject>
constexpr seek_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto seek = seek_gen{};
}}}
#endif
+120
View File
@@ -0,0 +1,120 @@
/*=============================================================================
Copyright (c) 2001-2014 Joel de Guzman
Copyright (c) 2013 Agustin Berge
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_X3_SKIP_JANUARY_26_2008_0422PM)
#define BOOST_SPIRIT_X3_SKIP_JANUARY_26_2008_0422PM
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/skip_over.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
#include <boost/utility/enable_if.hpp>
namespace boost { namespace spirit { namespace x3
{
template <typename Subject>
struct reskip_directive : unary_parser<Subject, reskip_directive<Subject>>
{
typedef unary_parser<Subject, reskip_directive<Subject>> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr reskip_directive(Subject const& subject)
: base_type(subject) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename disable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
auto const& skipper =
detail::get_unused_skipper(x3::get<skipper_tag>(context));
return this->subject.parse(
first, last
, make_context<skipper_tag>(skipper, context)
, rcontext
, attr);
}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
typename enable_if<has_skipper<Context>, bool>::type
parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
return this->subject.parse(
first, last
, context
, rcontext
, attr);
}
};
template <typename Subject, typename Skipper>
struct skip_directive : unary_parser<Subject, skip_directive<Subject, Skipper>>
{
typedef unary_parser<Subject, skip_directive<Subject, Skipper>> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
constexpr skip_directive(Subject const& subject, Skipper const& skipper)
: base_type(subject)
, skipper(skipper)
{}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
return this->subject.parse(
first, last
, make_context<skipper_tag>(skipper, context)
, rcontext
, attr);
}
Skipper const skipper;
};
struct reskip_gen
{
template <typename Skipper>
struct skip_gen
{
constexpr skip_gen(Skipper const& skipper)
: skipper_(skipper) {}
template <typename Subject>
constexpr skip_directive<typename extension::as_parser<Subject>::value_type, Skipper>
operator[](Subject const& subject) const
{
return { as_parser(subject), skipper_ };
}
Skipper skipper_;
};
template <typename Skipper>
constexpr skip_gen<Skipper> const operator()(Skipper const& skipper) const
{
return { skipper };
}
template <typename Subject>
constexpr reskip_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
{
return { as_parser(subject) };
}
};
constexpr auto skip = reskip_gen{};
}}}
#endif
+86
View File
@@ -0,0 +1,86 @@
/*=============================================================================
Copyright (c) 2014 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)
=============================================================================*/
#ifndef BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
#define BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
{
///////////////////////////////////////////////////////////////////////////
// with directive injects a value into the context prior to parsing.
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename Derived, typename T>
struct with_value_holder
: unary_parser<Subject, Derived>
{
typedef unary_parser<Subject, Derived> base_type;
mutable T val;
constexpr with_value_holder(Subject const& subject, T&& val)
: base_type(subject)
, val(std::forward<T>(val)) {}
};
template <typename Subject, typename Derived, typename T>
struct with_value_holder<Subject, Derived, T&>
: unary_parser<Subject, Derived>
{
typedef unary_parser<Subject, Derived> base_type;
T& val;
constexpr with_value_holder(Subject const& subject, T& val)
: base_type(subject)
, val(val) {}
};
template <typename Subject, typename ID, typename T>
struct with_directive
: with_value_holder<Subject, with_directive<Subject, ID, T>, T>
{
typedef with_value_holder<Subject, with_directive<Subject, ID, T>, T> base_type;
static bool const is_pass_through_unary = true;
static bool const handles_container = Subject::handles_container;
typedef Subject subject_type;
constexpr with_directive(Subject const& subject, T&& val)
: base_type(subject, std::forward<T>(val)) {}
template <typename Iterator, typename Context
, typename RContext, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, Attribute& attr) const
{
return this->subject.parse(
first, last
, make_context<ID>(this->val, context)
, rcontext
, attr);
}
};
template <typename ID, typename T>
struct with_gen
{
T&& val;
template <typename Subject>
constexpr with_directive<typename extension::as_parser<Subject>::value_type, ID, T>
operator[](Subject const& subject) const
{
return { as_parser(subject), std::forward<T>(val) };
}
};
template <typename ID, typename T>
constexpr with_gen<ID, T> with(T&& val)
{
return { std::forward<T>(val) };
}
}}}
#endif