Class AnsiSqlParser

Object
gudusoft.gsqlparser.parser.AbstractSqlParser
gudusoft.gsqlparser.parser.AnsiSqlParser
All Implemented Interfaces:
SqlParser

public class AnsiSqlParser extends AbstractSqlParser
ANSI SQL parser implementation.

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:
  • 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

      protected TCustomLexer getLexer(ParserContext context)
      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:
      getLexer in class AbstractSqlParser
      Parameters:
      context - parser context (not used, lexer already created)
      Returns:
      the ANSI lexer instance created in constructor
    • getParser

      protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
      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:
      getParser in class AbstractSqlParser
      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

      protected void 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:
      tokenizeVendorSql in class AbstractSqlParser
    • 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:
      setupVendorParsersForExtraction in class AbstractSqlParser
    • 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:
      extractVendorRawStatements in class AbstractSqlParser
      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:
      performParsing in class AbstractSqlParser
      Parameters:
      context - parser context
      parser - main parser instance
      secondaryParser - secondary parser (null for ANSI)
      tokens - source token list
      rawStatements - raw statements to parse
      Returns:
      list of parsed statements
    • toString

      public String toString()
      Overrides:
      toString in class AbstractSqlParser