Class OBaseParser

java.lang.Object
com.orientechnologies.common.parser.OBaseParser
Direct Known Subclasses:
OCommandExecutorAbstract, OSQLPredicate, OSQLTarget

public abstract class OBaseParser extends Object
Abstract generic command to parse.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Field Details

    • parserText

      public String parserText
    • parserTextUpperCase

      public String 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 search
      iBeginIndex - Begin index
      iSeparatorChars - Separators as a String of multiple characters
      ioBuffer - StringBuilder object with the word found
    • getSyntax

      public String 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

      public String parserGetLastWord()
      Returns the last parsed word.
      Returns:
      Last parsed word as String
    • getLastWordLength

      public int getLastWordLength()
    • throwSyntaxErrorException

      protected abstract void throwSyntaxErrorException(String iText)
      Throws a syntax error exception.
      Parameters:
      iText - Text about the problem.
    • parserOptionalWord

      protected String parserOptionalWord(boolean iUpperCase)
      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

      protected String parseOptionalWord(boolean iUpperCase, String... iWords)
      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

      protected String parserRequiredWord(boolean iUpperCase)
      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

      protected String parserRequiredWord(boolean iUpperCase, String iCustomMessage)
      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 false
      iCustomMessage - Custom message to include in case of SyntaxError exception
      Returns:
      The word parsed
    • parserRequiredWord

      protected String parserRequiredWord(boolean iUpperCase, String iCustomMessage, String iSeparators)
      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 false
      iCustomMessage - Custom message to include in case of SyntaxError exception
      iSeparators - Separator characters
      Returns:
      The word parsed
    • parserRequiredKeyword

      protected void parserRequiredKeyword(String... iWords)
      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

      protected int parserNextChars(boolean iUpperCase, boolean iMandatory, String... iCandidateWords)
      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

      protected boolean parserOptionalKeyword(String... iWords)
      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

      protected String parserNextWord(boolean iForceUpperCase)
      Parses the next word.
      Parameters:
      iForceUpperCase - True if must return UPPERCASE, otherwise false
    • parserNextWord

      protected String parserNextWord(boolean iForceUpperCase, String iSeparatorChars)
      Parses the next word.
      Parameters:
      iForceUpperCase - True if must return UPPERCASE, otherwise false
      iSeparatorChars -
    • parserNextWord

      protected String parserNextWord(boolean iForceUpperCase, String iSeparatorChars, boolean preserveEscapes)