📄 rule.ipp
字号:
return right.ast_parse(first, last, mt);
}
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// rule class implementation.
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>::base_rule()
: meta(0) {}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>::~base_rule()
{
delete meta;
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>
::base_rule(base_rule const& other)
: parser<DerivedT>()
, meta(new impl::rule_alias<IteratorT, MatchTraitsT, DerivedT>(other))
{
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
template <typename ParserT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>
::base_rule(ParserT const& parser)
: meta(new impl::concrete_parser<ParserT, IteratorT, MatchTraitsT>(parser))
{
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>&
base_rule<IteratorT, MatchTraitsT, DerivedT>
::operator = (base_rule<IteratorT, MatchTraitsT, DerivedT> const& other)
{
if (this != &other)
{
if (meta == 0)
meta = new impl::rule_alias<IteratorT, MatchTraitsT, DerivedT>(other);
else
meta = new impl::alt_parser<DerivedT, IteratorT, MatchTraitsT>(meta,
other);
}
return *this;
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
template <typename ParserT>
inline base_rule<IteratorT, MatchTraitsT, DerivedT>&
base_rule<IteratorT, MatchTraitsT, DerivedT>
::operator = (ParserT const& parser)
{
if (meta == 0)
meta = new impl::concrete_parser<ParserT, IteratorT, MatchTraitsT>(
parser);
else
meta = new impl::alt_parser<ParserT, IteratorT, MatchTraitsT>(meta,
parser);
return *this;
}
//////////////////////////////////
#ifdef SPIRIT_DEBUG
template <typename IteratorT>
void
print_rule_info(
bool hit,
int level,
bool close,
std::string const& name,
IteratorT first,
IteratorT last)
{
if (!name.empty())
{
for (int i = 0; i < level; ++i)
SPIRIT_DEBUG_OUT << " ";
if (close)
{
if (hit)
SPIRIT_DEBUG_OUT << "/";
else
SPIRIT_DEBUG_OUT << "#";
}
SPIRIT_DEBUG_OUT << name << ":\t\"";
typedef impl::strip_scanner<IteratorT> strip_scanner;
typename strip_scanner::iterator_type
iter = strip_scanner::get(first);
typename strip_scanner::iterator_type
ilast = strip_scanner::get(last);
for (int j = 0; j < 20; ++j)
{
if (iter == ilast)
break;
switch (*iter) {
case '\r': SPIRIT_DEBUG_OUT << "\\r"; break;
case '\n': SPIRIT_DEBUG_OUT << "\\n"; break;
default: SPIRIT_DEBUG_OUT << *iter; break;
}
++iter;
}
SPIRIT_DEBUG_OUT << " \"\n";
}
}
#endif
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline match
base_rule<IteratorT, MatchTraitsT, DerivedT>::parse(IteratorT& first,
IteratorT const& last) const
{
#if defined(SPIRIT_DEBUG) && (SPIRIT_DEBUG_LEVEL >= SPIRIT_DEBUG_LEVEL_LEVEL2)
print_rule_info(false, debug.level, false, debug.name(), first, last);
int save_level = debug.level;
debug.level++;
match hit = meta ? meta->parse(first, last) : match();
debug.level = save_level;
print_rule_info(hit, debug.level, true, debug.name(), first, last);
return hit;
#else
return meta ? meta->parse(first, last) : match();
#endif
}
template <typename IteratorT, typename MatchTraitsT, typename DerivedT>
inline typename MatchTraitsT::match_t
base_rule<IteratorT, MatchTraitsT, DerivedT>::ast_parse(IteratorT& first,
IteratorT const& last, MatchTraitsT const& mt) const
{
#ifdef SPIRIT_DEBUG
print_rule_info(false, debug.level, false, debug.name(), first, last);
int save_level = debug.level;
debug.level++;
typename MatchTraitsT::match_t hit;
if (meta)
{
hit = meta->ast_parse(first, last, mt);
MatchTraitsT::set_id_and_group(hit, this);
}
else
{
hit = MatchTraitsT::no_match;
}
debug.level = save_level;
print_rule_info(hit, debug.level, true, debug.name(), first, last);
return hit;
#else
if (meta)
{
typename MatchTraitsT::match_t hit = meta->ast_parse(first, last, mt);
MatchTraitsT::set_id_and_group(hit, this);
return hit;
}
else
{
return MatchTraitsT::no_match;
}
#endif
}
template <typename IteratorT, typename MatchTraitsT>
inline rule<IteratorT, MatchTraitsT>::rule()
{
}
template <typename IteratorT, typename MatchTraitsT>
inline rule<IteratorT, MatchTraitsT>::rule(rule const& other) :
base_rule<IteratorT, MatchTraitsT, rule<IteratorT, MatchTraitsT> >(other)
{
}
template <typename IteratorT, typename MatchTraitsT>
template <typename ParserT>
inline rule<IteratorT, MatchTraitsT>::rule(ParserT const& parser) :
base_rule<IteratorT, MatchTraitsT, rule<IteratorT, MatchTraitsT> >(parser)
{
}
template <typename IteratorT, typename MatchTraitsT>
inline rule<IteratorT, MatchTraitsT>&
rule<IteratorT, MatchTraitsT>::operator = (rule const& other)
{
if (this != &other)
*static_cast<base_rule_t *>(this) = other;
return *this;
}
template <typename IteratorT, typename MatchTraitsT>
template <typename ParserT>
inline rule<IteratorT, MatchTraitsT>&
rule<IteratorT, MatchTraitsT>::operator=(ParserT const& parser)
{
*static_cast<base_rule_t *>(this) = parser;
return *this;
}
///////////////////////////////////////////////////////////////////////////////
//
// skipper class implementation.
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename MatchTraitsT>
template <typename ParserT>
inline skipper<IteratorT, MatchTraitsT>::skipper(
ParserT const& skip_rule_,
IteratorT const& last_)
:
last(last_),
skip_rule(skip_rule_)
{
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT>
inline skipper<IteratorT, MatchTraitsT>::skipper(IteratorT const& last_)
:
last(last_),
skip_rule(space)
{
}
//////////////////////////////////
template <typename IteratorT, typename MatchTraitsT>
inline void
skipper<IteratorT, MatchTraitsT>::skip(IteratorT& current) const
{
while (skip_rule.parse(current, last))
{}
}
///////////////////////////////////////////////////////////////////////////////
} // namespace Spirit
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -