Top Description Fields Constructors Methods
org.jparsec

pack-priv final Class TreeNode

extends Object
Class Inheritance
Imports
org.jparsec.internal.util.Checks, java.util.ArrayList, .Collections, .List

A TreeNode remembers it's parent (which corresponds to a parent parser that syntactically encloses this parter), it's previous node (which is the parser at the same syntactical level and had just succeeded before this parser started). It also keeps all the children.

Once constructed, a node's 'parent' and 'previous' references are immutable. The list of children nodes however can change. When the alternative parsers in an or parser are attempted one after another, they each generate new child node of the parent node. These "alternative" nodes all point to the same parent and same "previous" node.

When exception is to be thrown, the most relevant error is picked, along with the tree node that was recorded at time of ParseContext#raise. That tree node is then frozen by setting its parent's latestChild to this error node's "previous" successful node, and that of its grandparent's to its parent node, all the way up to the root. This essentially freezes and collapse the "multi universes" into a single error state, with all other "potential" error state destroyed and forgotten.

Field Summary

Modifier and TypeField and Description
private final int
private int
pack-priv TreeNode
private final String
private final TreeNode
private final TreeNode
private Object

Constructor Summary

AccessConstructor and Description
pack-priv
TreeNode(String name, int beginIndex)

pack-priv
TreeNode(String name, int beginIndex, TreeNode parent, TreeNode previous)

Method Summary

Modifier and TypeMethod and Description
pack-priv TreeNode
addChild(String childName, int childIndex)

pack-priv TreeNode
freeze(int index)

Freezes the current tree node to make it the latest child of its parent (discarding nodes that have been tacked on after it in the same hierarchy level); and recursively apply to all of its ancestors.

pack-priv TreeNode
orphanize()

When this leaf node has errors, it didn't complete and shouldn't be part of the parse tree that is the current partial parse result with all successful matches.

pack-priv TreeNode
pack-priv void
setEndIndex(int index)

pack-priv void
setResult(Object result)

pack-priv ParseTree
toParseTree()

Converts this node into a ParseTree representation.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

beginIndexback to summary
private final int beginIndex
endIndexback to summary
private int endIndex
latestChildback to summary
pack-priv TreeNode latestChild
nameback to summary
private final String name
parentback to summary
private final TreeNode parent
previousback to summary
private final TreeNode previous
resultback to summary
private Object result

Constructor Detail

TreeNodeback to summary
pack-priv TreeNode(String name, int beginIndex)
TreeNodeback to summary
pack-priv TreeNode(String name, int beginIndex, TreeNode parent, TreeNode previous)

Method Detail

addChildback to summary
pack-priv TreeNode addChild(String childName, int childIndex)
freezeback to summary
pack-priv TreeNode freeze(int index)

Freezes the current tree node to make it the latest child of its parent (discarding nodes that have been tacked on after it in the same hierarchy level); and recursively apply to all of its ancestors.

This is because it's only called at time of error. If an ancestor node has a child node that was added during the process of trying other alternatives and then failed, those paths don't matter. So we should restore the tree back to when this most relevant error happened.

Returns the root node, which can then be used to toParseTree().

orphanizeback to summary
pack-priv TreeNode orphanize()

When this leaf node has errors, it didn't complete and shouldn't be part of the parse tree that is the current partial parse result with all successful matches. In that case, return the parent node, by setting its latestChild to previous.

parentback to summary
pack-priv TreeNode parent()
setEndIndexback to summary
pack-priv void setEndIndex(int index)
setResultback to summary
pack-priv void setResult(Object result)
toParseTreeback to summary
pack-priv ParseTree toParseTree()

Converts this node into a ParseTree representation.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override