PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/qi/operator/plus.hpp

http://hadesmem.googlecode.com/
C++ Header | 125 lines | 87 code | 18 blank | 20 comment | 3 complexity | 90c0114b1729b11363bd55930b2b18d5 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2011 Joel de Guzman
  3    Copyright (c) 2001-2011 Hartmut Kaiser
  4
  5    Distributed under the Boost Software License, Version 1.0. (See accompanying
  6    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7=============================================================================*/
  8#if !defined(SPIRIT_PLUS_MARCH_13_2007_0127PM)
  9#define SPIRIT_PLUS_MARCH_13_2007_0127PM
 10
 11#if defined(_MSC_VER)
 12#pragma once
 13#endif
 14
 15#include <boost/spirit/home/qi/meta_compiler.hpp>
 16#include <boost/spirit/home/qi/parser.hpp>
 17#include <boost/spirit/home/support/container.hpp>
 18#include <boost/spirit/home/qi/detail/attributes.hpp>
 19#include <boost/spirit/home/qi/detail/fail_function.hpp>
 20#include <boost/spirit/home/qi/detail/pass_container.hpp>
 21#include <boost/spirit/home/support/has_semantic_action.hpp>
 22#include <boost/spirit/home/support/handles_container.hpp>
 23#include <boost/spirit/home/support/info.hpp>
 24
 25namespace boost { namespace spirit
 26{
 27    ///////////////////////////////////////////////////////////////////////////
 28    // Enablers
 29    ///////////////////////////////////////////////////////////////////////////
 30    template <>
 31    struct use_operator<qi::domain, proto::tag::unary_plus> // enables +p
 32      : mpl::true_ {};
 33}}
 34
 35namespace boost { namespace spirit { namespace qi
 36{
 37    template <typename Subject>
 38    struct plus : unary_parser<plus<Subject> >
 39    {
 40        typedef Subject subject_type;
 41
 42        template <typename Context, typename Iterator>
 43        struct attribute
 44        {
 45            // Build a std::vector from the subject's attribute. Note
 46            // that build_std_vector may return unused_type if the
 47            // subject's attribute is an unused_type.
 48            typedef typename
 49                traits::build_std_vector<
 50                    typename traits::attribute_of<
 51                        Subject, Context, Iterator>::type
 52                >::type
 53            type;
 54        };
 55
 56        plus(Subject const& subject)
 57          : subject(subject) {}
 58
 59        template <typename F>
 60        bool parse_container(F f) const
 61        {
 62            // in order to succeed we need to match at least one element 
 63            if (f (subject))
 64                return false;
 65
 66            while (!f (subject))
 67                ;
 68            return true;
 69        }
 70
 71        template <typename Iterator, typename Context
 72          , typename Skipper, typename Attribute>
 73        bool parse(Iterator& first, Iterator const& last
 74          , Context& context, Skipper const& skipper
 75          , Attribute& attr) const
 76        {
 77            typedef detail::fail_function<Iterator, Context, Skipper>
 78                fail_function;
 79
 80            // ensure the attribute is actually a container type
 81            traits::make_container(attr);
 82
 83            Iterator iter = first;
 84            fail_function f(iter, last, context, skipper);
 85            if (!parse_container(detail::make_pass_container(f, attr)))
 86                return false;
 87
 88            first = f.first;
 89            return true;
 90        }
 91
 92        template <typename Context>
 93        info what(Context& context) const
 94        {
 95            return info("plus", subject.what(context));
 96        }
 97
 98        Subject subject;
 99    };
100
101    ///////////////////////////////////////////////////////////////////////////
102    // Parser generators: make_xxx function (objects)
103    ///////////////////////////////////////////////////////////////////////////
104    template <typename Elements, typename Modifiers>
105    struct make_composite<proto::tag::unary_plus, Elements, Modifiers>
106      : make_unary_composite<Elements, plus>
107    {};
108}}}
109
110namespace boost { namespace spirit { namespace traits
111{
112    ///////////////////////////////////////////////////////////////////////////
113    template <typename Subject>
114    struct has_semantic_action<qi::plus<Subject> >
115      : unary_has_semantic_action<Subject> {};
116
117    ///////////////////////////////////////////////////////////////////////////
118    template <typename Subject, typename Attribute, typename Context
119      , typename Iterator>
120    struct handles_container<qi::plus<Subject>, Attribute, Context
121          , Iterator>
122      : mpl::true_ {}; 
123}}}
124
125#endif