📄 utilities.ipp
字号:
template <typename ParserT, typename IteratorT, typename BaseT>
inline list_action_iterator<ParserT, IteratorT, BaseT>
list_action_iterator<ParserT, IteratorT, BaseT>::operator++ (int)
{
list_action_iterator<ParserT, IteratorT, BaseT> tmp = *this;
read();
return tmp;
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline bool
list_action_iterator<ParserT, IteratorT, BaseT>::operator== (
list_action_iterator<ParserT, IteratorT, BaseT> const &rhs) const
{
return (current == rhs.current &&
last == rhs.last &&
end_marker == rhs.end_marker) ||
(end_marker && rhs.end_marker);
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline bool
list_action_iterator<ParserT, IteratorT, BaseT>::operator!= (
list_action_iterator<ParserT, IteratorT, BaseT> const &rhs) const
{
return !(*this == rhs);
}
///////////////////////////////////////////////////////////////////////////////
// functions required for parser integration
template <typename ParserT, typename IteratorT, typename BaseT>
inline IteratorT const &
list_action_iterator<ParserT, IteratorT, BaseT>::actposition() const
{
return current;
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline bool
list_action_iterator<ParserT, IteratorT, BaseT>::matched() const
{
return saw_oneitem;
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline void
list_action_iterator<ParserT, IteratorT, BaseT>::operator() (
IteratorT const &begin_match, IteratorT const &end_match) const
{
value = BaseT(begin_match, end_match-begin_match);
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline void
list_action_iterator<ParserT, IteratorT, BaseT>::operator() (
typename spirit::iterator_traits<IteratorT>::value_type const &match_) const
{
value += match_;
}
template <typename ParserT, typename IteratorT, typename BaseT>
inline ParserT const &
list_action_iterator<ParserT, IteratorT, BaseT>::subject() const
{
assert(0 != parser);
return *parser;
}
///////////////////////////////////////////////////////////////////////////////
// get the next item from the parsed list
namespace impl {
template <typename CategoryT>
struct list_action_parser_type;
///////////////////////////////////////////////////////////////////////////////
// There is nothing special for plain_parser_category types as ItemT.
template <>
struct list_action_parser_type<plain_parser_category>
{
template <typename ActionIterT, typename ParserT, typename IteratorT>
static match read_item (
ActionIterT const &list_action_it, ParserT const &subject,
IteratorT ¤t, IteratorT const &last)
{
return (
*(subject.item_p() - (subject.delim_p() | subject.end_p()))
)[list_action_it].parse(current, last);
}
};
///////////////////////////////////////////////////////////////////////////////
// action_parser_category types as ItemT require some special handling
template <>
struct list_action_parser_type<action_parser_category>
{
template <typename ActionIterT, typename ParserT, typename IteratorT>
static match read_item (
ActionIterT const &list_action_it, ParserT const &subject,
IteratorT ¤t, IteratorT const &last)
{
return (
(*(subject.item_p().subject()
- (subject.delim_p() | subject.end_p())
) )[subject.item_p().predicate()]
)[list_action_it].parse(current, last);
}
};
} // end of namespace impl
template <typename ParserT, typename IteratorT, typename BaseT>
inline match
list_action_iterator<ParserT, IteratorT, BaseT>::read (bool firstread)
{
match hit;
if (!firstread) {
// match delimiter
hit = subject().delim_p().parse (current, last);
if (!hit) {
// try to match the 'end' sequence
end_marker = true;
return subject().end_p().parse(current, last);
}
}
// parse the next item
value.empty();
hit = impl::list_action_parser_type<ParserT::parser_category>
::read_item (*this, subject(), current, last);
if (!saw_oneitem)
saw_oneitem = hit;
end_marker = !hit;
return hit;
}
///////////////////////////////////////////////////////////////////////////////
//
// list_parser class
//
///////////////////////////////////////////////////////////////////////////////
namespace impl {
template <typename CategoryT>
struct list_parser_type;
///////////////////////////////////////////////////////////////////////////////
// There is nothing special for plain_parser_category types as ItemT.
template <>
struct list_parser_type<plain_parser_category>
{
// match list with 'normal' syntax
template <typename IteratorT, typename ItemT, typename DelimT>
static match
parse(IteratorT& first, IteratorT const& last,
ItemT const &item, DelimT const &delim)
{
return (
*(item - delim)
>> *(delim >> *(item - delim))
).parse(first, last);
}
// match list with 'extended' syntax
template <
typename IteratorT,
typename ItemT, typename DelimT, typename EndT
>
static match
parse(IteratorT& first, IteratorT const& last,
ItemT const &item, DelimT const &delim, EndT const &end)
{
return (
*(item - (delim | end))
>> *(delim >> *(item - (delim | end)))
>> !end
).parse(first, last);
}
};
///////////////////////////////////////////////////////////////////////////////
// action_parser_category types as ItemT require some special handling
template <>
struct list_parser_type<action_parser_category>
{
// match list with 'normal' syntax
template <typename IteratorT, typename ItemT, typename DelimT>
static match
parse(IteratorT& first, IteratorT const& last,
ItemT const &item, DelimT const &delim)
{
return (
*(item.subject() - delim)[item.predicate()]
>> *(delim >> *(item.subject() - delim)[item.predicate()])
).parse(first, last);
}
// match list with 'extended' syntax
template <
typename IteratorT,
typename ItemT, typename DelimT, typename EndT
>
static match
parse(IteratorT& first, IteratorT const& last,
ItemT const &item, DelimT const &delim, EndT const &end)
{
return (
*(item.subject() - (delim | end))[item.predicate()]
>> *(delim >> *(item.subject() - (delim | end))[
item.predicate()])
>> !end
).parse(first, last);
}
};
} // end of namespace impl
template <
typename ItemT, typename DelimT,
typename StringT, typename CategoryT
>
inline list_parser<ItemT, DelimT, StringT, CategoryT>
::list_parser(ItemT const &item_, const DelimT &delim_) :
item(item_),delim(delim_)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// list_parser_ex class
//
///////////////////////////////////////////////////////////////////////////////
template <
typename ItemT, typename DelimT, typename EndT,
typename StringT, typename CategoryT
>
inline list_parser_ex<ItemT, DelimT, EndT, StringT, CategoryT>
::list_parser_ex(ItemT const &item_, DelimT const &delim_,
EndT const &end_) :
item(item_), delim(delim_), end(end_)
{
}
} // namespace spirit
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -