Class BaseParser
java.lang.Object
migratedb.v1.core.internal.parser.BaseParser
- All Implemented Interfaces:
Parser
- Direct Known Subclasses:
BigQueryParser,CockroachDBParser,DB2Parser,DerbyParser,FirebirdParser,H2Parser,HSQLDBParser,IgniteThinParser,InformixParser,MySQLParser,OracleParser,PostgreSQLParser,RedshiftParser,SAPHANAParser,SnowflakeParser,SpannerParser,SQLiteParser,SQLServerParser,SybaseASEParser
The main parser all database-specific parsers derive from.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseParser(Configuration configuration, ParsingContext parsingContext, int peekDepth) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadjustBlockDepth(ParserContext context, List<Token> tokens, Token keyword, PeekingReader reader) protected voidadjustDelimiter(ParserContext context, StatementType statementType) Adjusts the delimiter if necessary for this statement type.protected ParsedSqlStatementcreateStatement(PeekingReader reader, Recorder recorder, int statementPos, int statementLine, int statementCol, int nonCommentPartPos, int nonCommentPartLine, int nonCommentPartCol, StatementType statementType, boolean canExecuteInTransaction, Delimiter delimiter, String sql) protected BooleandetectCanExecuteInTransaction(String simplifiedStatement, List<Token> keywords) protected StatementTypedetectStatementType(String simplifiedStatement, ParserContext context, PeekingReader reader) protected booleandoTokensMatchPattern(List<Token> previousTokens, Token current, Pattern regex) protected charprotected charprotected charprotected Delimiterprotected charprotected intgetLastKeywordIndex(List<Token> tokens) protected intgetLastKeywordIndex(List<Token> tokens, int endIndex) protected SqlStatementgetNextStatement(Resource resource, PeekingReader reader, Recorder recorder, PositionTracker tracker, ParserContext context) protected charprotected static TokengetPreviousToken(List<Token> tokens, int parensDepth) protected intprotected TokenhandleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) protected TokenhandleCommentDirective(PeekingReader reader, ParserContext context, int pos, int line, int col) protected TokenhandleDelimiter(PeekingReader reader, ParserContext context, int pos, int line, int col) protected TokenhandleKeyword(PeekingReader reader, ParserContext context, int pos, int line, int col, String keyword) protected TokenhandleStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) protected booleanprotected booleanisCommentDirective(String peek) protected booleanisDelimiter(String peek, ParserContext context, int col, int colIgnoringWhitespace) protected booleanprotected booleanisLetter(char c, ParserContext context) protected booleanisSingleLineComment(String peek, ParserContext context, int col) protected static booleanlastTokenIs(List<Token> tokens, int parensDepth, String tokenText) protected static booleanlastTokenIsOnLine(List<Token> tokens, int parensDepth, int line) final SqlStatementIteratorfinal SqlStatementIteratorparse(Resource resource, SqlScriptMetadata metadata) Parses this resource into a stream of statements.protected StringreadIdentifier(PeekingReader reader) protected StringreadKeyword(PeekingReader reader, Delimiter delimiter, ParserContext context) protected ReaderreplacePlaceholders(Reader reader, SqlScriptMetadata metadata) Configures this reader for placeholder replacement.protected voidresetDelimiter(ParserContext context) Resets the delimiter to its default value before parsing a new statement.protected booleanshouldAdjustBlockDepth(ParserContext context, List<Token> tokens, Token token) protected booleanshouldDiscard(Token token, boolean nonCommentPartSeen) Whether the current set of tokens should be discarded.protected booleanprotected static booleantokenAtIndexIs(List<Token> tokens, int index, String tokenText)
-
Field Details
-
LOG
-
-
Constructor Details
-
BaseParser
-
-
Method Details
-
getConfiguration
- Specified by:
getConfigurationin interfaceParser
-
getParsingContext
- Specified by:
getParsingContextin interfaceParser
-
getDefaultDelimiter
-
getIdentifierQuote
protected char getIdentifierQuote() -
getAlternativeIdentifierQuote
protected char getAlternativeIdentifierQuote() -
getAlternativeStringLiteralQuote
protected char getAlternativeStringLiteralQuote() -
getOpeningIdentifierSymbol
protected char getOpeningIdentifierSymbol() -
getClosingIdentifierSymbol
protected char getClosingIdentifierSymbol() -
getValidKeywords
-
supportsPeekingMultipleLines
protected boolean supportsPeekingMultipleLines() -
parse
Description copied from interface:ParserParses this resource into a stream of statements. -
parse
-
replacePlaceholders
Configures this reader for placeholder replacement.- Parameters:
reader- The original reader.metadata- The resource's metadata.- Returns:
- The new reader with placeholder replacement.
-
getNextStatement
protected SqlStatement getNextStatement(Resource resource, PeekingReader reader, Recorder recorder, PositionTracker tracker, ParserContext context) -
shouldAdjustBlockDepth
-
shouldDiscard
Whether the current set of tokens should be discarded.- Parameters:
token- The latest token.nonCommentPartSeen- Whether a non-comment part has already been seen.- Returns:
trueif it should,falseif not.
-
resetDelimiter
Resets the delimiter to its default value before parsing a new statement. -
adjustDelimiter
Adjusts the delimiter if necessary for this statement type.- Parameters:
statementType- The statement type.
-
getTransactionalDetectionCutoff
protected int getTransactionalDetectionCutoff()- Returns:
- The cutoff point in terms of number of tokens after which a statement can no longer be non-transactional.
-
adjustBlockDepth
protected void adjustBlockDepth(ParserContext context, List<Token> tokens, Token keyword, PeekingReader reader) throws IOException - Throws:
IOException
-
getLastKeywordIndex
-
getLastKeywordIndex
-
getPreviousToken
-
lastTokenIs
-
lastTokenIsOnLine
-
tokenAtIndexIs
-
doTokensMatchPattern
-
createStatement
protected ParsedSqlStatement createStatement(PeekingReader reader, Recorder recorder, int statementPos, int statementLine, int statementCol, int nonCommentPartPos, int nonCommentPartLine, int nonCommentPartCol, StatementType statementType, boolean canExecuteInTransaction, Delimiter delimiter, String sql) throws IOException - Throws:
IOException
-
detectStatementType
protected StatementType detectStatementType(String simplifiedStatement, ParserContext context, PeekingReader reader) -
detectCanExecuteInTransaction
-
readKeyword
protected String readKeyword(PeekingReader reader, Delimiter delimiter, ParserContext context) throws IOException - Throws:
IOException
-
readIdentifier
- Throws:
IOException
-
handleDelimiter
protected Token handleDelimiter(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException - Throws:
IOException
-
isAlternativeStringLiteral
-
isDelimiter
protected boolean isDelimiter(String peek, ParserContext context, int col, int colIgnoringWhitespace) -
isLetter
-
isSingleLineComment
-
isKeyword
-
isCommentDirective
-
handleCommentDirective
protected Token handleCommentDirective(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException - Throws:
IOException
-
handleStringLiteral
protected Token handleStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException - Throws:
IOException
-
handleAlternativeStringLiteral
protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException - Throws:
IOException
-
handleKeyword
protected Token handleKeyword(PeekingReader reader, ParserContext context, int pos, int line, int col, String keyword) throws IOException - Throws:
IOException
-