Package redempt.redlex.data
Class Token
java.lang.Object
redempt.redlex.data.Token
- Direct Known Subclasses:
- ObjectToken
Represents a Token created by a Lexer. Acts as a node in a tree.
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddChildren(Token... tokens) Appends the given tokens to this token's childrenFind all tokens in the tree by name, breadth-firstallByName(TraversalOrder order, String name) Find all tokens in the tree by nameallByNames(String... names) Find all tokens in the tree by any number of names and create a map, breadth-firstallByNames(TraversalOrder order, String... names) Find all tokens in the tree by any number of names and create a mapvoidcull(TokenFilter... filters) Culls tokens in the tokens which are descendants of this one using filters.firstByName(String name) Find the first token in the tree by name (breadth-first)Token[]intgetEnd()intgetIndex()getNext()intgetStart()getType()getValue()joinChildren(String sep) Joins the String values of the children of this node separated by a delimiterjoinLeaves(String sep) Joins the leaf nodes of this subtree separated by a delimiterintlength()voidRemoves this token from its parent, replacing it with its childrenvoidremove()Removes this token from its parentvoidremoveChildren(int start, int end) Removes a range of children from this token by indexvoidremoveChildren(Token... children) Removes the given children from this tokenvoidReplaces this token's parent with itselfReplaces this token in its parent with a token wrapper for the given object, or a token if the passed object is a tokenvoidsetChildren(Token[] children) Sets the children of this TokenvoidSets the String value of this TokensplitChildren(String name) Splits child tokens on a given token by nametoString()voidwalk(TraversalOrder order, Consumer<Token> forEachNode) Walks this Token tree in the given order
- 
Field Details- 
EMPTY
- 
value
 
- 
- 
Constructor Details- 
Token
- 
Token
 
- 
- 
Method Details- 
setChildrenSets the children of this Token- Parameters:
- children- The children of this Token
 
- 
getChildren- Returns:
- The children of this Token
 
- 
getNext- Returns:
- The next sibling of this Token, or null if none exists
 
- 
getPrevious- Returns:
- The previous sibling of this Token, or null if none exists
 
- 
getParent- Returns:
- The parent of this Token, or null if none exists
 
- 
getIndexpublic int getIndex()- Returns:
- The index of this Token in the array of its parent's children
 
- 
getType- Returns:
- The type of this Token
 
- 
getValue- Returns:
- The String value of this Token
 
- 
getBaseString- Returns:
- The base String this token was parsed from
 
- 
lengthpublic int length()- Returns:
- The length of this Token's String value
 
- 
getEndpublic int getEnd()- Returns:
- The ending index of this Token
 
- 
getStartpublic int getStart()- Returns:
- The starting index of this Token
 
- 
setValueSets the String value of this Token- Parameters:
- value- The String value to set
 
- 
joinChildrenJoins the String values of the children of this node separated by a delimiter- Parameters:
- sep- The delimiter to separate values with
- Returns:
- The joined string
 
- 
joinLeavesJoins the leaf nodes of this subtree separated by a delimiter- Parameters:
- sep- The delimiter to separate values with
- Returns:
- The joined string
 
- 
removepublic void remove()Removes this token from its parent
- 
removeChildrenRemoves the given children from this token- Parameters:
- children- The children to remove
 
- 
removeChildrenpublic void removeChildren(int start, int end) Removes a range of children from this token by index- Parameters:
- start- The starting index to remove children from, inclusive
- end- The ending index to remove children to, exclusive
 
- 
replaceWithReplaces this token in its parent with a token wrapper for the given object, or a token if the passed object is a token- Parameters:
- o- The object to replace this token with
- Returns:
- The Token this one was replaced with
 
- 
replaceParentpublic void replaceParent()Replaces this token's parent with itself
- 
liftChildrenpublic void liftChildren()Removes this token from its parent, replacing it with its children
- 
firstByNameFind the first token in the tree by name (breadth-first)- Parameters:
- name- The name of the token to search for
- Returns:
- The first token found, or null
 
- 
allByNameFind all tokens in the tree by name- Parameters:
- order- The order to traverse the tree in
- name- The name of the token to search for
- Returns:
- All tokens found
 
- 
allByNameFind all tokens in the tree by name, breadth-first- Parameters:
- name- The name of the token to search for
- Returns:
- All tokens found
 
- 
allByNamesFind all tokens in the tree by any number of names and create a map, breadth-first- Parameters:
- names- The names to look for
- Returns:
- A map of names to the tokens with those names
 
- 
allByNamesFind all tokens in the tree by any number of names and create a map- Parameters:
- order- The order to traverse the tree in
- names- The names to look for
- Returns:
- A map of names to the tokens with those names
 
- 
walkWalks this Token tree in the given order- Parameters:
- order- The order to walk the tree in
- forEachNode- The lambda to apply to each token
 
- 
getObject- Returns:
- Nothing, unless this is an ObjectToken
 
- 
splitChildrenSplits child tokens on a given token by name- Parameters:
- name- The name of the token to split on
- Returns:
- A 2d list of tokens split by the given token
 
- 
cullCulls tokens in the tokens which are descendants of this one using filters.- Parameters:
- filters- The filters to cull tokens with
 
- 
addChildrenAppends the given tokens to this token's children- Parameters:
- tokens- The tokens to add
 
- 
toString
 
-