public final class ParseTreeListener<V>
extends com.github.fge.grappa.run.ParseRunnerListener<V>
This listener will create ParseNodeBuilder instances (for rules
annotated with GenerateNode only) and build the parse tree when the
user calls getRootNode().
It is required that the root rule have such an annotation (it would be
impossible to build a parse tree otherwise); if this is not the case, an
IllegalStateException will be thrown (wrapped in a GrappaException).
Also, an attempt to retrieve a parse tree of a failed match will throw
an IllegalStateException as well. To prevent this, you should check
whether the match is a success (using ParsingResult.isSuccess())
before retrieving the parse tree.
| Constructor and Description |
|---|
ParseTreeListener(ParseNodeConstructorRepository repository)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
beforeMatch(com.github.fge.grappa.run.events.PreMatchEvent<V> event) |
ParseNode |
getRootNode()
Get the root
ParseNode of the parse tree built by this ParseTreeListener
This recursively builds all children, thus building a parse tree. |
void |
matchFailure(com.github.fge.grappa.run.events.MatchFailureEvent<V> event) |
void |
matchSuccess(com.github.fge.grappa.run.events.MatchSuccessEvent<V> event) |
public ParseTreeListener(ParseNodeConstructorRepository repository)
repository - the parse node constructors repositorypublic void beforeMatch(com.github.fge.grappa.run.events.PreMatchEvent<V> event)
beforeMatch in class com.github.fge.grappa.run.ParseRunnerListener<V>public void matchSuccess(com.github.fge.grappa.run.events.MatchSuccessEvent<V> event)
matchSuccess in class com.github.fge.grappa.run.ParseRunnerListener<V>public void matchFailure(com.github.fge.grappa.run.events.MatchFailureEvent<V> event)
matchFailure in class com.github.fge.grappa.run.ParseRunnerListener<V>public ParseNode getRootNode()
ParseNode of the parse tree built by this ParseTreeListener
This recursively builds all children, thus building a parse tree.java.lang.IllegalStateException - Attempt to retrieve the parse tree from
a failed match