Package adql.parser

Class ADQLParser

java.lang.Object
adql.parser.ADQLParser
All Implemented Interfaces:
ADQLParserConstants

public class ADQLParser extends Object implements ADQLParserConstants
Parses an ADQL query thanks to the Query() function.

This parser is able, thanks to a QueryChecker object, to check each ADQLQuery just after its generation. It could be used to check the consistency between the ADQL query to parse and the "database" on which the query must be executed. By default, there is no QueryChecker. Thus you must extend QueryChecker to check semantically all generated ADQLQuery objects.

To create an object representation of the given ADQL query, this parser uses a ADQLQueryFactory object. So if you want customize some object (ie. CONTAINS) of this representation you just have to extend the corresponding default object (ie. ContainsFunction) and to extend the corresponding function of ADQLQueryFactory (ie. createContains(...)).

Here are the key functions to use:

  • parseQuery(java.lang.String) (or any of its alternatives) to parse an input ADQL query String and get its corresponding ADQL tree
  • tryQuickFix(java.lang.String) to try fixing the most common issues with ADQL queries (e.g. Unicode confusable characters, unescaped ADQL identifiers, SQL reserved keywords, ...)

WARNING: To modify this class it's strongly encouraged to modify the .jj file in the section between PARSER_BEGIN and PARSER_END and to re-compile it with JavaCC.

Version:
1.5 (03/2019)
Author:
Grégory Mantelet (CDS;ARI)
See Also:
  • Field Details

    • REGEX_UNICODE_CONFUSABLES

      protected static final Map<String,String> REGEX_UNICODE_CONFUSABLES
      All of the most common Unicode confusable characters and their ASCII/UTF-8 alternative.

      Keys of this map represent the ASCII character while the values are the regular expression for all possible Unicode alternatives.

      Note: All of them have been listed using Unicode Utilities: Confusables.

      Since:
      1.5
    • REGEX_DASH

      protected static final String REGEX_DASH
      Regular expression matching all Unicode alternatives for -.
      Since:
      1.5
      See Also:
    • REGEX_UNDERSCORE

      protected static final String REGEX_UNDERSCORE
      Regular expression matching all Unicode alternatives for _.
      Since:
      1.5
      See Also:
    • REGEX_QUOTE

      protected static final String REGEX_QUOTE
      Regular expression matching all Unicode alternatives for '.
      Since:
      1.5
      See Also:
    • REGEX_DOUBLE_QUOTE

      protected static final String REGEX_DOUBLE_QUOTE
      Regular expression matching all Unicode alternatives for ".
      Since:
      1.5
      See Also:
    • REGEX_STOP

      protected static final String REGEX_STOP
      Regular expression matching all Unicode alternatives for ..
      Since:
      1.5
      See Also:
    • REGEX_PLUS

      protected static final String REGEX_PLUS
      Regular expression matching all Unicode alternatives for +.
      Since:
      1.5
      See Also:
    • REGEX_SPACE

      protected static final String REGEX_SPACE
      Regular expression matching all Unicode alternatives for .
      Since:
      1.5
      See Also:
    • REGEX_LESS_THAN

      protected static final String REGEX_LESS_THAN
      Regular expression matching all Unicode alternatives for <.
      Since:
      1.5
      See Also:
    • REGEX_GREATER_THAN

      protected static final String REGEX_GREATER_THAN
      Regular expression matching all Unicode alternatives for >.
      Since:
      1.5
      See Also:
    • REGEX_EQUAL

      protected static final String REGEX_EQUAL
      Regular expression matching all Unicode alternatives for =.
      Since:
      1.5
      See Also:
    • token_source

      public ADQLParserTokenManager token_source
      Generated Token Manager.
    • token

      public Token token
      Current token.
    • jj_nt

      public Token jj_nt
      Next token.
  • Constructor Details

    • ADQLParser

      public ADQLParser()
      Builds an ADQL parser without a query to parse.
    • ADQLParser

      public ADQLParser(QueryChecker checker, ADQLQueryFactory factory)
      Builds an ADQL parser without a query to parse but with a QueryChecker and a ADQLQueryFactory.
      Parameters:
      checker - The object to use to check each ADQLQuery.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(QueryChecker checker)
      Builds an ADQL parser without a query to parse but with a QueryChecker.
      Parameters:
      checker - The object to use to check each ADQLQuery.
    • ADQLParser

      public ADQLParser(ADQLQueryFactory factory)
      Builds an ADQL parser without a query to parse but with a ADQLQueryFactory.
      Parameters:
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(InputStream stream, QueryChecker checker, ADQLQueryFactory factory)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      checker - The object to use to check each ADQLQuery.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(InputStream stream, QueryChecker checker)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      checker - The object to use to check each ADQLQuery.
    • ADQLParser

      public ADQLParser(InputStream stream, ADQLQueryFactory factory)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(InputStream stream, String encoding, QueryChecker checker, ADQLQueryFactory factory)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      encoding - The supplied encoding.
      checker - The object to use to check each ADQLQuery.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(InputStream stream, String encoding, QueryChecker checker)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      encoding - The supplied encoding.
      checker - The object to use to check each ADQLQuery.
    • ADQLParser

      public ADQLParser(InputStream stream, String encoding, ADQLQueryFactory factory)
      Builds a parser with a stream containing the query to parse.
      Parameters:
      stream - The stream in which the ADQL query to parse is given.
      encoding - The supplied encoding.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(Reader reader, QueryChecker checker, ADQLQueryFactory factory)
      Builds a parser with a reader containing the query to parse.
      Parameters:
      reader - The reader in which the ADQL query to parse is given.
      checker - The object to use to check each ADQLQuery.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(Reader reader, QueryChecker checker)
      Builds a parser with a reader containing the query to parse.
      Parameters:
      reader - The reader in which the ADQL query to parse is given.
      checker - The object to use to check each ADQLQuery.
    • ADQLParser

      public ADQLParser(Reader reader, ADQLQueryFactory factory)
      Builds a parser with a reader containing the query to parse.
      Parameters:
      reader - The reader in which the ADQL query to parse is given.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(ADQLParserTokenManager tm, QueryChecker checker, ADQLQueryFactory factory)
      Builds a parser with another token manager.
      Parameters:
      tm - The manager which associates a token to a numeric code.
      checker - The object to use to check each ADQLQuery.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(ADQLParserTokenManager tm, QueryChecker checker)
      Builds a parser with another token manager.
      Parameters:
      tm - The manager which associates a token to a numeric code.
      checker - The object to use to check each ADQLQuery.
    • ADQLParser

      public ADQLParser(ADQLParserTokenManager tm, ADQLQueryFactory factory)
      Builds a parser with another token manager.
      Parameters:
      tm - The manager which associates a token to a numeric code.
      factory - The object to use to build an object representation of the given ADQL query.
    • ADQLParser

      public ADQLParser(InputStream stream)
      Constructor with InputStream.
    • ADQLParser

      public ADQLParser(InputStream stream, String encoding)
      Constructor with InputStream and supplied encoding
    • ADQLParser

      public ADQLParser(Reader stream)
      Constructor.
    • ADQLParser

      public ADQLParser(ADQLParserTokenManager tm)
      Constructor with generated Token Manager.
  • Method Details