Package gw.internal.gosu.parser
Class ParseTree
java.lang.Object
gw.internal.gosu.parser.ParseTree
- All Implemented Interfaces:
IParseTree
,Serializable
Intended to specify the location of a parsed element within the source.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface gw.lang.parser.IParseTree
IParseTree.Search
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DynamicArray<ParseTree>
private int
private int
private ParsedElement
private IScriptPartId
private static final DynamicArray<ParseTree>
-
Constructor Summary
ConstructorsConstructorDescriptionParseTree
(ParsedElement pe, int iOffset, int iLength, IScriptPartId scriptPart) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(int iIndex, IParseTree l) void
Adds a child location to this location.private void
addTokens
(ParseTree after, List<IToken> tokens, StringBuilder source) void
addUnder
(IParseTree parent) (package private) void
adjustOffset
(int offset, int lineNumOffset, int columnOffset) private void
appendTokensForOutline
(ParseTree child, List<IToken> tokens, StringBuilder source) boolean
areAllChildrenAfterPosition
(int caret) boolean
areOffsetAndExtentEqual
(IParseTree location) Is just the physical location equal?void
void
boolean
contains
(int iPosition) private boolean
contains
(int start, int end) boolean
boolean
containsOrBorders
(int iPosition, boolean strict) private boolean
containsOrBorders
(int start, int end, boolean strict) boolean
containsOrBorders
(IParseTree l, boolean strict) private void
findDescendantsWithParsedElementType
(ArrayList<IParseTree> matches, Class type) getChild
(int index) getChildAfter
(int point) getChildAfter
(IParseTree child) getChildBefore
(int point) getChildBefore
(IParseTree child) int
getChildrenBefore
(IParseTree parseTree) int
private ParseTree
getDeepestLocation
(boolean statementsOnly, int iPosition, boolean strict) getDeepestLocation
(boolean statementsOnly, int iStart, int iEnd, boolean strict) getDeepestLocation
(int iPosition, boolean strict) getDeepestLocation
(int iStart, int iEnd, boolean strict) getDeepestStatementLocation
(int iPosition, boolean strict) int
getFirstChildWithParsedElementType
(Class<? extends IParsedElement> aClass) getLastChildWithParsedElementType
(Class<? extends IParsedElement> aClass) int
int
final IParseTree
getMatchingElement
(int iStart, int iLength) int
Like getParent, but won't infinitely recurse if the parent turns out to be equal to this, which can happen when the expression in question is a program (since the outer program has the same location as the main statement).getStatementAtLine
(int iLineNum, Class clsSkip) private String
getTreeOutline
(String strIndent) void
initLocation
(ParsedElement pe, int iOffset, int iLength) boolean
isAncestor
(IParseTree child) boolean
boolean
isSiblingOf
(IParseTree deepestAtEnd) private void
recursivelyAdjustOffset
(int offset, int lineNumOffset, int columnOffset) void
void
setLength
(int iLength) void
Sets the parent location.toString()
-
Field Details
-
EMPTY_PARSE_TREE_LIST
-
_pe
-
_children
-
_iOffset
private int _iOffset -
_iLength
private int _iLength -
_scriptPart
-
-
Constructor Details
-
ParseTree
-
-
Method Details
-
getEnclosingType
- Specified by:
getEnclosingType
in interfaceIParseTree
-
getScriptPartId
- Specified by:
getScriptPartId
in interfaceIParseTree
-
getOffset
public int getOffset()- Specified by:
getOffset
in interfaceIParseTree
- Returns:
- The zero-based offset of the parsed element within the source.
-
getLength
public int getLength()- Specified by:
getLength
in interfaceIParseTree
- Returns:
- The length of the parsed element in the source.
-
setLength
public void setLength(int iLength) - Specified by:
setLength
in interfaceIParseTree
-
getLineNum
public int getLineNum()- Specified by:
getLineNum
in interfaceIParseTree
- Returns:
- The one based line number of the beginning of the parsed element
-
getColumn
public int getColumn()- Specified by:
getColumn
in interfaceIParseTree
- Returns:
- The offset from the beginning of the line where the parsed element starts
-
getParsedElement
- Specified by:
getParsedElement
in interfaceIParseTree
- Returns:
- The parsed element to which this location corresponds.
-
getExtent
public int getExtent()- Specified by:
getExtent
in interfaceIParseTree
- Returns:
- The most distant position this location occupies i.e., offset + length - 1.
-
contains
public boolean contains(int iPosition) - Specified by:
contains
in interfaceIParseTree
- Parameters:
iPosition
- Any position within the source.- Returns:
- True if this location contains the position.
-
contains
- Specified by:
contains
in interfaceIParseTree
- Parameters:
l
- A location to check.- Returns:
- True if the space occupied by this location is a superset of the space occupied by the specified location.
-
contains
private boolean contains(int start, int end) -
containsOrBorders
public boolean containsOrBorders(int iPosition, boolean strict) - Specified by:
containsOrBorders
in interfaceIParseTree
-
containsOrBorders
- Specified by:
containsOrBorders
in interfaceIParseTree
-
containsOrBorders
private boolean containsOrBorders(int start, int end, boolean strict) -
getDeepestLocation
- Specified by:
getDeepestLocation
in interfaceIParseTree
-
isAncestorOf
- Specified by:
isAncestorOf
in interfaceIParseTree
-
getDeepestLocation
-
getDeepestLocation
- Specified by:
getDeepestLocation
in interfaceIParseTree
- Parameters:
iPosition
- The location to check.strict
- Whether to match strictly or accept white spaces to the right- Returns:
- The deepest descendent location containing the specified location.
-
getDeepestLocation
- Specified by:
getDeepestLocation
in interfaceIParseTree
- Parameters:
iStart
- The start of the segment (inclusive)iEnd
- The end of the segment (inclusive)strict
- Whether to match strictly or accept white spaces to the right- Returns:
- The deepest descendent location containing the segment.
-
getDeepestStatementLocation
- Specified by:
getDeepestStatementLocation
in interfaceIParseTree
- Parameters:
iPosition
- The location to check.strict
- Whether to match strictly or accept white spaces to the right- Returns:
- The deepest descendent statement location containing the specified location.
-
getStatementAtLine
- Specified by:
getStatementAtLine
in interfaceIParseTree
- Parameters:
iLineNum
- The one based line number to check.clsSkip
- A statement sublcass to ignore. Optional.- Returns:
- The first statement beginning at the specified line number, or null if no statements start at the line number.
-
addChild
Adds a child location to this location. Note the location must cover only a subset of this locations area.- Specified by:
addChild
in interfaceIParseTree
- Parameters:
l
- The location to add.
-
addChild
-
removeChild
- Specified by:
removeChild
in interfaceIParseTree
-
getChildren
- Specified by:
getChildren
in interfaceIParseTree
- Returns:
- The list of child locations covered by this location.
-
getChildCount
public int getChildCount() -
setParent
Sets the parent location. Note the parent location must cover a superset of the specified location's area.- Specified by:
setParent
in interfaceIParseTree
- Parameters:
l
- The parent location.
-
getParent
- Specified by:
getParent
in interfaceIParseTree
- Returns:
- This location's parent location. Note the parent covers a superset of the this location's area.
-
getParentOtherThanThis
Like getParent, but won't infinitely recurse if the parent turns out to be equal to this, which can happen when the expression in question is a program (since the outer program has the same location as the main statement).- Specified by:
getParentOtherThanThis
in interfaceIParseTree
-
areOffsetAndExtentEqual
Is just the physical location equal?- Specified by:
areOffsetAndExtentEqual
in interfaceIParseTree
- Parameters:
location
- Location to check- Returns:
- True if the given physical location's offset and extents are equal to this one's
-
toString
- Specified by:
toString
in interfaceIParseTree
- Overrides:
toString
in classObject
-
initLocation
-
compactParseTree
public void compactParseTree() -
clearParseTreeInformation
public void clearParseTreeInformation()- Specified by:
clearParseTreeInformation
in interfaceIParseTree
-
areAllChildrenAfterPosition
public boolean areAllChildrenAfterPosition(int caret) - Specified by:
areAllChildrenAfterPosition
in interfaceIParseTree
-
getDominatingLocationList
- Specified by:
getDominatingLocationList
in interfaceIParseTree
-
getChildrenBefore
- Specified by:
getChildrenBefore
in interfaceIParseTree
-
isSiblingOf
- Specified by:
isSiblingOf
in interfaceIParseTree
-
getChildAfter
- Specified by:
getChildAfter
in interfaceIParseTree
-
getChildBefore
- Specified by:
getChildBefore
in interfaceIParseTree
-
getChildBefore
- Specified by:
getChildBefore
in interfaceIParseTree
-
getChildAfter
- Specified by:
getChildAfter
in interfaceIParseTree
-
getFirstChildWithParsedElementType
- Specified by:
getFirstChildWithParsedElementType
in interfaceIParseTree
-
getLastChildWithParsedElementType
- Specified by:
getLastChildWithParsedElementType
in interfaceIParseTree
-
getLastChild
- Specified by:
getLastChild
in interfaceIParseTree
-
getNextSibling
- Specified by:
getNextSibling
in interfaceIParseTree
-
getPreviousSibling
- Specified by:
getPreviousSibling
in interfaceIParseTree
-
getDeepestFirstChild
- Specified by:
getDeepestFirstChild
in interfaceIParseTree
-
findDescendantsWithParsedElementType
- Specified by:
findDescendantsWithParsedElementType
in interfaceIParseTree
-
addUnder
- Specified by:
addUnder
in interfaceIParseTree
-
adjustOffset
void adjustOffset(int offset, int lineNumOffset, int columnOffset) -
recursivelyAdjustOffset
private void recursivelyAdjustOffset(int offset, int lineNumOffset, int columnOffset) -
findDescendantsWithParsedElementType
-
getEnclosingFunctionStatement
- Specified by:
getEnclosingFunctionStatement
in interfaceIParseTree
-
getMatchingElement
- Specified by:
getMatchingElement
in interfaceIParseTree
-
getTreeOutline
-
getTreeOutline
-
appendTokensForOutline
-
getTextFromTokens
- Specified by:
getTextFromTokens
in interfaceIParseTree
-
addTokens
-
getChildrenSorted
-
isAncestor
- Specified by:
isAncestor
in interfaceIParseTree
-
getChild
-