Class SqlParserUtils


  • public class SqlParserUtils
    extends Object
    Parser utility methods.
    • Method Detail

      • parseIfExists

        public static boolean parseIfExists​(SqlLexer lex)
        Parse IF EXISTS statement.
        Parameters:
        lex - Lexer.
        Returns:
        True if statement is found.
      • parseIfNotExists

        public static boolean parseIfNotExists​(SqlLexer lex)
        Parse IF NOT EXISTS statement.
        Parameters:
        lex - Lexer.
        Returns:
        True if statement is found.
      • skipCommaOrRightParenthesis

        public static boolean skipCommaOrRightParenthesis​(SqlLexer lex)
        Skip comma or right parenthesis.
        Parameters:
        lex - Lexer.
        Returns:
        True if right parenthesis is found.
      • parseInt

        public static int parseInt​(SqlLexer lex)
        Parse integer value (positive or negative).
        Parameters:
        lex - Lexer.
        Returns:
        Integer value.
      • parseBoolean

        public static boolean parseBoolean​(SqlLexer lex)
        Parse boolean parameter value based on presence of tokens 1, 0, ON, OFF. Not that this is not and is not intended to be routine for parsing a boolean literal from TRUE/FALSE.
        Parameters:
        lex - Lexer.
        Returns:
        Boolean parameter value.
      • parseIdentifier

        public static String parseIdentifier​(SqlLexer lex,
                                             String... additionalExpTokens)
        Process name.
        Parameters:
        lex - Lexer.
        additionalExpTokens - Additional expected tokens in case of error.
        Returns:
        Name.
      • parseUsername

        public static String parseUsername​(SqlLexer lex,
                                           String... additionalExpTokens)
        Process name.
        Parameters:
        lex - Lexer.
        additionalExpTokens - Additional expected tokens in case of error.
        Returns:
        Name.
      • parseString

        public static String parseString​(SqlLexer lex,
                                         String... additionalExpTokens)
        Process name.
        Parameters:
        lex - Lexer.
        additionalExpTokens - Additional expected tokens in case of error.
        Returns:
        Name.
      • parseQualifiedIdentifier

        public static SqlQualifiedName parseQualifiedIdentifier​(SqlLexer lex,
                                                                String... additionalExpTokens)
        Process qualified name.
        Parameters:
        lex - Lexer.
        additionalExpTokens - Additional expected tokens in case of error.
        Returns:
        Qualified name.
      • isValidIdentifier

        public static boolean isValidIdentifier​(SqlLexerToken token)
        Check if token is identifier.
        Parameters:
        token - Token.
        Returns:
        True if we are standing on possible identifier.
      • matchesKeyword

        public static boolean matchesKeyword​(SqlLexerToken token,
                                             String expKeyword)
        Check if current lexer token matches expected.
        Parameters:
        token - Token..
        expKeyword - Expected keyword.
        Returns:
        True if matches.
      • skipIfMatchesKeyword

        public static void skipIfMatchesKeyword​(SqlLexer lex,
                                                String expKeyword)
        Skip token if it matches expected keyword.
        Parameters:
        lex - Lexer.
        expKeyword - Expected keyword.
      • skipIfMatchesOptionalKeyword

        public static boolean skipIfMatchesOptionalKeyword​(SqlLexer lex,
                                                           String expKeyword)
        Skip token if it matches expected keyword by using lookahead. If next token is not what we expect, no shift is done.
        Parameters:
        lex - Lexer.
        expKeyword - Expected keyword.
        Returns:
        true In case token mathes, false otherwise.
      • skipIfMatches

        public static void skipIfMatches​(SqlLexer lex,
                                         SqlLexerTokenType tokenTyp)
        Skip next token if it matches expected type.
        Parameters:
        lex - Lexer.
        tokenTyp - Expected token type.
      • error

        public static SqlParseException error​(SqlLexerToken token,
                                              String msg)
        Create parse exception referring to current lexer position.
        Parameters:
        token - Token.
        msg - Message.
        Returns:
        Exception.
      • errorUnexpectedToken

        public static SqlParseException errorUnexpectedToken​(SqlLexerToken token)
        Create generic parse exception due to unexpected token.
        Parameters:
        token - Token.
        Returns:
        Exception.
      • errorUnsupportedIfMatchesKeyword

        public static void errorUnsupportedIfMatchesKeyword​(SqlLexerToken token,
                                                            String keyword)
        Throw unsupported token exception if passed keyword is found.
        Parameters:
        token - Token.
        keyword - Keyword.
      • errorUnsupportedIfMatchesKeyword

        public static void errorUnsupportedIfMatchesKeyword​(SqlLexerToken token,
                                                            String... keywords)
        Throw unsupported token exception if one of passed keywords is found.
        Parameters:
        token - Token.
        keywords - Keywords.
      • errorUnsupported

        public static SqlParseException errorUnsupported​(SqlLexerToken token)
        Error on unsupported keyword.
        Parameters:
        token - Token.
        Returns:
        Error.
      • errorUnexpectedToken

        public static SqlParseException errorUnexpectedToken​(SqlLexer lex,
                                                             String expToken)
        Create generic parse exception due to unexpected token.
        Parameters:
        lex - Lexer.
        expToken - Expected token.
        Returns:
        Exception.
      • errorUnexpectedToken

        public static SqlParseException errorUnexpectedToken​(SqlLexerToken token,
                                                             String firstExpToken,
                                                             String... expTokens)
        Create generic parse exception due to unexpected token.
        Parameters:
        token - Token.
        firstExpToken - First expected token.
        expTokens - Additional expected tokens (if any).
        Returns:
        Exception.