|
Boost Users : |
Subject: Re: [Boost-users] [Spirit/Qi/Phoenix] non compiling rules...
From: Francois Mauger (mauger_at_[hidden])
Date: 2013-12-12 13:47:13
>>>On 12/12/2013 15:24, TONGARI J wrote:
Hi TJ,
Thanks for this fast answer.
>
> The problem is (at least what I see): your key_rule/value_rule have no
> attribute, so qi::_1 eventually evaluates to nothing (i.e. unused_type).
> To give them attr, for example:
>
> boost::spirit::qi::rule<std::__string::iterator,
> std::vector<char>()> key_rule;
>
I have added to second template attribute for rules and it works !
<pre>
boost::spirit::qi::rule<std::string::iterator, std::vector<char>()>
key_rule = +(char_ - '=');
boost::spirit::qi::rule<std::string::iterator, std::vector<char>()>
value_rule = lexeme[+(char_ - ';')];
bool r = phrase_parse(
strbegin,
s.end(),
key_rule[boost::phoenix::ref(vkey) =
boost::spirit::qi::_1 ]
>> '=' >> *space
>> value_rule[boost::phoenix::ref(vvalue) =
boost::spirit::qi::_1 ],
space
);
</pre>
However I don't understand the "()" after the "std::vector<char>". what
does it mean ? Does it refer to the std::vector constructor ?
Also I have implemented the following to play directly with std::strings
and not use temporary vectors of char anymore:
<pre>
boost::spirit::qi::rule<std::string::iterator, std::string()>
key_rule = as_string[+(char_ - '=')];
boost::spirit::qi::rule<std::string::iterator, std::string()>
value_rule = as_string[lexeme[+(char_ - ';')]];
std::string key;
std::string value;
bool r = phrase_parse(
strbegin,
s.end(),
key_rule[boost::phoenix::ref(key) =
boost::spirit::qi::_1 ]
>> '=' >> *space
>> value_rule[boost::phoenix::ref(value) =
boost::spirit::qi::_1 ],
space
);
</pre>
Guess what... it works... obviously. Many thanks for the fix.
> And I'd suggest using attr propagation instead of the explicit semantic
> action if possible.
>
Thanks you for the suggestion but I'm afraid I don't understand that
much what you speak about !!! ;-|
I just had a quick look at this article:
http://boost-spirit.com/home/articles/attribute_handling/attribute-propagation-and-attribute-compatibility/
but I need more time to allow this science to percolate in my brain (if
possible!).
Do you mean I should discard "...[boost::phoenix::ref(...) = ...]" stuff
in my rules and use a "sink" data structure (some kind of fusion
"container")
<pre>
Foo bar;
bool r = phrase_parse(
strbegin,
s.end(),
my_rule,
bar);
</pre>
where Foo could be a sort of tuple aggregating more basic attributes ?
Maybe can you show me an URL where I will find some "simple" code
snippet... I'm ready to RTFM but first I should find it (at least the
right one... there are so many confusing informations about Spirit for a
newbie).
Thanks.
Best
frc
-- François Mauger
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