|
Boost Users : |
Subject: Re: [Boost-users] [Spirit] parse tree node does not get produced with Single character input.
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-06-29 03:22:20
I know this is old, but it has had no response, I apologize...
On Tue, Jun 8, 2010 at 9:03 AM, Philippe forest
<philippe.forest_at_[hidden]> wrote:
> Hi,
Greetings,
You should update your Boost, the later versions are vastly better,
allow me to demonstrate:
On Tue, Jun 8, 2010 at 9:03 AM, Philippe forest
<philippe.forest_at_[hidden]> wrote:
> First of all I would like to state that
> spirit =
> Â str_p("very") >> +ch_p(' ') >>( str_p("nice") | str_p("cool") |
> str_p("greate") ) >> +ch_p(' ') >> str_p("parser")
> ;
In modern Spirit:
spirit
= skip(' ')[lit("very")
>> (lit("nice")
| "cool"
| "great")
)>>"parser"]
;
> So Thanks for that.
>
> But I do face a problem. When assigning ID to nodes of the parse tree.
> ex: rule<ScannerT, parser_context<>, parser_tag<stringID> > Â String;
>
> I've attached a sample to demonstrate the problem.
>
> In short:
>
> The grammar below does not produce a parse tree node with a 'stringID'
> when the input is a single character 'a'. As soon as I have 2 or more
> characters 'aa' then I get a node stringID.
>
> Â Â Â Â definition(
> Â Â Â Â Â ExpressionNoStringIDGrammar const& /*self*/)
> Â Â Â Â {
> Â Â Â Â Â Char =
> Â Â Â Â Â Â ch_p('a')
> Â Â Â Â Â Â ;
>
> Â Â Â Â Â String =
> Â Â Â Â Â Â ( +Char )
> Â Â Â Â Â Â ;
>
> Â Â Â Â Â language =
> Â Â Â Â Â Â String
> Â Â Â Â Â Â ;
> Â Â Â Â }
>
> rule<ScannerT, parser_context<>, parser_tag<charID> > Â Â Â Â Char;
> rule<ScannerT, parser_context<>, parser_tag<stringID> > Â Â Â String;
> rule<ScannerT> language;
In modern Spirit, this should work fine:
template<typename Iterator>
class definition : grammar<Iterator, std::string()>
{
definition() : definition::base_type(language)
{
Char =
char_('a')
;
String =
+Char
;
language =
String
;
}
rule<Iterator, char()> Char;
rule<Iterator, std::string()> String;
rule<Iterator, std::string()> language;
}
That will return the parsed string of a's as an std::string. Look at
the new Spirit, insanely more powerful, and so much easier to use as
well.
http://www.boost.org/doc/libs/1_43_0/libs/spirit/doc/html/index.html
On Tue, Jun 8, 2010 at 9:03 AM, Philippe forest
<philippe.forest_at_[hidden]> wrote:
> BUT:
> If I remove the 'Char' parser and substitute it with ch_p('a') then it
> works fine , then I always get a node stringID even with a single input
> char.
>
> Â Â Â Â definition(
> Â Â Â Â Â ExpressionNoStringIDGrammar const& /*self*/)
> Â Â Â Â {
> Â Â Â Â Â String =
> Â Â Â Â Â Â ( +ch_p('a') )
> Â Â Â Â Â Â ;
>
> Â Â Â Â Â language =
> Â Â Â Â Â Â String
> Â Â Â Â Â Â ;
> Â Â Â Â }
>
> rule<ScannerT, parser_context<>, parser_tag<charID> > Â Â Â Â Char;
> rule<ScannerT, parser_context<>, parser_tag<stringID> > Â Â Â String;
> rule<ScannerT> language;
>
> Could anyone either explain me what is going on ?
> Â - I'm I doing something wrong or is this a bug or works as designed ?
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