Difficulties with binding to functions for semantic actions
SF Markus Elfring <[email protected]> Fri, 25 Oct 2013 13:00:36 +0200
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------020605060203010206090109
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Hello,
Does the attached source file work on your software development or test system
eventually?
http://sourceforge.net/mailarchive/message.php?msg_id=31535238
How can an error message like the following be resolved here?
/usr/local/include/boost/spirit/home/qi/detail/parse_auto.hpp:186:50: error:
‘call’ is not a member of
‘boost::spirit::qi::detail::phrase_parse_impl<my_grammar<__gnu_cxx::__normal_iterator<const
char*, std::basic_string<char> >, std::map<std::basic_string<char>,
std::basic_string<char> > >, void>’
Regards,
Markus
--------------020605060203010206090109
Content-Type: text/x-c++src;
name="bind-test1.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="bind-test1.cpp"
#include <iostream>
#include <stdexcept>
#include <string>
#include <map>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/home/phoenix/bind.hpp>
#include <cstdio>
#include <cstdlib>
namespace bsq = boost::spirit::qi;
namespace bsa = boost::spirit::ascii;
template <typename I, typename T>
class my_grammar
: bsq::grammar<I>
{
T& table;
void add_entry(std::string key, typename T::mapped_type value)
{
table[key] = value;
}
bsq::rule<I> start;
public:
my_grammar(T& t)
: my_grammar<I, T>::base_type(start),
table(t),
start(
+( ( (+ bsa::alnum) >> bsq::lexeme['=' >> + bsa::graph] )
[bind(&my_grammar<I, T>::add_entry, bsq::_1, bsq::_3)]
)
)
{
}
};
struct extractor
{
std::map<std::string, std::string> table;
void parse(std::string const& text)
{
typedef std::string::const_iterator iterator_type;
my_grammar<iterator_type, decltype(table)> gr(table);
iterator_type first = text.begin();
iterator_type last = text.end();
bool r = bsq::phrase_parse(first, last, gr, bsa::space);
if (!r)
{
std::cerr << "stopped at: \"" << std::string(first, last) << '"' << std::endl;
throw std::runtime_error("Parsing failure");
}
}
};
int main(int argc, char* argv[])
{
char const my_message[] = " exception was caught.";
try
{
extractor ex;
ex.parse(argc == 1 ? "key=value" : argv[1]);
std::cout << ex.table.size() << " parameters" << std::endl;
for (auto& x: ex.table)
{
std::cout << '|' << x.first << "|: |" << x.second << '|' << std::endl;
}
}
catch (std::bad_alloc const& b)
{
(void) std::fputs("out of memory\n", stderr);
return EXIT_FAILURE;
}
catch (std::exception const& x)
{
(void) std::fprintf(stderr,
"A kind of standard%s\n%s\n",
my_message,
x.what());
return EXIT_FAILURE;
}
catch (...)
{
(void) std::fprintf(stderr, "An unknown%s\n", my_message);
throw;
}
}
--------------020605060203010206090109
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
--------------020605060203010206090109
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Spirit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
--------------020605060203010206090109--