Class OBaseParser
java.lang.Object
com.orientechnologies.common.parser.OBaseParser
- Direct Known Subclasses:
OCommandExecutorAbstract,OSQLPredicate,OSQLTarget
Abstract generic command to parse.
- Author:
- Luca Garulli (l.garulli--(at)--orientdb.com)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintstatic voidgetWordStatic(CharSequence iText, int iBeginIndex, String iSeparatorChars, StringBuilder ioBuffer) static intnextWord(String iText, String iTextUpperCase, int ioCurrentPosition, StringBuilder ioWord, boolean iForceUpperCase) static intnextWord(String iText, String iTextUpperCase, int ioCurrentPosition, StringBuilder ioWord, boolean iForceUpperCase, String iSeparatorChars) protected StringparseOptionalWord(boolean iUpperCase, String... iWords) Parses the next word.charReturns the current character in the current stream positionintReturns the current stream position.charReturns the last separator encountered, otherwise returns a blank (' ').Returns the last parsed word.intReturns the stream position before last parsing.protected intGoes back to the previous position.booleanTells if the parsing has reached the end of the content.protected booleanparserMoveCurrentPosition(int iOffset) Moves the current stream position forward or backward of iOffset charactersprotected intparserNextChars(boolean iUpperCase, boolean iMandatory, String... iCandidateWords) Parses the next sequence of chars.protected StringparserNextWord(boolean iForceUpperCase) Parses the next word.protected StringparserNextWord(boolean iForceUpperCase, String iSeparatorChars) Parses the next word.protected StringparserNextWord(boolean iForceUpperCase, String iSeparatorChars, boolean preserveEscapes) protected booleanparserOptionalKeyword(String... iWords) Parses optional keywords between the iWords.protected StringparserOptionalWord(boolean iUpperCase) Parses the next word.protected voidparserRequiredKeyword(String... iWords) Parses the next word.protected StringparserRequiredWord(boolean iUpperCase) Parses the next word.protected StringparserRequiredWord(boolean iUpperCase, String iCustomMessage) Parses the next word.protected StringparserRequiredWord(boolean iUpperCase, String iCustomMessage, String iSeparators) Parses the next word.protected booleanparserSetCurrentPosition(int iPosition) Overwrites the current stream position.protected voidSets the end of text as positionvoidparserSetLastSeparator(char iSeparator) Overwrites the last separator.protected booleanSkips not valid characters like spaces and line feeds.protected abstract voidthrowSyntaxErrorException(String iText) Throws a syntax error exception.
-
Field Details
-
parserText
-
parserTextUpperCase
-
-
Constructor Details
-
OBaseParser
public OBaseParser()
-
-
Method Details
-
nextWord
public static int nextWord(String iText, String iTextUpperCase, int ioCurrentPosition, StringBuilder ioWord, boolean iForceUpperCase) -
nextWord
public static int nextWord(String iText, String iTextUpperCase, int ioCurrentPosition, StringBuilder ioWord, boolean iForceUpperCase, String iSeparatorChars) -
getWordStatic
public static void getWordStatic(CharSequence iText, int iBeginIndex, String iSeparatorChars, StringBuilder ioBuffer) - Parameters:
iText- Text where to searchiBeginIndex- Begin indexiSeparatorChars- Separators as a String of multiple charactersioBuffer- StringBuilder object with the word found
-
getSyntax
-
parserGetLastSeparator
public char parserGetLastSeparator()Returns the last separator encountered, otherwise returns a blank (' '). -
parserSetLastSeparator
public void parserSetLastSeparator(char iSeparator) Overwrites the last separator. To ignore it set it to blank (' '). -
parserGetPreviousPosition
public int parserGetPreviousPosition()Returns the stream position before last parsing.- Returns:
- Offset from the beginning
-
parserIsEnded
public boolean parserIsEnded()Tells if the parsing has reached the end of the content.- Returns:
- True if is ended, otherwise false
-
parserGetCurrentPosition
public int parserGetCurrentPosition()Returns the current stream position.- Returns:
- Offset from the beginning
-
parserGetCurrentChar
public char parserGetCurrentChar()Returns the current character in the current stream position- Returns:
- The current character in the current stream position. If the end is reached, then a blank (' ') is returned
-
parserGetLastWord
Returns the last parsed word.- Returns:
- Last parsed word as String
-
getLastWordLength
public int getLastWordLength() -
throwSyntaxErrorException
Throws a syntax error exception.- Parameters:
iText- Text about the problem.
-
parserOptionalWord
Parses the next word. It returns the word parsed if any.- Parameters:
iUpperCase- True if must return UPPERCASE, otherwise false- Returns:
- The word parsed if any, otherwise null
-
parseOptionalWord
Parses the next word. If any word is parsed it's checked against the word array received as parameter. If the parsed word is not enlisted in it a SyntaxError exception is thrown. It returns the word parsed if any.- Parameters:
iUpperCase- True if must return UPPERCASE, otherwise false- Returns:
- The word parsed if any, otherwise null
-
parserGoBack
protected int parserGoBack()Goes back to the previous position.- Returns:
- The previous position
-
parserRequiredWord
Parses the next word. If no word is found an SyntaxError exception is thrown It returns the word parsed if any.- Parameters:
iUpperCase- True if must return UPPERCASE, otherwise false- Returns:
- The word parsed
-
parserRequiredWord
Parses the next word. If no word is found an SyntaxError exception with the custom message received as parameter is thrown It returns the word parsed if any.- Parameters:
iUpperCase- True if must return UPPERCASE, otherwise falseiCustomMessage- Custom message to include in case of SyntaxError exception- Returns:
- The word parsed
-
parserRequiredWord
Parses the next word. If no word is found or the parsed word is not present in the word array received as parameter then a SyntaxError exception with the custom message received as parameter is thrown. It returns the word parsed if any.- Parameters:
iUpperCase- True if must return UPPERCASE, otherwise falseiCustomMessage- Custom message to include in case of SyntaxError exceptioniSeparators- Separator characters- Returns:
- The word parsed
-
parserRequiredKeyword
Parses the next word. If no word is found or the parsed word is not present in the word array received as parameter then a SyntaxError exception is thrown.- Parameters:
iWords- Array of expected keywords
-
parserNextChars
Parses the next sequence of chars.- Returns:
- The position of the word matched if any, otherwise -1 or an exception if iMandatory is true
-
parserOptionalKeyword
Parses optional keywords between the iWords. If a keyword is found but doesn't match with iWords then a SyntaxError is raised.- Parameters:
iWords- Optional words to match as keyword. If at least one is passed, then the check is made- Returns:
- true if a keyword was found, otherwise false
-
parserSkipWhiteSpaces
protected boolean parserSkipWhiteSpaces()Skips not valid characters like spaces and line feeds.- Returns:
- True if the string is not ended, otherwise false
-
parserSetCurrentPosition
protected boolean parserSetCurrentPosition(int iPosition) Overwrites the current stream position.- Parameters:
iPosition- New position- Returns:
- True if the string is not ended, otherwise false
-
parserSetEndOfText
protected void parserSetEndOfText()Sets the end of text as position -
parserMoveCurrentPosition
protected boolean parserMoveCurrentPosition(int iOffset) Moves the current stream position forward or backward of iOffset characters- Parameters:
iOffset- Number of characters to move. Negative numbers means backwards- Returns:
- True if the string is not ended, otherwise false
-
parserNextWord
Parses the next word.- Parameters:
iForceUpperCase- True if must return UPPERCASE, otherwise false
-
parserNextWord
Parses the next word.- Parameters:
iForceUpperCase- True if must return UPPERCASE, otherwise falseiSeparatorChars-
-
parserNextWord
-