📄 composite.hpp
字号:
/*=============================================================================
Composite parsers
Spirit V1.3.1
Copyright (c) 2001, Joel de Guzman
This software is provided 'as-is', without any express or implied
warranty. In no event will the copyright holder be held liable for
any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Acknowledgements:
Special thanks to Dan Nuffer, John (EBo) David, Chris Uzdavinis,
and Doug Gregor. These people are most instrumental in steering
Spirit in the right direction.
Special thanks also to people who have contributed to the code base
and sample code, ported Spirit to various platforms and compilers,
gave suggestions, reported and provided bug fixes. Alexander
Hirner, Andy Elvey, Bogdan Kushnir, Brett Calcott, Bruce Florman,
Changzhe Han, Colin McPhail, Hakki Dogusan, Jan Bares, Joseph
Smith, Martijn W. van der Lee, Raghavendra Satish, Remi Delcos, Tom
Spilman, Vladimir Prus, W. Scott Dillman, David A. Greene, Bob
Bailey, Hartmut Kaiser.
Finally special thanks also to people who gave feedback and
valuable comments, particularly members of Spirit's Source Forge
mailing list and boost.org.
URL: http://spirit.sourceforge.net/
=============================================================================*/
#ifndef SPIRIT_COMPOSITE_HPP
#define SPIRIT_COMPOSITE_HPP
///////////////////////////////////////////////////////////////////////////////
#include "boost/spirit/MSVC/ps_helper.hpp"
#include "boost/spirit/MSVC/rule.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace spirit {
///////////////////////////////////////////////////////////////////////////////
//
// embed_trait
//
// Typically, parser objects are embedded by value. The special
// case is the rule or others where a reference is stored instead.
//
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
////////////////////////////////////////////
template <int i>
struct embed_traits_transformer
{
template<typename T>
struct local {
typedef T embed_trait;
};
};
template <>
struct embed_traits_transformer<1>
{
template<typename T>
struct local {
typedef T const& embed_trait;
};
};
////////////////////////////////////////////
template<typename IteratorT, typename MatchTraitsT>
selector1
embed_traits_helper(const rule<IteratorT, MatchTraitsT> &);
template<typename IteratorT, typename MatchTraitsT ,typename DerivedT>
selector1
embed_traits_helper(const base_rule<IteratorT, MatchTraitsT, DerivedT> & );
template<typename CharT ,typename T ,typename SetT>
selector1
embed_traits_helper( symbols<CharT, T, SetT> const& );
template<typename ClosureT ,typename IteratorT ,typename MatchTraitsT>
selector1
embed_traits_helper( attr_rule<ClosureT, IteratorT, MatchTraitsT> const& );
template<typename ParserT ,typename IteratorT ,typename BaseT>
selector1
embed_traits_helper( list_action_iterator<ParserT, IteratorT, BaseT> const& );
selector2 embed_traits_helper(...);
template <int i>
struct embed_traits_array_diff
{
template<class T>
struct inner
{
typedef T embed_trait;
};
};
template <>
struct embed_traits_array_diff<0>
{
template<class T>
struct inner
{
static T t();
typedef typename
impl::embed_traits_transformer< sizeof(impl::embed_traits_helper(t())) >::
template local<T>::embed_trait embed_trait;
};
};
////////////////////////////////////////
} //end namespace impl
template <typename T>
struct embed_trait
{
typedef impl::embed_traits_array_diff<boost::is_array<T>::value> helper_type;
typedef typename
helper_type::
template inner<T>::embed_trait type;
};
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// unary class.
//
// Class composed of a single subject.
//
///////////////////////////////////////////////////////////////////////////////
template <typename S>
struct unary {
unary() : subj() {}
unary(S const& subj_) : subj(subj_) {}
S& subject() { return subj; }
S const& subject() const { return subj; }
private:
typename embed_trait<S>::type subj;
};
///////////////////////////////////////////////////////////////////////////////
//
// binary class.
//
// Class composed of a pair.
//
///////////////////////////////////////////////////////////////////////////////
template <typename A, typename B>
struct binary {
binary() {}
binary(A const& a_, B const& b_)
:a(a_), b(b_) {}
A& left() { return a; }
A const& left() const { return a; }
B& right() { return b; }
B const& right() const { return b; }
//support for longest and shortest
typedef A TypeA;
typedef B TypeB;
private:
typename embed_trait<A>::type a;
typename embed_trait<B>::type b;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace Spirit
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -