diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/spirit/home/x3/directive | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/spirit/home/x3/directive')
-rw-r--r-- | boost/spirit/home/x3/directive/expect.hpp | 80 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/lexeme.hpp | 84 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/no_skip.hpp | 82 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/omit.hpp | 55 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/raw.hpp | 70 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/skip.hpp | 124 | ||||
-rw-r--r-- | boost/spirit/home/x3/directive/with.hpp | 107 |
7 files changed, 602 insertions, 0 deletions
diff --git a/boost/spirit/home/x3/directive/expect.hpp b/boost/spirit/home/x3/directive/expect.hpp new file mode 100644 index 0000000000..4e59ce5dca --- /dev/null +++ b/boost/spirit/home/x3/directive/expect.hpp @@ -0,0 +1,80 @@ +/*============================================================================= + 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(SPIRIT_EXPECT_MARCH_16_2012_1024PM) +#define SPIRIT_EXPECT_MARCH_16_2012_1024PM + +#if defined(_MSC_VER) +#pragma once +#endif + +#include <boost/spirit/home/x3/support/context.hpp> +#include <boost/spirit/home/x3/core/parser.hpp> +#include <boost/throw_exception.hpp> +#include <stdexcept> + +namespace boost { namespace spirit { namespace x3 +{ + template <typename Iterator> + struct 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() throw() {} + + 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; + + 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> + expect_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + expect_gen const expect = expect_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/lexeme.hpp b/boost/spirit/home/x3/directive/lexeme.hpp new file mode 100644 index 0000000000..e5104272f9 --- /dev/null +++ b/boost/spirit/home/x3/directive/lexeme.hpp @@ -0,0 +1,84 @@ +/*============================================================================= + 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(SPIRIT_LEXEME_MARCH_24_2007_0802AM) +#define SPIRIT_LEXEME_MARCH_24_2007_0802AM + +#if defined(_MSC_VER) +#pragma once +#endif + +#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; + + 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 + //- x3::skip_over(first, last, context); + + return this->subject.parse( + first, last + , context + , rcontext + , attr); + } + }; + + struct lexeme_gen + { + template <typename Subject> + lexeme_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + lexeme_gen const lexeme = lexeme_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/no_skip.hpp b/boost/spirit/home/x3/directive/no_skip.hpp new file mode 100644 index 0000000000..14dee4d85c --- /dev/null +++ b/boost/spirit/home/x3/directive/no_skip.hpp @@ -0,0 +1,82 @@ +/*============================================================================= + 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(SPIRIT_NO_SKIP_JAN_16_2010_0802PM) +#define SPIRIT_NO_SKIP_JAN_16_2010_0802PM + +#if defined(_MSC_VER) +#pragma once +#endif + +#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; + + 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> + no_skip_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + no_skip_gen const no_skip = no_skip_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/omit.hpp b/boost/spirit/home/x3/directive/omit.hpp new file mode 100644 index 0000000000..43ebd49aaf --- /dev/null +++ b/boost/spirit/home/x3/directive/omit.hpp @@ -0,0 +1,55 @@ +/*============================================================================= + 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(SPIRIT_OMIT_MARCH_24_2007_0802AM) +#define SPIRIT_OMIT_MARCH_24_2007_0802AM + +#if defined(_MSC_VER) +#pragma once +#endif + +#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; + 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> + omit_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + omit_gen const omit = omit_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/raw.hpp b/boost/spirit/home/x3/directive/raw.hpp new file mode 100644 index 0000000000..e6bcd9a3a1 --- /dev/null +++ b/boost/spirit/home/x3/directive/raw.hpp @@ -0,0 +1,70 @@ +/*============================================================================= + 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) +=============================================================================*/ +#if !defined(SPIRIT_X3_RAW_APRIL_9_2007_0912AM) +#define SPIRIT_X3_RAW_APRIL_9_2007_0912AM + +#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/range/iterator_range.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 = Subject::handles_container; + typedef Subject subject_type; + + 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> + raw_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + raw_gen const raw = raw_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/skip.hpp b/boost/spirit/home/x3/directive/skip.hpp new file mode 100644 index 0000000000..c880720791 --- /dev/null +++ b/boost/spirit/home/x3/directive/skip.hpp @@ -0,0 +1,124 @@ +/*============================================================================= + 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(SPIRIT_SKIP_JANUARY_26_2008_0422PM) +#define SPIRIT_SKIP_JANUARY_26_2008_0422PM + +#if defined(_MSC_VER) +#pragma once +#endif + +#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; + + 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; + + 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 + { + explicit skip_gen(Skipper const& skipper) + : skipper_(skipper) {} + + template <typename Subject> + 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> + skip_gen<Skipper> const operator()(Skipper const& skipper) const + { + return skip_gen<Skipper>(skipper); + } + + template <typename Subject> + reskip_directive<typename extension::as_parser<Subject>::value_type> + operator[](Subject const& subject) const + { + return {as_parser(subject)}; + } + }; + + reskip_gen const skip = reskip_gen(); +}}} + +#endif diff --git a/boost/spirit/home/x3/directive/with.hpp b/boost/spirit/home/x3/directive/with.hpp new file mode 100644 index 0000000000..cc6c442a34 --- /dev/null +++ b/boost/spirit/home/x3/directive/with.hpp @@ -0,0 +1,107 @@ +/*============================================================================= + 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) +=============================================================================*/ +#if !defined(SPIRIT_X3_WITH_MAY_02_2014_0749AM) +#define SPIRIT_X3_WITH_MAY_02_2014_0749AM + +#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; + with_value_holder(Subject const& subject, T const& val) + : base_type(subject) + , val(val) {} + }; + + template <typename Subject, typename Derived, typename T> + struct with_value_holder<Subject, Derived, T const> + : unary_parser<Subject, Derived> + { + typedef unary_parser<Subject, Derived> base_type; + T val; + with_value_holder(Subject const& subject, T const& 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; + + with_directive(Subject const& subject, T const& val) + : base_type(subject, 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, typename NextContext = unused_type> + struct with_context + { + typedef context<ID, T, NextContext> type; + }; + + template <typename ID, typename T> + struct with_context<ID, T, unused_type> + { + typedef context<ID, T> const type; + }; + + template <typename ID, typename T> + struct with_gen + { + T& val; + + with_gen(T& val) + : val(val) {} + + template <typename Subject> + with_directive<typename extension::as_parser<Subject>::value_type, ID, T> + operator[](Subject const& subject) const + { + return {as_parser(subject), val}; + } + }; + + template <typename ID, typename T> + inline with_gen<ID, T> with(T& val) + { + return with_gen<ID, T>{val}; + } + + template <typename ID, typename T> + inline with_gen<ID, T const> with(T const& val) + { + return with_gen<ID, T const>{val}; + } +}}} + +#endif |