Package com.gengoai.parsing
Class ParserToken
- java.lang.Object
-
- com.gengoai.parsing.ParserToken
-
- All Implemented Interfaces:
Serializable
public class ParserToken extends Object implements Serializable
A token and its associated metadata extracted via aLexer
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ParserToken(Tag type, String text, int start)
Instantiates a new Parser token.ParserToken(Tag type, String text, int start, int end)
Instantiates a new Parser token.ParserToken(Tag type, String text, int start, int end, String[] variables)
Instantiates a new Parser token.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int
getEndOffset()
Gets the ending character offset of the token in the stream.int
getStartOffset()
Gets the starting character offset of the token in the stream.String
getText()
Gets the extracted surface text of the tokenTag
getType()
Gets the token's associated typeString
getVariable(int index)
Gets a variable captured with the token.int
getVariableCount()
Gets the number of variables associated with the tokenString[]
getVariables()
Gets the token variables as an array of Stringint
hashCode()
boolean
isInstance(Tag... tags)
Checks if the token's tag is an instance of one of the given tagsString
toString()
-
-
-
Constructor Detail
-
ParserToken
public ParserToken(Tag type, String text, int start, int end)
Instantiates a new Parser token.- Parameters:
type
- the typetext
- the textstart
- the startend
- the end
-
ParserToken
public ParserToken(Tag type, String text, int start)
Instantiates a new Parser token.- Parameters:
type
- the typetext
- the textstart
- the start
-
-
Method Detail
-
getEndOffset
public int getEndOffset()
Gets the ending character offset of the token in the stream.- Returns:
- the ending character offset
-
getStartOffset
public int getStartOffset()
Gets the starting character offset of the token in the stream.- Returns:
- the starting character offset
-
getText
public String getText()
Gets the extracted surface text of the token- Returns:
- the surface text of the token
-
getType
public Tag getType()
Gets the token's associated type- Returns:
- the token's type
-
getVariable
public String getVariable(int index)
Gets a variable captured with the token.- Parameters:
index
- the index of the variable- Returns:
- the variable value or null if the index is invalid or there are no variables
-
getVariableCount
public int getVariableCount()
Gets the number of variables associated with the token- Returns:
- the number of variables
-
getVariables
public String[] getVariables()
Gets the token variables as an array of String- Returns:
- the string array of token variables
-
isInstance
public boolean isInstance(Tag... tags)
Checks if the token's tag is an instance of one of the given tags- Parameters:
tags
- the tags to check- Returns:
- True if this token's tag is an instance of any of the given tags
-
-