AST node collapsing

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

AST node collapsing

Jason Blochowiak
Today, while working on getting an AST set up for my parser project, I ended
up being rather surprised that inner_node_d also collapses up a node, or
somesuch. To borrow from the AST calc example:

factor = inner_node_d[ch_p('(') >> expression >> ch_p(')')];

This seems to yield an AST with no "factor" node in it - only the
"expression" remains.

I searched the mailing list archives, and this appears to be by design. I
would be interested in a more complete explanation of what the intended
behavior is - the documentation simply says "The inner_node_d directive
causes the first and last nodes generated by the enclosed parser to be
discarded", which doesn't seem to be complete.

Is there documentation for this? Or am I completely missing the boat on
this?

Is BOOST_SPIRIT_NO_TREE_NODE_COLLAPSING expected to be fully supported? It
seems to do what I want in my current project.

Thanks for any insight. If there's some text describing the intended
behavior, please point me at it. Btw, I'm using Spirit 1.8.3 on .NET C++
2003.

Cheers,
Jason




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: AST node collapsing

Carl Barron

On Sep 22, 2005, at 7:10 PM, Jason Blochowiak wrote:

> Today, while working on getting an AST set up for my parser project, I
> ended
> up being rather surprised that inner_node_d also collapses up a node,
> or
> somesuch. To borrow from the AST calc example:
>
> factor = inner_node_d[ch_p('(') >> expression >> ch_p(')')];
>
> This seems to yield an AST with no "factor" node in it - only the
> "expression" remains.
>
> I searched the mailing list archives, and this appears to be by
> design. I
> would be interested in a more complete explanation of what the intended
> behavior is - the documentation simply says "The inner_node_d directive
> causes the first and last nodes generated by the enclosed parser to be
> discarded", which doesn't seem to be complete.
>
   are you generating an ast tree or a parse tree? an ast tree will
see the factor has only an expression node [after the first and last
children are deleted] so it move the expression up the tree. If you
want these one chlld nodes in your tree create a parse tree
(pt_parse instead ast_parse).  This will leave all such one node
nodes in the tree.  If you want selective pruning use gen_pt_node_d and
gen_ast_node_d to switch between them.

an ast tree is pruned of the one node nodes and a parse tree (pt) is
verbose.






-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

RE: AST node collapsing

Jason Blochowiak
Aha - the documentation that didn't stick properly in my head was
"ast_match_policy has the effect of eliminating intermediate rule levels
which are simply pass-through rules." I missed that - instead focusing on
the behavior of inner_node_d and root_node_d.

Interestingly enough, using the BOOST_SPIRIT_NO_TREE_NODE_COLLAPSING define
with ast_parse() yields the behavior I want - for my grammar, nodes that
appear to be "pass-through" are significant, so I want them around. At the
moment, I'm not using root_node_d, but I would strongly prefer to keep that
as an option for later, so I think I'll stick with ast & the define.

Thanks much for the clarification,
Jason


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of Carl Barron
> Sent: Thursday, September 22, 2005 9:46 PM
> To: [hidden email]
> Subject: Re: [Spirit-general] AST node collapsing
>
> On Sep 22, 2005, at 7:10 PM, Jason Blochowiak wrote:
> > factor = inner_node_d[ch_p('(') >> expression >> ch_p(')')];
> >
> > This seems to yield an AST with no "factor" node in it - only the
> > "expression" remains.
> >
>    are you generating an ast tree or a parse tree? an ast
> tree will see the factor has only an expression node [after
> the first and last children are deleted] so it move the
> expression up the tree. If you want these one chlld nodes in
> your tree create a parse tree (pt_parse instead ast_parse).  
> This will leave all such one node nodes in the tree.  If you
> want selective pruning use gen_pt_node_d and gen_ast_node_d
> to switch between them.
>
> an ast tree is pruned of the one node nodes and a parse tree
> (pt) is verbose.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general