|
Boost Users : |
Subject: [Boost-users] spirit::qi and Phoenix placeholder
From: Olivier Austina (olivier.austina_at_[hidden])
Date: 2013-10-04 16:12:39
I am reading Spirit tutorial, at
http://www.boost.org/doc/libs/1_54_0/libs/spirit/doc/html/spirit/qi/tutorials.html.
I am new to boost. It is not clear to me what the placeholder are and when
using them. This is some of them:
*Spirit.Qi specific Phoenix placeholders*
_1, _2... , _N
Nth attribute of p
_val
The enclosing rule's synthesized attribute.
_r1, _r2... , _rN
The enclosing rule's Nth inherited attribute.
_a, _b... , _j
The enclosing rule's local variables (_a refers to the first).
_pass
Assign false to _pass to force a parser failure.
For example in this code :
template <typename Iterator>bool parse_numbers(Iterator first,
Iterator last, std::vector<double>& v){
using qi::double_;
using qi::phrase_parse;
using qi::_1;
using ascii::space;
using phoenix::push_back;
using phoenix::ref;
bool r = phrase_parse(first, last,
// Begin grammar (
*double_[push_back(ref(v), _1)]
>> *(',' >> double_[push_back(ref(v), _1)])*
)
,
// End grammar
space);
if (first != last) // fail if we did not get a full match
return false;
return r;}
why using _1, (using qi::_1) instead of _2 (using qi::_2).
Which parts of boost should I read before reading spirit.
Any suggestion is welcome. Thank you.
Regards
Olivier
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net