public class ADQLParser extends java.lang.Object implements ADQLParserConstants
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.
QueryChecker
,
ADQLQueryFactory
Modifier and Type | Field and Description |
---|---|
Token |
jj_nt
Next token.
|
protected static java.lang.String |
REGEX_DASH
Regular expression matching all Unicode alternatives for
- . |
protected static java.lang.String |
REGEX_DOUBLE_QUOTE
Regular expression matching all Unicode alternatives for
" . |
protected static java.lang.String |
REGEX_EQUAL
Regular expression matching all Unicode alternatives for
= . |
protected static java.lang.String |
REGEX_GREATER_THAN
Regular expression matching all Unicode alternatives for
> . |
protected static java.lang.String |
REGEX_LESS_THAN
Regular expression matching all Unicode alternatives for
< . |
protected static java.lang.String |
REGEX_PLUS
Regular expression matching all Unicode alternatives for
+ . |
protected static java.lang.String |
REGEX_QUOTE
Regular expression matching all Unicode alternatives for
' . |
protected static java.lang.String |
REGEX_SPACE
Regular expression matching all Unicode alternatives for
. |
protected static java.lang.String |
REGEX_STOP
Regular expression matching all Unicode alternatives for
. . |
protected static java.lang.String |
REGEX_UNDERSCORE
Regular expression matching all Unicode alternatives for
_ . |
protected static 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.
|
Token |
token
Current token.
|
ADQLParserTokenManager |
token_source
Generated Token Manager.
|
ABS, ACOS, AND, AREA, AS, ASC, ASIN, ASTERISK, ATAN, ATAN2, AVG, BETWEEN, BOX, BY, CEILING, CENTROID, CIRCLE, COMMA, CONCAT, CONTAINS, COORD1, COORD2, COORDSYS, COS, COT, COUNT, DEFAULT, DEGREES, DELIMITED_IDENTIFIER, DESC, DIGIT, DISTANCE, DIVIDE, DOT, EOF, EOQ, EQUAL, EXISTS, EXP, FLOOR, FROM, FULL, GREATER_EQUAL_THAN, GREATER_THAN, GROUP, HAVING, IN, INNER, INTERSECTS, IS, JOIN, LEFT, LEFT_PAR, LESS_EQUAL_THAN, LESS_THAN, Letter, LIKE, LOG, LOG10, MAX, MIN, MINUS, MOD, NATURAL, NOT, NOT_EQUAL, NULL, ON, OR, ORDER, OUTER, PI, PLUS, POINT, POLYGON, POWER, QUANTIFIER, RADIANS, RAND, REGION, REGULAR_IDENTIFIER_CANDIDATE, RIGHT, RIGHT_PAR, ROUND, SCIENTIFIC_NUMBER, SELECT, SIN, SQL_RESERVED_WORD, SQRT, STRING_LITERAL, SUM, TAN, tokenImage, TOP, TRUNCATE, UNSIGNED_FLOAT, UNSIGNED_INTEGER, USING, WHERE, WithinDelimitedId, WithinString
Constructor and Description |
---|
ADQLParser()
Builds an ADQL parser without a query to parse.
|
ADQLParser(ADQLParserTokenManager tm)
Constructor with generated Token Manager.
|
ADQLParser(ADQLParserTokenManager tm,
ADQLQueryFactory factory)
Builds a parser with another token manager.
|
ADQLParser(ADQLParserTokenManager tm,
QueryChecker checker)
Builds a parser with another token manager.
|
ADQLParser(ADQLParserTokenManager tm,
QueryChecker checker,
ADQLQueryFactory factory)
Builds a parser with another token manager.
|
ADQLParser(ADQLQueryFactory factory)
Builds an ADQL parser without a query to parse but with a
ADQLQueryFactory . |
ADQLParser(java.io.InputStream stream)
Constructor with InputStream.
|
ADQLParser(java.io.InputStream stream,
ADQLQueryFactory factory)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(java.io.InputStream stream,
QueryChecker checker)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(java.io.InputStream stream,
QueryChecker checker,
ADQLQueryFactory factory)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(java.io.InputStream stream,
java.lang.String encoding)
Constructor with InputStream and supplied encoding
|
ADQLParser(java.io.InputStream stream,
java.lang.String encoding,
ADQLQueryFactory factory)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(java.io.InputStream stream,
java.lang.String encoding,
QueryChecker checker)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(java.io.InputStream stream,
java.lang.String encoding,
QueryChecker checker,
ADQLQueryFactory factory)
Builds a parser with a stream containing the query to parse.
|
ADQLParser(QueryChecker checker)
Builds an ADQL parser without a query to parse but with a
QueryChecker . |
ADQLParser(QueryChecker checker,
ADQLQueryFactory factory)
Builds an ADQL parser without a query to parse but with a
QueryChecker and a ADQLQueryFactory . |
ADQLParser(java.io.Reader stream)
Constructor.
|
ADQLParser(java.io.Reader reader,
ADQLQueryFactory factory)
Builds a parser with a reader containing the query to parse.
|
ADQLParser(java.io.Reader reader,
QueryChecker checker)
Builds a parser with a reader containing the query to parse.
|
ADQLParser(java.io.Reader reader,
QueryChecker checker,
ADQLQueryFactory factory)
Builds a parser with a reader containing the query to parse.
|
Modifier and Type | Method and Description |
---|---|
Between |
BetweenEnd(ADQLOperand leftOp) |
ADQLColumn |
Column() |
IdentifierItems |
ColumnName()
Extracts the name of a column with its possible catalog, schema and table prefixes.
|
Comparison |
ComparisonEnd(ADQLOperand leftOp) |
ClauseConstraints |
ConditionsList(ClauseConstraints clause) |
ADQLConstraint |
Constraint() |
ADQLOperand[] |
Coordinates() |
ADQLOperand |
CoordinateSystem() |
void |
disable_tracing()
Disable tracing.
|
void |
enable_tracing()
Enable tracing.
|
GeometryFunction |
ExtractCoordSys() |
ADQLOperand |
Factor() |
void |
From() |
ParseException |
generateParseException()
Generate ParseException.
|
GeometryFunction.GeometryValue<GeometryFunction> |
GeometryExpression() |
GeometryFunction |
GeometryFunction() |
GeometryFunction |
GeometryValueFunction() |
Token |
getNextToken()
Get the next Token.
|
QueryChecker |
getQueryChecker() |
ADQLQueryFactory |
getQueryFactory() |
Token |
getToken(int index)
Get the specific Token.
|
void |
GroupBy() |
void |
Having() |
IdentifierItems.IdentifierItem |
Identifier() |
In |
InEnd(ADQLOperand leftOp) |
protected boolean |
isEnd(Token token)
Tell whether the given token represents the end of an ADQL query.
|
protected boolean |
isFunctionName(Token token)
Tell whether the given token matches to an ADQL function name.
|
boolean |
isRegularIdentifier(java.lang.String idCandidate)
Tell whether the given string is a valid ADQL regular identifier.
|
FromContent |
JoinedTable() |
ADQLJoin |
JoinSpecification(FromContent leftTable) |
static void |
main(java.lang.String[] args)
Gets the specified ADQL query and parses the given ADQL query.
|
MathFunction |
MathFunction() |
protected boolean |
mustEscape(Token token,
Token nextToken)
Tell whether the given token must be double quoted.
|
ADQLOperand |
NumericExpression() |
ADQLFunction |
NumericFunction() |
ADQLOperand |
NumericTerm() |
ADQLOperand |
NumericValueExpressionPrimary() |
void |
OrderBy() |
ADQLOrder |
OrderItem() |
ADQLQuery |
parseQuery()
Parses the query given at the creation of this parser or in the
ReInit functions.
|
ADQLQuery |
parseQuery(java.io.InputStream stream)
Parses the query contained in the stream given in parameter.
|
ADQLQuery |
parseQuery(java.lang.String q)
Parses the query given in parameter.
|
PointFunction |
Point() |
ADQLConstraint |
Predicate() |
ADQLQuery |
Query()
Parses the ADQL query given at the parser creation or in the
ReInit(java.io.InputStream)
or in the parseQuery functions. |
ADQLQuery |
QueryExpression() |
void |
ReInit(ADQLParserTokenManager tm)
Reinitialise.
|
void |
ReInit(java.io.InputStream stream)
Reinitialise.
|
void |
ReInit(java.io.InputStream stream,
java.lang.String encoding)
Reinitialise.
|
void |
ReInit(java.io.Reader stream)
Reinitialise.
|
protected java.lang.String |
replaceUnicodeConfusables(java.lang.String adqlQuery)
Replace all Unicode characters that can be confused with other ASCI/UTF-8
characters (e.g.
|
void |
Select() |
SelectItem |
SelectItem() |
void |
setDebug(boolean debug) |
void |
setQueryChecker(QueryChecker checker) |
void |
setQueryFactory(ADQLQueryFactory factory) |
NumericConstant |
SignedInteger() |
FromContent |
SimpleTableRef() |
SQLFunction |
SqlFunction() |
StringConstant |
String() |
ADQLOperand |
StringExpression() |
ADQLOperand |
StringFactor() |
ADQLOperand |
StringValueExpressionPrimary() |
ADQLQuery |
SubQueryExpression() |
IdentifierItems |
TableName()
Extracts the name of a table with its possible catalog and schema prefixes.
|
FromContent |
TableRef() |
void |
testRegularIdentifier(Token token)
Test the given token as an ADQL's regular identifier.
|
MathFunction |
TrigFunction() |
java.lang.String |
tryQuickFix(java.io.InputStream input)
Try fixing tokens/terms of the input ADQL query.
|
java.lang.String |
tryQuickFix(java.lang.String adqlQuery)
Try fixing tokens/terms of the given ADQL query.
|
NumericConstant |
UnsignedFloat() |
NumericConstant |
UnsignedNumeric() |
UserDefinedFunction |
UserDefinedFunction() |
ADQLOperand |
ValueExpression() |
void |
Where() |
protected static final java.util.Map<java.lang.String,java.lang.String> REGEX_UNICODE_CONFUSABLES
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.
protected static final java.lang.String REGEX_DASH
-
.protected static final java.lang.String REGEX_UNDERSCORE
_
.protected static final java.lang.String REGEX_QUOTE
'
.protected static final java.lang.String REGEX_DOUBLE_QUOTE
"
.protected static final java.lang.String REGEX_STOP
.
.protected static final java.lang.String REGEX_PLUS
+
.protected static final java.lang.String REGEX_SPACE
.protected static final java.lang.String REGEX_LESS_THAN
<
.protected static final java.lang.String REGEX_GREATER_THAN
>
.protected static final java.lang.String REGEX_EQUAL
=
.public ADQLParserTokenManager token_source
public Token token
public Token jj_nt
public ADQLParser()
public ADQLParser(QueryChecker checker, ADQLQueryFactory factory)
QueryChecker
and a ADQLQueryFactory
.checker
- The object to use to check each ADQLQuery
.factory
- The object to use to build an object representation of
the given ADQL query.public ADQLParser(QueryChecker checker)
QueryChecker
.checker
- The object to use to check each ADQLQuery
.public ADQLParser(ADQLQueryFactory factory)
ADQLQueryFactory
.factory
- The object to use to build an object representation of
the given ADQL query.public ADQLParser(java.io.InputStream stream, QueryChecker checker, ADQLQueryFactory factory)
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.public ADQLParser(java.io.InputStream stream, QueryChecker checker)
stream
- The stream in which the ADQL query to parse is given.checker
- The object to use to check each ADQLQuery
.public ADQLParser(java.io.InputStream stream, ADQLQueryFactory factory)
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.public ADQLParser(java.io.InputStream stream, java.lang.String encoding, QueryChecker checker, ADQLQueryFactory factory)
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.public ADQLParser(java.io.InputStream stream, java.lang.String encoding, QueryChecker checker)
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
.public ADQLParser(java.io.InputStream stream, java.lang.String encoding, ADQLQueryFactory factory)
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.public ADQLParser(java.io.Reader reader, QueryChecker checker, ADQLQueryFactory factory)
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.public ADQLParser(java.io.Reader reader, QueryChecker checker)
reader
- The reader in which the ADQL query to parse is given.checker
- The object to use to check each ADQLQuery
.public ADQLParser(java.io.Reader reader, ADQLQueryFactory factory)
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.public ADQLParser(ADQLParserTokenManager tm, QueryChecker checker, ADQLQueryFactory factory)
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.public ADQLParser(ADQLParserTokenManager tm, QueryChecker checker)
tm
- The manager which associates a token to a numeric code.checker
- The object to use to check each ADQLQuery
.public ADQLParser(ADQLParserTokenManager tm, ADQLQueryFactory factory)
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.public ADQLParser(java.io.InputStream stream)
public ADQLParser(java.io.InputStream stream, java.lang.String encoding)
public ADQLParser(java.io.Reader stream)
public ADQLParser(ADQLParserTokenManager tm)
public final void setDebug(boolean debug)
public final QueryChecker getQueryChecker()
public final void setQueryChecker(QueryChecker checker)
public final ADQLQueryFactory getQueryFactory()
public final void setQueryFactory(ADQLQueryFactory factory)
public final boolean isRegularIdentifier(java.lang.String idCandidate)
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.
idCandidate
- The string to test.true
if the given string is a valid regular
identifier,
false
otherwise.testRegularIdentifier(adql.parser.Token)
public final void testRegularIdentifier(Token token) throws ParseException
This function uses isRegularIdentifier(java.lang.String)
to
test the given token's image. If the test fails, a
ParseException
is thrown.
token
- The token to test.ParseException
- If the given token is not a valid ADQL regular
identifier.isRegularIdentifier(java.lang.String)
public final ADQLQuery parseQuery() throws ParseException
ParseException
- If there is at least one syntactic error.Query()
public final ADQLQuery parseQuery(java.lang.String q) throws ParseException
q
- The ADQL query to parse.ParseException
- If there is at least one syntactic error.ReInit(java.io.InputStream)
,
setDebug(boolean)
,
Query()
public final ADQLQuery parseQuery(java.io.InputStream stream) throws ParseException
stream
- The stream which contains the ADQL query to parse.ParseException
- If there is at least one syntactic error.ReInit(java.io.InputStream)
,
setDebug(boolean)
,
Query()
public final java.lang.String tryQuickFix(java.io.InputStream input) throws java.io.IOException, ParseException
This function does not try to fix syntactical or semantical errors. It just try to fix the most common issues in ADQL queries, such as:
_RAJ2000
),distance
)public
).Note 1: The given stream is NOT closed by this function even if the EOF is reached. It is the responsibility of the caller to close it.
Note 2: This function does not use any instance variable of this parser (especially the InputStream or Reader provided at initialisation or ReInit).
input
- Stream containing the input ADQL query to fix.java.io.IOException
- If there is any error while reading from the
given input stream.ParseException
- If any unrecognised character is encountered,
or if anything else prevented the tokenization
of some characters/words/terms.tryQuickFix(java.lang.String)
public java.lang.String tryQuickFix(java.lang.String adqlQuery) throws ParseException
This function does not try to fix syntactical or semantical errors. It just try to fix the most common issues in ADQL queries, such as:
_RAJ2000
),distance
)public
).Note: This function does not use any instance variable of this parser (especially the InputStream or Reader provided at initialisation or ReInit).
adqlQuery
- The input ADQL query to fix.ParseException
- If any unrecognised character is encountered,
or if anything else prevented the tokenization
of some characters/words/terms.protected java.lang.String replaceUnicodeConfusables(java.lang.String adqlQuery)
adqlQuery
- The ADQL query string in which Unicode confusable
characters must be replaced.protected boolean isEnd(Token token)
token
- Token to analyze.true
if the given token represents a query end,
false
otherwise.protected boolean mustEscape(Token token, Token nextToken)
This function considers all the following as terms to double quote:
token
- The token to analyze.nextToken
- The following token. (useful to detect the start of a
function's parameters list)true
if the given token must be double quoted,
false
to keep it as provided.protected boolean isFunctionName(Token token)
token
- The token to analyze.true
if the given token is an ADQL function name,
false
otherwise.public static final void main(java.lang.String[] args) throws java.lang.Exception
ONLY the syntax is checked: the query is NOT EXECUTED !
args
- java.lang.Exception
public final ADQLQuery Query() throws ParseException
ReInit(java.io.InputStream)
or in the parseQuery functions.ParseException
- If the query syntax is incorrect.public final ADQLQuery QueryExpression() throws ParseException
ParseException
public final ADQLQuery SubQueryExpression() throws ParseException
ParseException
public final void Select() throws ParseException
ParseException
public final SelectItem SelectItem() throws ParseException
ParseException
public final void From() throws ParseException
ParseException
public final void Where() throws ParseException
ParseException
public final void GroupBy() throws ParseException
ParseException
public final void Having() throws ParseException
ParseException
public final void OrderBy() throws ParseException
ParseException
public final IdentifierItems.IdentifierItem Identifier() throws ParseException
ParseException
public final IdentifierItems TableName() throws ParseException
IdentifierItems
which contains at most three items: catalogName, schemaName and tableName.ParseException
public final IdentifierItems ColumnName() throws ParseException
IdentifierItems
which contains at most four items: catalogName, schemaName, tableName and columnName.ParseException
public final ADQLColumn Column() throws ParseException
ParseException
public final ADQLOrder OrderItem() throws ParseException
ParseException
public final FromContent SimpleTableRef() throws ParseException
ParseException
public final FromContent TableRef() throws ParseException
ParseException
public final FromContent JoinedTable() throws ParseException
ParseException
public final ADQLJoin JoinSpecification(FromContent leftTable) throws ParseException
ParseException
public final StringConstant String() throws ParseException
ParseException
public final NumericConstant UnsignedNumeric() throws ParseException
ParseException
public final NumericConstant UnsignedFloat() throws ParseException
ParseException
public final NumericConstant SignedInteger() throws ParseException
ParseException
public final ADQLOperand NumericValueExpressionPrimary() throws ParseException
ParseException
public final ADQLOperand StringValueExpressionPrimary() throws ParseException
ParseException
public final ADQLOperand ValueExpression() throws ParseException
ParseException
public final ADQLOperand NumericExpression() throws ParseException
ParseException
public final ADQLOperand NumericTerm() throws ParseException
ParseException
public final ADQLOperand Factor() throws ParseException
ParseException
public final ADQLOperand StringExpression() throws ParseException
ParseException
public final ADQLOperand StringFactor() throws ParseException
ParseException
public final GeometryFunction.GeometryValue<GeometryFunction> GeometryExpression() throws ParseException
ParseException
public final ClauseConstraints ConditionsList(ClauseConstraints clause) throws ParseException
ParseException
public final ADQLConstraint Constraint() throws ParseException
ParseException
public final ADQLConstraint Predicate() throws ParseException
ParseException
public final Comparison ComparisonEnd(ADQLOperand leftOp) throws ParseException
ParseException
public final Between BetweenEnd(ADQLOperand leftOp) throws ParseException
ParseException
public final In InEnd(ADQLOperand leftOp) throws ParseException
ParseException
public final SQLFunction SqlFunction() throws ParseException
ParseException
public final ADQLOperand[] Coordinates() throws ParseException
ParseException
public final GeometryFunction GeometryFunction() throws ParseException
ParseException
public final ADQLOperand CoordinateSystem() throws ParseException
ParseException
public final GeometryFunction GeometryValueFunction() throws ParseException
ParseException
public final PointFunction Point() throws ParseException
ParseException
public final GeometryFunction ExtractCoordSys() throws ParseException
ParseException
public final ADQLFunction NumericFunction() throws ParseException
ParseException
public final MathFunction MathFunction() throws ParseException
ParseException
public final MathFunction TrigFunction() throws ParseException
ParseException
public final UserDefinedFunction UserDefinedFunction() throws ParseException
ParseException
public void ReInit(java.io.InputStream stream)
public void ReInit(java.io.InputStream stream, java.lang.String encoding)
public void ReInit(java.io.Reader stream)
public void ReInit(ADQLParserTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()