tzlaine / parser

A C++ parser combinator library.
Boost Software License 1.0
81 stars 12 forks source link

parsing to `vector<aggregate>` doesn't work #47

Closed akrzemi1 closed 9 months ago

akrzemi1 commented 9 months ago

While https://github.com/tzlaine/parser/issues/28 fixes the parsing into a single aggregate, parsing to a vector of aggregates still doesn't work.

The following fails to compile.

#include <boost/parser/parser.hpp>
#include <vector>

struct X
{
  char a;
  int b;
};

int main()
{
  namespace bp = boost::parser;
  auto pair = bp::char_ >> bp::int_;
  auto pairs = +pair;

  std::vector<X> x;
  auto b = bp::parse("d 3", pairs, bp::ws, x);  
}

The analogous code in Boost.Spirit works:

#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/spirit/include/qi.hpp>

struct X
{
  char a;
  int b;
};

BOOST_FUSION_ADAPT_STRUCT(X, a, b);

int main()
{
  namespace bp = boost::spirit::qi;
  auto pair = bp::char_ >> bp::int_;
  auto pairs = +pair;

  std::vector<X> x;
  std::string input = "d 3 c 4";
  auto begin = input.begin();
  bool b = bp::phrase_parse(begin, input.end(), pairs, bp::ascii::space, x);
}
tzlaine commented 9 months ago

Thanks. I'll have a look.