public class DamengSqlParser extends AbstractSqlParser
This parser handles Dameng-specific SQL syntax including:
Implementation Status: PHASE 3 - IN PROGRESS
Design Notes:
SqlParser directly (will extend AbstractSqlParser in Phase 4)TLexerDameng, TParserDameng, TParserDamengUsage Example:
// Get Dameng parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvdameng);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvdameng)
.sqlText("SELECT * FROM emp WHERE deptno = 10")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
Phase 3 Extraction Roadmap:
Key Methods to Extract from TGSqlParser:
dodamengsqltexttotokenlist() - Dameng tokenization with SQL*Plus command detectiondodamenggetrawsqlstatements() - Dameng raw statement boundaries (handles PL/SQL blocks)getanewsourcetoken() - Token iterator from lexergetprevsolidtoken() - Navigate token list backwardsIsValidPlaceForDivToSqlplusCmd() - Slash vs divide operator disambiguationcountLines() - Multi-line token handlingspaceAtTheEndOfReturnToken() - SQL*Plus command validationSqlParser,
AbstractSqlParser,
TLexerDameng,
TParserDameng,
TParserDamengAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerDameng |
flexer
The Dameng lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
DamengSqlParser()
Construct Dameng SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Override to provide Dameng-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 Dameng-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Dameng lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Dameng SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Return the Dameng PL/SQL parser instance with updated token list.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform Dameng-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 Dameng-specific semantic analysis using TSQLResolver.
|
protected void |
setupVendorParsersForExtraction()
Setup Dameng parsers for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call Dameng-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 TLexerDameng flexer
public DamengSqlParser()
Configures the parser for Dameng 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)
Dameng needs a secondary parser (TParserDameng) 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 dodamengsqltexttotokenlist which handles Dameng'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()
Dameng 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 dodamenggetrawsqlstatements which handles Dameng'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 (TParserDameng)secondaryParser - PL/SQL parser (TParserDameng)tokens - source token listrawStatements - raw statements already extracted (never null)protected void afterStatementParsed(TCustomSqlStatement stmt)
For Dameng, 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