[antlr-interest] tree construction : skip empty nodes
Sébastien Kirche
sebastien.kirche at gmail.com
Thu Jul 28 05:07:51 PDT 2011
Hi,
I have the two following rules :
codeBlock : stmt+=compoundStatement* -> ^(STMT $stmt)* ;
compoundStatement
:
(
( /* empty */
| tryCatchBlock
| localVarDecl
| ifStatement
| chooseCaseStatement
| forStatement
| loopStatement
| embeddedSQL
| singleStatement
) (Semi! | EOL! )
)
| Label -> ^(LABEL Label)
;
As the compoundStatement can match empty lines or null statements
(like ;;;) my parser sometimes emit empty STMT nodes.
I cannot figure the correct way to conditionaly emit STMT if only the
compoundStatement is not empty.
I have tried something like codeBlock : stmt+=compoundStatement* ->
{$stmt.tree != null} ^(STMT $stmt)* ;
but because of the += notation the $stmt is a list and I did not find
yet the proper way to test each item.
Could you give me some help ?
--
Sébastien Kirche
More information about the antlr-interest
mailing list