Class AnsiSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles ANSI standard SQL syntax. It delegates tokenization and raw statement extraction to DB2 logic, as ANSI SQL shares similar parsing characteristics with DB2.
Design Notes:
- Extends
AbstractSqlParser - Can directly instantiate:
TLexerAnsi,TParserAnsi - Uses single parser (no secondary parser)
- Delimiter character: ';' (semicolon)
- Shares tokenization and extraction logic with DB2
Migrated from TGSqlParser:
- doansitexttotokenlist() → delegates to dodb2sqltexttotokenlist()
- doansigetrawsqlstatements() → delegates to dodb2getrawsqlstatements()
- Since:
- 3.2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
AbstractSqlParser.PreparedSqlReader -
Field Summary
Fields inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCall ANSI-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the ANSI lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the ANSI SQL parser instance with updated token list.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing on raw ANSI SQL statements.protected voidSetup ANSI parser for raw statement extraction.protected voidCall ANSI-specific tokenization logic.toString()Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
afterStatementParsed, attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSecondaryParser, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performInterpreter, performSemanticAnalysis, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreak
-
Constructor Details
-
AnsiSqlParser
public AnsiSqlParser()Construct ANSI SQL parser.Configures the parser for ANSI standard SQL with default delimiter: semicolon (;)
Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.
-
-
Method Details
-
getLexer
Return the ANSI lexer instance.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.
- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- parser context (not used, lexer already created)- Returns:
- the ANSI lexer instance created in constructor
-
getParser
Return the ANSI SQL parser instance with updated token list.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.
- Specified by:
getParserin classAbstractSqlParser- Parameters:
context- parser context (not used, parser already created)tokens- source token list to parse- Returns:
- the ANSI SQL parser instance created in constructor
-
tokenizeVendorSql
Call ANSI-specific tokenization logic.Delegates to dodb2sqltexttotokenlist which handles ANSI/DB2 specific keyword recognition and token generation.
This follows the original TGSqlParser pattern where doansitexttotokenlist() delegates to dodb2sqltexttotokenlist().
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup ANSI parser for raw statement extraction.ANSI uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call ANSI-specific raw statement extraction logic.Delegates to dodb2getrawsqlstatements which handles ANSI/DB2 statement boundaries and compound blocks.
This follows the original TGSqlParser pattern where doansigetrawsqlstatements() delegates to dodb2getrawsqlstatements().
- Specified by:
extractVendorRawStatementsin classAbstractSqlParser- Parameters:
builder- result builder to populate
-
performParsing
protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing on raw ANSI SQL statements.This method parses each raw statement into a complete parse tree, handling stored procedures, functions, triggers, and nested blocks.
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- parser contextparser- main parser instancesecondaryParser- secondary parser (null for ANSI)tokens- source token listrawStatements- raw statements to parse- Returns:
- list of parsed statements
-
toString
- Overrides:
toStringin classAbstractSqlParser
-