...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The seek[]
parser-directive skips all input until the subject parser matches. On failure,
the current position is the end of the input.
// forwards to <boost/spirit/repository/home/qi/directive/seek.hpp> #include <boost/spirit/repository/include/qi_seek.hpp>
Also, see Include Structure.
Name |
---|
|
Notation
a
A Parser
.
Semantics of an expression is defined only where it differs from, or is
not defined in UnaryParser
.
Expression |
Semantics |
---|---|
|
Advances until the parser |
See Compound Attribute Notation.
Expression |
Attribute |
---|---|
|
a: A --> seek[a]: A a: Unused --> seek[a]: Unused
|
The complexity is defined by the complexity of the subject parser,
a
The following example shows a simple use case of the seek[]
directive, seeking all the ints preceding
by '#'
. (For the full source
of the example, see seek.cpp)
Some namespace aliases:
namespace qi = boost::spirit::qi; namespace ka = boost::spirit::karma; namespace repo = boost::spirit::repository;
The input iterators and the attribute to store the result:
iterator it = line.begin(); iterator end = line.end(); std::vector<int> val;
Parsing and showing the result:
if (qi::phrase_parse(it, end, +repo::qi::seek["#" >> qi::int_], qi::space, val)) { std::cout << "-------------------------------- \n"; std::cout << "Parsing succeeded, got: " << ka::format("[ " << ka::int_ % ", " << " ]\n", val); std::cout << "---------------------------------\n"; }
Input:
1 will not be outputted while #2, ##3 and # 4 will.
Output:
-------------------------------- Parsing succeeded, got: [ 2, 3, 4 ] ---------------------------------