📄 symbols.ipp
字号:
/*=============================================================================
Symbol Tables
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_SYMBOLS_IPP
#define SPIRIT_SYMBOLS_IPP
///////////////////////////////////////////////////////////////////////////////
#include "boost/spirit/MSVC/symbols.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace spirit {
//////////////////////////////////
template <typename T, typename CharT>
inline tst<T, CharT>::tst()
: root(0)
{
}
//////////////////////////////////
template <typename T, typename CharT>
inline tst<T, CharT>::tst(tst const& other)
: root(other.root->clone())
{
}
//////////////////////////////////
template <typename T, typename CharT>
inline tst<T, CharT>::~tst()
{
delete root;
}
//////////////////////////////////
template <typename T, typename CharT>
inline tst<T, CharT>&
tst<T, CharT>::operator=(tst const& other)
{
if (this != &other)
{
node* new_root = other.root->clone();
delete root;
root = new_root;
}
return *this;
}
///////////////////////////////////////////////////////////////////////////////
//
// symbol_match class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename T>
inline symbol_match<T>::symbol_match()
: match(),
info(0)
{
}
//////////////////////////////////
template <typename T>
inline symbol_match<T>::symbol_match(unsigned length, T* info_)
: match(length),
info(info_)
{
}
//////////////////////////////////
template <typename T>
inline T*
symbol_match<T>::data() const
{
return info;
}
///////////////////////////////////////////////////////////////////////////////
//
// ast_symbol_match class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename MatchTraitsT, typename T>
inline ast_symbol_match<MatchTraitsT, T>::ast_symbol_match()
: MatchTraitsT::match_t(),
info(0)
{
}
//////////////////////////////////
template <typename MatchTraitsT, typename T>
inline ast_symbol_match<MatchTraitsT, T>::ast_symbol_match(unsigned length,
T* info_)
: MatchTraitsT::match_t(length),
info(info_)
{
}
//////////////////////////////////
template <typename MatchTraitsT, typename T>
inline T*
ast_symbol_match<MatchTraitsT, T>::data() const
{
return info;
}
///////////////////////////////////////////////////////////////////////////////
//
// symbol_inserter class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename T, typename SetT>
symbol_inserter<T, SetT>::symbol_inserter(SetT& set_)
: set(set_)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// symbol_action class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename ActionT>
inline symbol_action<ParserT, ActionT>::symbol_action(
ParserT const& parser_,
ActionT const& actor_)
: unary<ParserT>(parser_),
actor(actor_)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// symbols class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline symbols<T, CharT, SetT>::symbols()
: tst<T, CharT>(),
add(*this)
{
}
//////////////////////////////////
template <typename T, typename CharT, typename SetT>
symbols<T, CharT, SetT>::symbols(symbols const& other)
: tst<T, CharT>(other)
, parser<symbols<T, CharT, SetT> >()
, add(*this)
{
}
//////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline symbols<T, CharT, SetT>::~symbols()
{
}
//////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline symbols<T, CharT, SetT>&
symbols<T, CharT, SetT>::operator=(symbols const& other)
{
tst<T, CharT>::operator=(other);
return *this;
}
//////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline symbol_inserter<T, SetT> const&
symbols<T, CharT, SetT>::operator=(CharT const* str)
{
return add, str;
}
///////////////////////////////////////////////////////////////////////////////
//
// Symbol table utilities
//
///////////////////////////////////////////////////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline T*
find(symbols<T, CharT, SetT>& table, CharT const* sym)
{
CharT const* last = sym;
while (*last)
last++;
return table.parse(sym, last).info();
}
//////////////////////////////////
template <typename T, typename CharT, typename SetT>
inline T*
add(symbols<T, CharT, SetT>& table, CharT const* sym, T const& data)
{
CharT const* last = sym;
while (*last)
last++;
return table.add(sym, last, data);
}
///////////////////////////////////////////////////////////////////////////////
} // namespace Spirit
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -