Re: newbie here ask about qi::_val and semantic action
Yi Leong <[email protected]> Mon, 9 Jul 2018 13:38:55 +0800
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMFq=pZULWFvGBTJvjRoZ8ayKR6tCr=ixPBcze_dd2yngymYMQ@mail.gmail.com> |
yeah, in the qi::double_[qi::_val = qi::_1] , the semantic action is a
lambda expression, but as the following:
#include <iostream>
#include <string>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
void print_action(double f)
{
qi::_val = qi::_1; // it does not work....
}
int main() {
std::string s = "1234.56789";
double d;
std::string::iterator first = s.begin();
std::string::iterator last = s.end();
namespace qi = boost::spirit::qi;
bool r = qi::phrase_parse(first, last, qi::double_ [&print_action],
qi::space, d);
if (!r || first != last) {
std::cerr << "Error while parsing. Rest: " << std::string(first,
last) << "\n";
}
std::cout << "Success! " << d << "\n";
}
The above code gets compiling error, so is the placeholder qi::_val
usable only in the lambda expression, right?
On Mon, Jul 9, 2018 at 10:06 AM, Henri Menke <[email protected]> wrote:
> Elaborate. The following works.
>
> #include <iostream>
> #include <string>
>
> #include <boost/spirit/include/phoenix.hpp>
> #include <boost/spirit/include/qi.hpp>
>
> int main() {
> std::string s = "1234.56789";
> double d;
>
> std::string::iterator first = s.begin();
> std::string::iterator last = s.end();
>
> namespace qi = boost::spirit::qi;
> bool r = qi::phrase_parse(first, last, qi::double_ [qi::_val =
> qi::_1], qi::space, d);
>
> if (!r || first != last) {
> std::cerr << "Error while parsing. Rest: " << std::string(first,
> last) << "\n";
> }
> std::cout << "Success! " << d << "\n";
>
> }
>
>
> On 09/07/18 03:40, Yi Leong wrote:
>
>> Hi,
>> I set qi::_val in semantic action function , but it does not work.
>> Is the placeholder _val only usable in lambda expression?
>>
>>
>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>
>>
>>
>> _______________________________________________
>> Spirit-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/spirit-general
>>
>>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Spirit-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general