Listing 4: The sequence class
// Copyright (c) 2001, Joel de Guzman and Dan Nuffer
// Permission is granted to use this code without restriction as
// long as this copyright notice appears in all source files.
template <typename A, typename B>
struct sequence
: public binary<A, B>
, public parser<sequence<A, B> >
{
sequence(A const& a, B const& b)
: binary<A, B>(a, b) {}
template <typename IteratorT>
match parse(IteratorT& first, IteratorT const& last) const
{
IteratorT s = first;
match ma, mb;
if ((ma = this->left().parse(s, last)) &&
(mb = this->right().parse(s, last)))
{
first = s;
return ma + mb;
}
return match();
}
};