public class ParseNode extends java.lang.Object implements Locatable
It is also the root of the parse tree which is built automatically when parsing is done with GenericParser.parse(boolean).
GenericParser| Constructor and Description |
|---|
ParseNode()
Constructs an unititialized ParseNode object.
|
ParseNode(ParseNode node)
Constructs a ParseNode object that is a (shallow) copy of
of the specified ParseNode.
|
ParseNode(ParserSymbol symbol)
Constructs a ParseNode object with its symbol
field initialized to the specified parser symbol.
|
ParseNode(ParserSymbol symbol,
double value)
Constructs a ParseNode object with its symbol
field initialized to the specified parser symbol, and nvalue
field initialized to the specified double value.
|
ParseNode(ParserSymbol symbol,
int value)
Constructs a ParseNode object with its symbol
field initialized to the specified parser symbol, and nvalue
field initialized to the specified integer value.
|
ParseNode(ParserSymbol symbol,
java.lang.String value)
Constructs a ParseNode object with its symbol
field initialized to the specified parser symbol and svalue
field initialized to the specified string.
|
ParseNode(java.lang.String value)
Constructs an anonymous ParseNode object (i.e.,
with a null symbol), and sets its svalue field to
the specified string.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAlternative(ParseNode alternative)
Add an alternative form for this ParseNode.
|
ArrayList |
alternatives()
If non-null, this contains alternative forms of an ambiguous
token.
|
int |
associativity()
Returns the associativity value of this node.
|
ParseNode |
child(int i)
If a parse tree has been built, this returns the i-th in the
sequence of ParseNodes that are this node's constituents.
|
ArrayList |
children()
When constructing the parse tree, this is the set of constituents.
|
ParseNode |
copy()
Returns a new ParseNode that is a shallow copy of this ParseNode.
|
ParseNode |
copy(ParseNode node)
Returns an almost complete copy of the specified node by
copying the values of all its attributes except that of its
symbol, children, and location span.
|
void |
display()
Spawns a framed graphical display of the parse tree
rooted in this node.
|
void |
display(java.lang.String source)
Spawns a framed graphical display of the parse tree
rooted in this node and corresponding to the specified
source file.
|
boolean |
equals(java.lang.Object other)
Two ParseNodes are considered equal iff they carry the same info.
|
ParseNode |
firstChild()
If a parse tree has been built, this returns the first in the sequence of
ParseNodes that are this node's constituents.
|
int |
fixity()
Returns the fixity value of this node.
|
Location |
getEnd() |
java.lang.String |
getFile()
Returns the file name where this node's constituents start from
if any; or null
|
int |
getLineNumber()
Returns the line number in the input stream corresponding to the
start location of this node's extent.
|
Span |
getSpan()
Returns information to locate this node's extent in the input stream
or null.
|
Location |
getStart() |
boolean |
hasAlternatives()
Returns true iff this ParseNode has one or more alternative
forms.
|
boolean |
hasChildren()
Returns true iff this node does not have any child.
|
boolean |
hasValue()
Returns true iff this node carries a value (which is either
in its svalue or nvalue field).
|
boolean |
hasXmlForm()
Returns true iff xmlForm() is non-empty.
|
boolean |
isEmptyNode()
Returns true iff this node is a null inner node (i.e.,
iff it corresponds to an empty derivation).
|
boolean |
isEOI() |
boolean |
isError() |
boolean |
isInnerNode()
Returns true iff this node is an inner node in the parse
tree (i.e., iff it corresponds to a nonterminal symbol).
|
boolean |
isInteger()
Returns true iff this ParseNode is an integer number.
|
boolean |
isLeafNode()
Returns true iff this node is a leaf in the parse tree
(i.e., iff it corresponds to a terminal symbol or an
anonymous symbol).
|
boolean |
isLocated() |
boolean |
isOperator()
Returns true iff this is a dynamic operator.
|
boolean |
isTerminal()
Returns true iff this node corresponds to a terminal symbol.
|
boolean |
isUnknown() |
ParseNode |
lastChild()
If a parse tree has been built, this returns the last in the sequence of
ParseNodes that are this node's constituents.
|
void |
locate()
This method (by default empty) is invoked anytime this node's span
is set.
|
java.lang.String |
locationString()
Returns an explicit string for this node's location.
|
void |
makeInteger(boolean isInteger)
Sets the integer flag to the given boolean argument (i.e.,
whenever this argument is true, this node's numerical
value will be cast as an int).
|
java.lang.String |
nodeInfo()
Returns a string representation of this node's information
contents: its string form and its location if known.
|
int |
numberOfChildren()
Returns the number of constituents of this node.
|
double |
nvalue()
The number value of this node.
|
ParserOperator |
operator()
If this is a dynamic operator, the actual specific operator.
|
int |
precedence()
Returns the precedence value of this node.
|
void |
setChildren(ArrayList children) |
Locatable |
setEnd(Location location) |
ParseNode |
setFile(java.lang.String file)
Sets the file name where this node's constituents are, and returns
this parse node.
|
ParseNode |
setLineNumber(int line)
Sets the line number in the input stream corresponding to this
node's location extent start, and returns this parse node.
|
void |
setNvalue(double nvalue)
Sets the number value of this node.
|
void |
setOperator(ParserOperator operator)
Sets the operator.
|
Locatable |
setSpan(ParseNode node) |
Locatable |
setStart(Location location) |
void |
setSvalue(java.lang.String svalue)
Sets the String value of this node.
|
void |
setSymbol(ParserSymbol symbol)
Sets the grammar symbol this node stands for.
|
ParseNode |
setXmlInfo(XmlInfo info)
Sets this parse node's XML info to the specified info and
returns this node.
|
void |
show()
Prints the parse tree rooted in this node on stdout.
|
void |
show(int margin,
java.io.PrintStream out)
Prints the parse tree rooted in this node on the specified
output stream with the given initial margin.
|
void |
show(java.io.PrintStream out)
Prints the parse tree rooted in this node on the specified
output stream.
|
void |
showXmlElement(org.jdom.Element element,
java.io.PrintStream out)
Serializes the specified XML element on the specified output
stream.
|
Span |
span()
Returns information to locate this node's extent in the input stream.
|
java.lang.String |
stringValue()
Returns the value carried by this node as a String.
|
java.lang.String |
svalue()
The String value of this node.
|
ParserSymbol |
symbol()
The grammar symbol this node stands for.
|
java.lang.String |
toString()
Returns a string representation of this node, along, possibly, with
all its alternatives if any.
|
org.jdom.Document |
xmlDocument()
Returns the XML document associated with this parse node, if any,
or null otherwise.
|
org.jdom.Document |
xmlDocument(java.lang.String xmlroot,
java.lang.String nsprefix,
java.lang.String[] namespaces)
Returns the XML document associated with this parse node with a
root element named as specified by xmlroot and
nsprefix in the context of the namespaces declarations
specified in namespaces.
|
ArrayList |
xmlForm()
Returns the (possibly empty) list of XML elements associated with
this parse node.
|
ArrayList |
xmlify(org.jdom.Element root)
|
public ParseNode()
public ParseNode(java.lang.String value)
public ParseNode(ParserSymbol symbol)
DynamicParser,
DynamicTokenpublic ParseNode(ParserSymbol symbol, double value)
public ParseNode(ParserSymbol symbol, int value)
public ParseNode(ParserSymbol symbol, java.lang.String value)
public ParseNode(ParseNode node)
public ParserSymbol symbol()
public void setSymbol(ParserSymbol symbol)
public double nvalue()
public void setNvalue(double nvalue)
public boolean isInteger()
public void makeInteger(boolean isInteger)
public java.lang.String svalue()
public void setSvalue(java.lang.String svalue)
public ArrayList alternatives()
public void addAlternative(ParseNode alternative)
public boolean hasAlternatives()
public boolean isUnknown()
public boolean isError()
public boolean isEOI()
public final Span span()
public final Span getSpan()
public void locate()
public final boolean isLocated()
public final java.lang.String getFile()
public final int getLineNumber()
public final ParseNode setFile(java.lang.String file)
public final ParseNode setLineNumber(int line)
public final java.lang.String locationString()
locationString in interface Locatablepublic final ArrayList children()
public void setChildren(ArrayList children)
public final int numberOfChildren()
public final boolean isTerminal()
public final boolean hasChildren()
public final boolean isLeafNode()
public final boolean isInnerNode()
public final boolean isEmptyNode()
public final boolean hasValue()
public final java.lang.String stringValue()
public final java.lang.String nodeInfo()
public final ParseNode child(int i)
public final ParseNode firstChild()
public final ParseNode lastChild()
public ParserOperator operator()
public void setOperator(ParserOperator operator)
public final boolean isOperator()
public final int precedence()
public final int associativity()
public final int fixity()
public final ParseNode copy(ParseNode node)
public ParseNode copy()
public final void display()
public final void display(java.lang.String source)
public final void show()
public final void show(java.io.PrintStream out)
public final void show(int margin,
java.io.PrintStream out)
public final ArrayList xmlForm()
[N.B.: This list is "populated" by calling xmlify(Element root).]
public final boolean hasXmlForm()
public final void showXmlElement(org.jdom.Element element,
java.io.PrintStream out)
throws java.io.IOException
java.io.IOExceptionpublic final org.jdom.Document xmlDocument()
[N.B.: This will return null as long as xmlDocument(xmlroot,nsprefix,namespaces) has not been invoked.]
public org.jdom.Document xmlDocument(java.lang.String xmlroot,
java.lang.String nsprefix,
java.lang.String[] namespaces)
public ParseNode setXmlInfo(XmlInfo info)
public final ArrayList xmlify(org.jdom.Element root)
The XML info is of type XmlInfo and consists of:
Thus, we need to specify how to transduce this node into an
ArrayList following the following steps:
[N.B., _xmlInfo.children() is then
null or empty since there may be no reference to children
in an empty derivation's annotation -
here's why]
[N.B: this should not happen and be flagged
as an annotation error at grammar-processing time since
punctuation terminals may not be annotated;
only rules and value-carrying tokens may be
annotated in the grammar. Thus, punctuation
terminals are systematically ignored.]
[N.B.: _xmlInfo.children() is then
null or empty since there may be no reference to children
in a terminal's annotation - here's why]
[See also the method createXmlForm(ParseNode node, Element root) in the class XmlInfo.]
N.B.: The code below is guaranteed to work safely only if the annotation is strictly consistent.
public final boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object