Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003     Copyright (c) 2001-2011 Hartmut Kaiser
0004     Copyright (c)      2010 Bryce Lelbach
0005 
0006     Distributed under the Boost Software License, Version 1.0. (See accompanying
0007     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #ifndef BOOST_SPIRIT_QI_DIRECTIVE_AS_HPP
0010 #define BOOST_SPIRIT_QI_DIRECTIVE_AS_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/spirit/home/qi/meta_compiler.hpp>
0017 #include <boost/spirit/home/qi/skip_over.hpp>
0018 #include <boost/spirit/home/qi/parser.hpp>
0019 #include <boost/spirit/home/qi/detail/assign_to.hpp>
0020 #include <boost/spirit/home/support/unused.hpp>
0021 #include <boost/spirit/home/support/info.hpp>
0022 #include <boost/spirit/home/support/common_terminals.hpp>
0023 #include <boost/spirit/home/support/unused.hpp>
0024 #include <boost/spirit/home/support/has_semantic_action.hpp>
0025 #include <boost/spirit/home/support/handles_container.hpp>
0026 #include <boost/spirit/home/support/assert_msg.hpp>
0027 #include <boost/spirit/home/support/container.hpp>
0028 
0029 namespace boost { namespace spirit { namespace qi
0030 {
0031     template <typename T>
0032     struct as
0033       : stateful_tag_type<T, tag::as>
0034     {
0035         //~ BOOST_SPIRIT_ASSERT_MSG(
0036             //~ (traits::is_container<T>::type::value),
0037             //~ error_type_must_be_a_container,
0038             //~ (T));
0039     };
0040 }}}
0041 
0042 namespace boost { namespace spirit
0043 {
0044     ///////////////////////////////////////////////////////////////////////////
0045     // Enablers
0046     ///////////////////////////////////////////////////////////////////////////
0047     // enables as_string[...]
0048     template <>
0049     struct use_directive<qi::domain, tag::as_string>
0050       : mpl::true_ {};
0051 
0052     // enables as_wstring[...]
0053     template <>
0054     struct use_directive<qi::domain, tag::as_wstring>
0055       : mpl::true_ {};
0056 
0057     // enables as<T>[...]
0058     template <typename T>
0059     struct use_directive<qi::domain, tag::stateful_tag<T, tag::as> >
0060       : mpl::true_
0061     {};
0062 }}
0063 
0064 namespace boost { namespace spirit { namespace qi
0065 {
0066 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0067     using spirit::as_string;
0068     using spirit::as_wstring;
0069 #endif
0070     using spirit::as_string_type;
0071     using spirit::as_wstring_type;
0072 
0073     template <typename Subject, typename T>
0074     struct as_directive : unary_parser<as_directive<Subject, T> >
0075     {
0076         typedef Subject subject_type;
0077         as_directive(Subject const& subject_)
0078           : subject(subject_) {}
0079 
0080         template <typename Context, typename Iterator>
0081         struct attribute
0082         {
0083             typedef T type;
0084         };
0085 
0086         template <typename Iterator, typename Context
0087           , typename Skipper, typename Attribute>
0088         bool parse(Iterator& first, Iterator const& last
0089           , Context& context, Skipper const& skipper, Attribute& attr_) const
0090         {
0091             Iterator i = first;
0092             T as_attr;
0093             if (subject.parse(i, last, context, skipper, as_attr))
0094             {
0095                 spirit::traits::assign_to(as_attr, attr_);
0096                 first = i;
0097                 return true;
0098             }
0099             return false;
0100         }
0101 
0102         template <typename Iterator, typename Context, typename Skipper>
0103         bool parse(Iterator& first, Iterator const& last
0104           , Context& context, Skipper const& skipper, T& attr_) const
0105         {
0106             Iterator i = first;
0107             if (subject.parse(i, last, context, skipper, attr_))
0108             {
0109                 first = i;
0110                 return true;
0111             }
0112             return false;
0113         }
0114 
0115         template <typename Context>
0116         info what(Context& context) const
0117         {
0118             return info("as", subject.what(context));
0119         }
0120 
0121         Subject subject;
0122     };
0123 
0124     ///////////////////////////////////////////////////////////////////////////
0125     // Parser generators: make_xxx function (objects)
0126     ///////////////////////////////////////////////////////////////////////////
0127     template <typename Subject, typename Modifiers>
0128     struct make_directive<tag::as_string, Subject, Modifiers>
0129     {
0130         typedef as_directive<Subject, std::string> result_type;
0131         result_type operator()(unused_type, Subject const& subject
0132           , unused_type) const
0133         {
0134             return result_type(subject);
0135         }
0136     };
0137 
0138     template <typename Subject, typename Modifiers>
0139     struct make_directive<tag::as_wstring, Subject, Modifiers>
0140     {
0141         typedef as_directive<Subject, std::basic_string<wchar_t> > result_type;
0142         result_type operator()(unused_type, Subject const& subject
0143           , unused_type) const
0144         {
0145             return result_type(subject);
0146         }
0147     };
0148 
0149     template <typename T, typename Subject, typename Modifiers>
0150     struct make_directive<tag::stateful_tag<T, tag::as>, Subject, Modifiers>
0151     {
0152         typedef as_directive<Subject, T> result_type;
0153         result_type operator()(unused_type, Subject const& subject
0154           , unused_type) const
0155         {
0156             return result_type(subject);
0157         }
0158     };
0159 }}}
0160 
0161 namespace boost { namespace spirit { namespace traits
0162 {
0163     ///////////////////////////////////////////////////////////////////////////
0164     template <typename Subject, typename T>
0165     struct has_semantic_action<qi::as_directive<Subject, T> >
0166       : unary_has_semantic_action<Subject> {};
0167 
0168     ///////////////////////////////////////////////////////////////////////////
0169     template <typename Subject, typename T, typename Attribute
0170         , typename Context, typename Iterator>
0171     struct handles_container<qi::as_directive<Subject, T>, Attribute
0172         , Context, Iterator>
0173       : mpl::false_ {};
0174 }}}
0175 
0176 #endif