Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::spirit] Help! Unexpected Leading spaces got injected into a parse tree node
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-10-18 17:26:44


On Sun, Oct 18, 2009 at 1:19 PM, HT4N - <ht4n_at_[hidden]> wrote:
> It is confirmed that seems to work as expected, by swapping the lexeme_d
> with the node directive and it does really make sense.
>
> Appreciate it Steven for the help.
>
>> Date: Sun, 18 Oct 2009 11:53:11 -0700
>> From: watanabesj_at_[hidden]
>> To: boost-users_at_[hidden]
>> Subject: Re: [Boost-users] [boost::spirit] Help! Unexpected Leading spaces
>> got injected into a parse tree node
>>
>> AMDG
>>
>> HT4N - wrote:
>> > I have a question regarding unexpected leading spaces got injected into
>> > a parse tree node.
>> >
>> > Here is my grammar:
>> >
>> > Text = leaf_node_d[+digit_p] >> root_node_d[ch_p('=')] >>
>> > leaf_node_d[+digit_p];
>> >
>> > If I parse "5=5", as expected no extra leading spaces added to the
>> > resulting tree nodes.
>> >
>> > If I parse "5= 5" (read:5 followed by = followed by 4 spaces and
>> > followed by 5), given my grammar definition of leaf_node_d[+digit_p], I am
>> > expecting the parse tree node value should not contain any leading spaces.
>> > Yet, I see that the extra 4 spaces is stored in the corresponding parse
>> > tree node as shown below.
>> >
>> > <snip>
>> > ==> <value> 5</value>
>> >
>> > I am wondering if this is a by design or unexpected behavior. If it is a
>> > by design behavior, is there a way to trim leading/trailing spaces.
>> >
>>
>> Perhaps you should use lexeme_d[leaf_node_d[+digit_p]]?
>>
>> In Christ,
>> Steven Watanabe
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users

Also, you should use Boost.Spirit2.1 instead of Boost.Spirit.Classic.
2.1 is vastly more efficient, easier to write, easier to read, etc...
There is absolutely no reason not to use it unless you are stuck on a
Boost older then 1.38 or so.


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