Class ParserAbstract<S extends AbstractDatabase>

java.lang.Object
org.pgcodekeeper.core.parsers.antlr.base.statement.ParserAbstract<S>
Direct Known Subclasses:
ChParserAbstract, MsParserAbstract, PgParserAbstract

public abstract class ParserAbstract<S extends AbstractDatabase> extends Object
Abstract base class for database object parsers that provides common parsing functionality and utilities for working with ANTLR-generated parse trees.
  • Method Details

    • parseObject

      public void parseObject(String fileName, ParserListenerMode mode, org.antlr.v4.runtime.ParserRuleContext ctx)
      Parses a database object from the given parse tree context.
      Parameters:
      fileName - the source file being parsed
      mode - the parsing mode (REF, SCRIPT, etc.)
      ctx - the ANTLR parse tree context to parse from
    • parseObject

      public abstract void parseObject()
      Parses a database object from the current context. Must be implemented by concrete subclasses to handle specific object types.
    • getFullCtxText

      public static String getFullCtxText(org.antlr.v4.runtime.ParserRuleContext ctx)
      Extracts raw text from context
      Parameters:
      ctx - context
      Returns:
      raw string
    • getFullCtxText

      public static String getFullCtxText(org.antlr.v4.runtime.ParserRuleContext start, org.antlr.v4.runtime.ParserRuleContext end)
      Extracts raw text between two parse tree contexts.
      Parameters:
      start - the starting context
      end - the ending context
      Returns:
      the text between the contexts
    • getFullCtxText

      public static String getFullCtxText(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.Token end)
      Extracts raw text between two tokens.
      Parameters:
      start - the starting token
      end - the ending token
      Returns:
      the text between the tokens
    • parseArgMode

      public static ArgMode parseArgMode(org.antlr.v4.runtime.ParserRuleContext mode)
      Parses an argument mode from a parse tree context.
      Parameters:
      mode - the mode parse tree context
      Returns:
      the parsed ArgMode
    • getSafe

      public <T extends IStatement, R extends IStatement> R getSafe(BiFunction<T,String,R> getter, T container, org.antlr.v4.runtime.ParserRuleContext ctx)
      Safely retrieves a database statement with validation.

      Note: Always returns null if parser is in ref mode.

      Type Parameters:
      T - the container statement type
      R - the child statement type
      Parameters:
      getter - the getter function to retrieve the child
      container - the containing statement
      ctx - the parse tree context
      Returns:
      the found statement or null if parser is in ref mode
      Throws:
      UnresolvedReferenceException - if statement not found
    • getSafe

      public <T extends IStatement, R extends IStatement> R getSafe(BiFunction<T,String,R> getter, T container, String name, org.antlr.v4.runtime.Token errToken)
      Safely retrieves a database statement by name with validation.

      Note: Always returns null if parser is in ref mode.

      Type Parameters:
      T - the container statement type
      R - the child statement type
      Parameters:
      getter - the getter function to retrieve the child
      container - the containing statement
      name - the name of the statement to find
      errToken - the token for error reporting
      Returns:
      the found statement
      Throws:
      UnresolvedReferenceException - if statement not found
    • fillOptionParams

      public static void fillOptionParams(String[] options, BiConsumer<String,String> c, boolean isToast, boolean forceQuote, boolean isQuoted)
      Processes option parameters into key-value pairs.
      Parameters:
      options - the option strings to parse
      c - the consumer to receive each key-value pair
      isToast - whether these are TOAST options
      forceQuote - whether to force quoting of values
      isQuoted - whether values are already quoted
    • fillOptionParams

      public static void fillOptionParams(String value, String option, boolean isToast, BiConsumer<String,String> c)
      Processes a single option parameter.
      Parameters:
      value - the option value
      option - the option name
      isToast - whether this is a TOAST option
      c - the consumer to receive the key-value pair