Class ADQLGrammarBase

java.lang.Object
adql.parser.grammar.ADQLGrammarBase
All Implemented Interfaces:
ADQLGrammar

public abstract class ADQLGrammarBase extends Object implements ADQLGrammar
Common partial implementation of an ADQLGrammar.
Since:
2.0
  • Field Details

    • queryFactory

      protected ADQLQueryFactory queryFactory
      Tool to build the object representation of the ADQL query.
    • query

      protected ADQLQuery query
      The object representation of the ADQL query to parse. (ONLY USED DURING THE PARSING, otherwise it is always NULL).
    • stackQuery

      protected Stack<ADQLQuery> stackQuery
      The stack of queries (in order to deal with sub-queries).
  • Constructor Details

    • ADQLGrammarBase

      public ADQLGrammarBase()
  • Method Details

    • getQueryFactory

      public final ADQLQueryFactory getQueryFactory()
      Description copied from interface: ADQLGrammar
      Get the ADQLQueryFactory used by this Grammar Parser to create ADQL object representations (e.g. SELECT, column, string, constraint) while building the ADQL query tree
      Specified by:
      getQueryFactory in interface ADQLGrammar
      Returns:
      The used ADQLQueryFactory. Never NULL
    • setQueryFactory

      public final void setQueryFactory(ADQLQueryFactory factory) throws NullPointerException
      Description copied from interface: ADQLGrammar
      Set the ADQLQueryFactory to use in order to create ADQL object representations (e.g. SELECT, column, string, constraint) while building the ADQL query tree.
      Specified by:
      setQueryFactory in interface ADQLGrammar
      Parameters:
      factory - The ADQLQueryFactory to use.
      Throws:
      NullPointerException - If the given factory is NULL.
    • reset

      public final void reset(InputStream inputADQLExpression) throws Exception
      Description copied from interface: ADQLGrammar
      (Re-)Set the ADQL expression to parse.

      Important note: This function MUST always be called BEFORE calling any parsing function.

      Specified by:
      reset in interface ADQLGrammar
      Parameters:
      inputADQLExpression - ADQL expression to parse.
      Throws:
      Exception - If any error occurs while initializing the parser.
    • ReInit

      public abstract void ReInit(InputStream stream)
      Re-initialize the input of the ADQL grammar parser.
      Parameters:
      stream - The new input stream to parse.
    • isRegularIdentifier

      public final boolean isRegularIdentifier(String idCandidate)
      Description copied from interface: ADQLGrammar
      Tell whether the given string is a valid ADQL regular identifier.

      According to the ADQL-2.0's BNF, a regular identifier (i.e. not delimited ; not between double quotes) must be a letter followed by a letter, digit or underscore. So, the following regular expression:

      [a-zA-Z]+[a-zA-Z0-9_]*

      This is what this function tests on the given string.

      Warning: This function may return a different result for different versions of the ADQL grammar.

      Specified by:
      isRegularIdentifier in interface ADQLGrammar
      Parameters:
      idCandidate - The string to test.
      Returns:
      true if the given string is a valid regular identifier, false otherwise.
      See Also:
    • testRegularIdentifier

      public final void testRegularIdentifier(Token token) throws ParseException
      Description copied from interface: ADQLGrammar
      Test the given token as an ADQL's regular identifier.

      Implementation note: This function uses ADQLGrammar.isRegularIdentifier(String) to test the given token's image. If the test fails, a ParseException is thrown.

      Specified by:
      testRegularIdentifier in interface ADQLGrammar
      Parameters:
      token - The token to test.
      Throws:
      ParseException - If the given token is not a valid ADQL regular identifier.
      See Also:
    • isEnd

      public boolean isEnd(Token token)
      Description copied from interface: ADQLGrammar
      Tell whether the given token represents the end of an ADQL query.

      Implementation note: NULL is considered as a last token of a set. So, by extension it should also be considered as the end of an ADQL query. But this method should rely on the ADQL grammar. Consequently, at least the token for the semi-colon (;) and the token for the End-Of-File (EOF) should be considered as the correct one to use to indicate the end of an ADQL query.

      Specified by:
      isEnd in interface ADQLGrammar
      Parameters:
      token - Token to analyze. Might be NULL.
      Returns:
      true if the given token represents a query end, false otherwise.
    • generateParseException

      public final ParseException generateParseException(Exception ex)
      Description copied from interface: ADQLGrammar
      Generate a ParseException instance representing the given Exception.

      Implementation note: If the given Exception is already a ParseException this function should do nothing else than returning it as such.

      Specified by:
      generateParseException in interface ADQLGrammar
      Parameters:
      ex - The exception to represent as a ParseException.
      Returns:
      The corresponding ParseException.