annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/operator/difference.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3
Chris@16 4 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 =============================================================================*/
Chris@16 7 #if !defined(SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM)
Chris@16 8 #define SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/qi/domain.hpp>
Chris@16 15 #include <boost/spirit/home/qi/meta_compiler.hpp>
Chris@16 16 #include <boost/spirit/home/qi/parser.hpp>
Chris@16 17 #include <boost/spirit/home/qi/detail/attributes.hpp>
Chris@16 18 #include <boost/spirit/home/support/info.hpp>
Chris@16 19 #include <boost/spirit/home/support/has_semantic_action.hpp>
Chris@16 20 #include <boost/spirit/home/support/handles_container.hpp>
Chris@16 21 #include <boost/fusion/include/at.hpp>
Chris@16 22
Chris@16 23 namespace boost { namespace spirit
Chris@16 24 {
Chris@16 25 ///////////////////////////////////////////////////////////////////////////
Chris@16 26 // Enablers
Chris@16 27 ///////////////////////////////////////////////////////////////////////////
Chris@16 28 template <>
Chris@16 29 struct use_operator<qi::domain, proto::tag::minus> // enables -
Chris@16 30 : mpl::true_ {};
Chris@16 31 }}
Chris@16 32
Chris@16 33 namespace boost { namespace spirit { namespace qi
Chris@16 34 {
Chris@16 35 template <typename Left, typename Right>
Chris@16 36 struct difference : binary_parser<difference<Left, Right> >
Chris@16 37 {
Chris@16 38 typedef Left left_type;
Chris@16 39 typedef Right right_type;
Chris@16 40
Chris@16 41 template <typename Context, typename Iterator>
Chris@16 42 struct attribute
Chris@16 43 {
Chris@16 44 typedef typename
Chris@16 45 traits::attribute_of<left_type, Context, Iterator>::type
Chris@16 46 type;
Chris@16 47 };
Chris@16 48
Chris@16 49 difference(Left const& left_, Right const& right_)
Chris@16 50 : left(left_), right(right_) {}
Chris@16 51
Chris@16 52 template <typename Iterator, typename Context
Chris@16 53 , typename Skipper, typename Attribute>
Chris@16 54 bool parse(Iterator& first, Iterator const& last
Chris@16 55 , Context& context, Skipper const& skipper
Chris@16 56 , Attribute& attr_) const
Chris@16 57 {
Chris@16 58 // Unlike classic Spirit, with this version of difference, the rule
Chris@16 59 // lit("policeman") - "police" will always fail to match.
Chris@16 60
Chris@16 61 // Spirit2 does not count the matching chars while parsing and
Chris@16 62 // there is no reliable and fast way to check if the LHS matches
Chris@16 63 // more than the RHS.
Chris@16 64
Chris@16 65 // Try RHS first
Chris@16 66 Iterator start = first;
Chris@16 67 if (right.parse(first, last, context, skipper, unused))
Chris@16 68 {
Chris@16 69 // RHS succeeds, we fail.
Chris@16 70 first = start;
Chris@16 71 return false;
Chris@16 72 }
Chris@16 73 // RHS fails, now try LHS
Chris@16 74 return left.parse(first, last, context, skipper, attr_);
Chris@16 75 }
Chris@16 76
Chris@16 77 template <typename Context>
Chris@16 78 info what(Context& context) const
Chris@16 79 {
Chris@16 80 return info("difference",
Chris@16 81 std::make_pair(left.what(context), right.what(context)));
Chris@16 82 }
Chris@16 83
Chris@16 84 Left left;
Chris@16 85 Right right;
Chris@16 86 };
Chris@16 87
Chris@16 88 ///////////////////////////////////////////////////////////////////////////
Chris@16 89 // Parser generators: make_xxx function (objects)
Chris@16 90 ///////////////////////////////////////////////////////////////////////////
Chris@16 91 template <typename Elements, typename Modifiers>
Chris@16 92 struct make_composite<proto::tag::minus, Elements, Modifiers>
Chris@16 93 : make_binary_composite<Elements, difference>
Chris@16 94 {};
Chris@16 95 }}}
Chris@16 96
Chris@16 97 namespace boost { namespace spirit { namespace traits
Chris@16 98 {
Chris@16 99 ///////////////////////////////////////////////////////////////////////////
Chris@16 100 template <typename Left, typename Right>
Chris@16 101 struct has_semantic_action<qi::difference<Left, Right> >
Chris@16 102 : binary_has_semantic_action<Left, Right> {};
Chris@16 103
Chris@16 104 ///////////////////////////////////////////////////////////////////////////
Chris@16 105 template <typename Left, typename Right, typename Attribute
Chris@16 106 , typename Context, typename Iterator>
Chris@16 107 struct handles_container<qi::difference<Left, Right>, Attribute, Context
Chris@16 108 , Iterator>
Chris@16 109 : binary_handles_container<Left, Right, Attribute, Context, Iterator> {};
Chris@16 110 }}}
Chris@16 111
Chris@16 112 #endif