Re: Attribute propagation to semantic actions (Spirit Qi 2.5.2)
Anatol Zolotusky <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
Mario is right, thanks - one of the problems was the missing parenthesis. The other one was the expected type of v3 generated attribute - it's fusion::vector3, not fusion::tuple.
Sorry for the trouble
On Thursday, April 21, 2016 10:04 PM, Anatol Zolotusky <[email protected]> wrote:
I'm trying to call a semantic action upon parsing of a sequence of 3
strings, for which I defined void do_triple() function. (There are 2 other functions defined - for reasons explained below). I thought that the attribute type for the parser:
tripleExp = attrname >> predicate >> attrvalue
where each of the sequence members has attribute of std::string,
according to the attribute propagation rules, would have the type of
boost::fusion::tuple<std::string, std::string, std::string>
But NOOOO - the code as posted gives a compilation error:
/usr/include/boost/spirit/home/support/action_dispatch.hpp:204:19: error: could not convert ‘attr’ from ‘std::basic_string<char>’ to ‘boost::fusion::tuple<std::basic_string<char>, std::basic_string<char>, std::basic_string<char> >’
f(attr);
^
And of course, when I define the semantic action as do_string, it does
compile, and prints the last string in the expression. Which is of
course not what I want - I need all three (the do_vector doesn't
compile too).
What am I doing wrong, and how to fix this? (I read the post of 02/12
"Attribute Propagation and Attribute Compatibility" by Hartmut, but
still can't help my problem). Using Boost 1.55, Spirit 2.5.2
TIA,
--AZ
==============================
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/tuple.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
namespace client
{
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
typedef boost::fusion::tuple<std::string, std::string, std::string> v3;
typedef std::vector<std::string> vs;
using namespace boost::fusion;
void do_triple(v3 tup)
{
std::cout << "got this tuple: " << std::endl;
std::cout << get<0>(tup) << std::endl;
std::cout << get<1>(tup) << std::endl;
std::cout << get<2>(tup) << std::endl;
}
void do_vector(vs tup)
{
BOOST_FOREACH(std::string s, tup)
{
std::cout << s << std::endl;
}
}
void do_string(std::string tup)
{
std::cout << "tup is apparently a string - why??? " << tup << std::endl;
}
template <typename Iterator>
struct search_query_grammar : qi::grammar<Iterator,
ascii::space_type>
{
search_query_grammar() : search_query_grammar::base_type(start)
{
using qi::lit;
using qi::string;
start = lit("-query") >> '=' >> tripleExp;
tripleExp = attrname >> predicate >> attrvalue [&do_triple];
attrname = +(ascii::alnum);
attrvalue = +(ascii::alnum);
predicate = string(">") | string("<") | string("==");
}
qi::rule<Iterator, ascii::space_type> start;
qi::rule<Iterator, v3(), ascii::space_type> tripleExp;
qi::rule<Iterator, std::string()> attrname, attrvalue, predicate;
};
}
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general