Package adql.parser

Class ADQLParser

  • All Implemented Interfaces:
    ADQLParserConstants

    public class ADQLParser
    extends java.lang.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:
    QueryChecker, ADQLQueryFactory
    • Field Detail

      • REGEX_UNICODE_CONFUSABLES

        protected static final java.util.Map<java.lang.String,​java.lang.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 java.lang.String REGEX_DASH
        Regular expression matching all Unicode alternatives for -.
        Since:
        1.5
        See Also:
        Constant Field Values
      • REGEX_UNDERSCORE

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

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

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

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

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

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

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

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

        protected static final java.lang.String REGEX_EQUAL
        Regular expression matching all Unicode alternatives for =.
        Since:
        1.5
        See Also:
        Constant Field Values
      • token

        public Token token
        Current token.
      • jj_nt

        public Token jj_nt
        Next token.
    • Constructor Detail

      • 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​(java.io.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​(java.io.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​(java.io.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​(java.io.InputStream stream,
                          java.lang.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​(java.io.InputStream stream,
                          java.lang.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​(java.io.InputStream stream,
                          java.lang.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​(java.io.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​(java.io.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​(java.io.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​(java.io.InputStream stream)
        Constructor with InputStream.
      • ADQLParser

        public ADQLParser​(java.io.InputStream stream,
                          java.lang.String encoding)
        Constructor with InputStream and supplied encoding
      • ADQLParser

        public ADQLParser​(java.io.Reader stream)
        Constructor.