public class OceanBaseOracleSqlParser extends AbstractSqlParser
This class is a verbatim fork of OracleSqlParser with class
names rewritten to point at the forked grammar artifacts under
gsp_java_parser/.../parser/oceanbaseoracle/. The structural
intent is identical to the Oracle parser; what differs is:
TLexerOceanbaseoracle,
TParserOceanbaseoracle, and
TParserOceanbaseoracleplsql (generated
from the forked lzlexoceanbaseoracle.l,
lzyaccoceanbaseoracle.y, and
lzyaccoceanbaseoracleplsql.y sources).EDbVendor.dbvoceanbase so downstream
components (sqlcmds, IdentifierProfile, the various TSQLEnv
EnumMaps) consult OceanBase rules rather than Oracle rules.OceanBaseSqlParser when the active
EOBTenantMode is
EOBTenantMode.ORACLE.Phase 3 ships this fork at zero divergence from the Oracle base
grammar — same shift/reduce conflicts (60 s/r + 2 r/r in SQL parser),
same token positions, same statement coverage including full PL/SQL
(packages, procedures, functions, triggers, anonymous blocks,
SQL*Plus commands, hierarchical query, MERGE, MODEL clause).
OceanBase-specific Oracle-mode extensions (hints, partition
extensions, tenant DDL, outlines, tablegroups) arrive incrementally
in Phase 4 via additive edits to the .y sources. Each Phase 4
addition is tracked in oceanbaseoracle/FORK_DIVERGENCE.md.
Token alignment between lzyaccoceanbaseoracle.y and
lzyaccoceanbaseoracleplsql.y is mandatory and enforced by
oceanbaseoracle/check_token_alignment.sh. Both files MUST
declare identical tokens at identical positions or the SQL lexer and
the PL/SQL parser disagree silently — see CLAUDE.md and the
Phase 0 plan for the rationale.
Backporting upstream Oracle grammar fixes is documented in the
Phase 0 plan (gsp_java_core/doc/oceanbase/PHASE0_REPORT.md)
and the per-fork oceanbaseoracle/REGEN.md.
AbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerOceanbaseoracle |
flexer
The Oracle lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
OceanBaseOracleSqlParser()
Construct Oracle SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Override to provide Oracle-specific post-processing after statement parsing.
|
protected void |
doAfterTokenize(TSourceTokenList tokens)
Post-tokenization: merge ${...} template variable tokens into single IDENT tokens.
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call Oracle-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Oracle lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Oracle SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Return the Oracle PL/SQL parser instance with updated token list.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform Oracle-specific AST interpretation/evaluation using TASTEvaluator.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Perform full parsing of statements with syntax checking.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform Oracle-specific semantic analysis using TSQLResolver.
|
protected void |
setupVendorParsersForExtraction()
Setup Oracle parsers for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call Oracle-specific tokenization logic.
|
String |
toString()
Copy syntax errors from a statement to our error list.
|
attemptErrorRecovery, copyErrorsFromStatement, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic TLexerOceanbaseoracle flexer
public OceanBaseOracleSqlParser()
Configures the parser for Oracle database with default delimiters:
Following the original TGSqlParser pattern, the lexer and parsers are created once in the constructor and reused for all parsing operations. This avoids unnecessary object allocation overhead since the parser is not thread-safe and designed for single-use per instance.
protected TCustomLexer getLexer(ParserContext context)
The lexer is created once in the constructor and reused for all parsing operations. This method simply returns the existing instance, matching the original TGSqlParser pattern where the lexer is created once and reset before each use.
getLexer in class AbstractSqlParsercontext - parser context (not used, lexer already created)protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
The parser is created once in the constructor and reused for all parsing operations. This method updates the token list and returns the existing instance, matching the original TGSqlParser pattern.
getParser in class AbstractSqlParsercontext - parser context (not used, parser already created)tokens - source token list to parseprotected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens)
Oracle needs a secondary parser (TParserOceanbaseoracleplsql) for PL/SQL blocks (procedures, functions, packages, triggers, anonymous blocks).
The parser is created once in the constructor and reused for all parsing operations. This method updates the token list and returns the existing instance, matching the original TGSqlParser pattern.
getSecondaryParser in class AbstractSqlParsercontext - parser context (not used, parser already created)tokens - source token list to parseprotected void tokenizeVendorSql()
Delegates to dooraclesqltexttotokenlist which handles Oracle's specific keyword recognition, SQL*Plus commands, forward slash disambiguation, and token generation.
tokenizeVendorSql in class AbstractSqlParserprotected void doAfterTokenize(TSourceTokenList tokens)
doAfterTokenize in class AbstractSqlParsertokens - the source token list (mutable)protected void setupVendorParsersForExtraction()
Oracle uses dual parsers (SQL + PL/SQL), so we inject sqlcmds and update token lists for both parsers.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to dooraclegetrawsqlstatements which handles Oracle's statement delimiters (semicolon and forward slash).
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method orchestrates the parsing of all statements by:
Important: This method does NOT extract raw statements - they are
passed in as a parameter already extracted by AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long).
This eliminates duplicate extraction that was occurring in the old design.
Extracted from: TGSqlParser.doparse() lines 16903-17026
performParsing in class AbstractSqlParsercontext - parser contextparser - main SQL parser (TParserOceanbaseoracle)secondaryParser - PL/SQL parser (TParserOceanbaseoracleplsql)tokens - source token listrawStatements - raw statements already extracted (never null)protected void afterStatementParsed(TCustomSqlStatement stmt)
For Oracle, we check if the statement is PL/SQL and recursively find syntax errors in nested PL/SQL statements.
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsedprotected void performSemanticAnalysis(ParserContext context, TStatementList statements)
This includes:
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statementsprotected void performInterpreter(ParserContext context, TStatementList statements)
This executes simple SQL statements and evaluates expressions for static analysis and constant folding.
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statementspublic String toString()
toString in class AbstractSqlParser