Parsing a set number of repetitions

Sebastian Gsänger <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hi,

I'm struggling to find a satisfying solution for this seemingly simple 
problem:
Given a number of repetitions to follow, i want the parser to succeed 
only if this number is matched exactly.
I tried the following, which succesfully fails if there are too little 
occurences:

steps = step % +qi::eol;
step  = qi::omit[qi::int_[qi::_a = qi::_1] > qi::eol]
         > atoms(qi::_a);
atoms = qi::repeat(qi::_r1)[qi::eol > atom];

With too many atoms, it parses the first step, fails the second and ends.
In this specific case, i could rewrite the steps-rule to be more 
explicit in it's expectations, but i'd like to reuse this concept for 
formats where this is not possible.
Is there a way to fail the 'step' rule inside of itself given a mismatch 
of 'qi::_a' and the size of the parsed vector?
I also tried to use phoenix, as in:

steps = step % +qi::eol;
step  = qi::omit[qi::int_[qi::_a = qi::_1] > qi::eol]
         > atoms[qi::_b = phx::stl::size(qi::_1)]
         > qi::eps(qi::_a == qi::_b)
atoms = atom % qi::eol;

This does not compile though:
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note: 
candidate: constexpr boost::phoenix::stl::size::size()
          struct size
                 ^~~~
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note:   
candidate expects 0 arguments, 1 provided
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note: 
candidate: constexpr boost::phoenix::stl::size::size(const 
boost::phoenix::stl::size&)
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note:   
no known conversion for argument 1 from 'const _1_type {aka const 
boost::phoenix::actor<boost::spirit::argument<0> >}' to 'const 
boost::phoenix::stl::size&'
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note: 
candidate: constexpr 
boost::phoenix::stl::size::size(boost::phoenix::stl::size&&)
/usr/include/boost/phoenix/stl/container/container.hpp:735:16: note:   
no known conversion for argument 1 from 'const _1_type {aka const 
boost::phoenix::actor<boost::spirit::argument<0> >}' to 
'boost::phoenix::stl::size&&'

What am i missing?

Thank you,
Sebastian

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.