Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:46

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #ifndef BOOST_SPIRIT_QI_OPERATOR_DIFFERENCE_HPP
0008 #define BOOST_SPIRIT_QI_OPERATOR_DIFFERENCE_HPP
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/qi/domain.hpp>
0015 #include <boost/spirit/home/qi/meta_compiler.hpp>
0016 #include <boost/spirit/home/qi/parser.hpp>
0017 #include <boost/spirit/home/qi/detail/attributes.hpp>
0018 #include <boost/spirit/home/support/info.hpp>
0019 #include <boost/spirit/home/support/has_semantic_action.hpp>
0020 #include <boost/spirit/home/support/handles_container.hpp>
0021 #include <boost/fusion/include/at.hpp>
0022 #include <boost/proto/operators.hpp>
0023 #include <boost/proto/tags.hpp>
0024 
0025 namespace boost { namespace spirit
0026 {
0027     ///////////////////////////////////////////////////////////////////////////
0028     // Enablers
0029     ///////////////////////////////////////////////////////////////////////////
0030     template <>
0031     struct use_operator<qi::domain, proto::tag::minus> // enables -
0032       : mpl::true_ {};
0033 }}
0034 
0035 namespace boost { namespace spirit { namespace qi
0036 {
0037     template <typename Left, typename Right>
0038     struct difference : binary_parser<difference<Left, Right> >
0039     {
0040         typedef Left left_type;
0041         typedef Right right_type;
0042 
0043         template <typename Context, typename Iterator>
0044         struct attribute
0045         {
0046             typedef typename
0047                 traits::attribute_of<left_type, Context, Iterator>::type
0048             type;
0049         };
0050 
0051         difference(Left const& left_, Right const& right_)
0052           : left(left_), right(right_) {}
0053 
0054         template <typename Iterator, typename Context
0055           , typename Skipper, typename Attribute>
0056         bool parse(Iterator& first, Iterator const& last
0057           , Context& context, Skipper const& skipper
0058           , Attribute& attr_) const
0059         {
0060             // Unlike classic Spirit, with this version of difference, the rule
0061             // lit("policeman") - "police" will always fail to match.
0062 
0063             // Spirit2 does not count the matching chars while parsing and
0064             // there is no reliable and fast way to check if the LHS matches
0065             // more than the RHS.
0066 
0067             // Try RHS first
0068             Iterator start = first;
0069             if (right.parse(first, last, context, skipper, unused))
0070             {
0071                 // RHS succeeds, we fail.
0072                 first = start;
0073                 return false;
0074             }
0075             // RHS fails, now try LHS
0076             return left.parse(first, last, context, skipper, attr_);
0077         }
0078 
0079         template <typename Context>
0080         info what(Context& context) const
0081         {
0082             return info("difference",
0083                 std::make_pair(left.what(context), right.what(context)));
0084         }
0085 
0086         Left left;
0087         Right right;
0088     };
0089 
0090     ///////////////////////////////////////////////////////////////////////////
0091     // Parser generators: make_xxx function (objects)
0092     ///////////////////////////////////////////////////////////////////////////
0093     template <typename Elements, typename Modifiers>
0094     struct make_composite<proto::tag::minus, Elements, Modifiers>
0095       : make_binary_composite<Elements, difference>
0096     {};
0097 }}}
0098 
0099 namespace boost { namespace spirit { namespace traits
0100 {
0101     ///////////////////////////////////////////////////////////////////////////
0102     template <typename Left, typename Right>
0103     struct has_semantic_action<qi::difference<Left, Right> >
0104       : binary_has_semantic_action<Left, Right> {};
0105 
0106     ///////////////////////////////////////////////////////////////////////////
0107     template <typename Left, typename Right, typename Attribute
0108       , typename Context, typename Iterator>
0109     struct handles_container<qi::difference<Left, Right>, Attribute, Context
0110       , Iterator>
0111       : binary_handles_container<Left, Right, Attribute, Context, Iterator> {};
0112 }}}
0113 
0114 #endif