public class FQLParser extends antlr.LLkParser implements FQLParserTokenTypes
FQLLexer
). More specifically, the
parser does the following:
nextToken
method. This method tokenizes the
lexer's input stream of characters and returns the next found Token
object.
expression()
and statement()
methods as an entry points.
This grammar is highly specific to ANTLR 2.7.x and it may not be valid in future versions of ANTLR. This is due to the fact that the generated code and the grammar syntax of ANTLR can change between versions. These factors are the most important constraints defining the structure of the resulting grammar. As a result, it is possible that the grammar will require changes to run in future versions of ANTLR.
This is a generated file using ANTLR 2.7.4 and a grammar specified in fql.g
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
_tokenNames |
static antlr.collections.impl.BitSet |
_tokenSet_0 |
static antlr.collections.impl.BitSet |
_tokenSet_1 |
static antlr.collections.impl.BitSet |
_tokenSet_10 |
static antlr.collections.impl.BitSet |
_tokenSet_11 |
static antlr.collections.impl.BitSet |
_tokenSet_12 |
static antlr.collections.impl.BitSet |
_tokenSet_13 |
static antlr.collections.impl.BitSet |
_tokenSet_14 |
static antlr.collections.impl.BitSet |
_tokenSet_15 |
static antlr.collections.impl.BitSet |
_tokenSet_16 |
static antlr.collections.impl.BitSet |
_tokenSet_17 |
static antlr.collections.impl.BitSet |
_tokenSet_18 |
static antlr.collections.impl.BitSet |
_tokenSet_19 |
static antlr.collections.impl.BitSet |
_tokenSet_2 |
static antlr.collections.impl.BitSet |
_tokenSet_3 |
static antlr.collections.impl.BitSet |
_tokenSet_4 |
static antlr.collections.impl.BitSet |
_tokenSet_5 |
static antlr.collections.impl.BitSet |
_tokenSet_6 |
static antlr.collections.impl.BitSet |
_tokenSet_7 |
static antlr.collections.impl.BitSet |
_tokenSet_8 |
static antlr.collections.impl.BitSet |
_tokenSet_9 |
private static java.lang.Class<FQLAst> |
AST_CLASS
Name of the specialized AST class to use when parsing.
|
private FqlToSqlConverter |
listener |
private int |
nextSubstitutionIndex
Next index value to be assigned to a query substitution node
|
private static java.util.Map<java.lang.String,java.lang.Integer> |
tokenLookup
Provides an efficient reverse lookup of names to token types.
|
astFactory, inputState, returnAST, tokenNames, tokenTypeToASTClassMap, traceDepth
ALIAS, AND, AS, ASC, BOOL_FALSE, BOOL_TRUE, BY, CASE, CAST, COMMA, CONCAT, CROSS, DEC_LITERAL, DELETE, DELETE_STMT, DESC, DIGIT, DIVIDE, DMO, DOT, ELSE, END, EOF, EQUALS, ESCAPE, FROM, FULL, FUNCTION, GROUP, GT, GTE, HAVING, IN, INDEX, INNER, INSERT, INSERT_STMT, INTO, IS, IS_NULL, JOIN, LBRACKET, LEFT, LETTER, LIKE, LONG_LITERAL, LPARENS, LT, LTE, MINUS, MULTIPLY, NOT, NOT_EQ, NOT_NULL, NULL, NULL_TREE_LOOKAHEAD, NUM_LITERAL, ON, OR, ORDER, OUTER, PLUS, POSITIONAL, PROPERTY, RBRACKET, RIGHT, RPARENS, SELECT, SELECT_STMT, SET, SINGLE, STRING, SUBSCRIPT, SUBSELECT, SUBST, SYM_CHAR, SYMBOL, TERNARY, THEN, UN_MINUS, UPDATE, UPDATE_STMT, VALID_1ST_IDENT, VALID_SYM_CHAR, VALUES, WHEN, WHERE, WS
Modifier | Constructor and Description |
---|---|
|
FQLParser(antlr.ParserSharedInputState state) |
|
FQLParser(antlr.TokenBuffer tokenBuf) |
protected |
FQLParser(antlr.TokenBuffer tokenBuf,
int k) |
|
FQLParser(antlr.TokenStream lexer) |
protected |
FQLParser(antlr.TokenStream lexer,
int k) |
Modifier and Type | Method and Description |
---|---|
void |
aggregate()
Matches FQL aggregate signatures: a SYMBOL followed by an expression in parentheses.
|
void |
alias()
Matches an alias for a data model object, which is simply a SYMBOL, optionally followed by a
property.
|
void |
as_expr()
Matches an as phrase, which is an optional assignment of an alias to a DMO at the end of a from
phrase.
|
protected void |
buildTokenTypeASTClassMap() |
void |
cast()
Matches a CAST FQL primary expression in which the value of an expression is converted to a specified type.
|
void |
compare_expr()
Implements the 4th lowest precedence level of expressions - the comparison operators.
|
void |
concat_expr()
Implements the 5th lowest precedence level of expressions - concatenation.
|
void |
convertNullTest(antlr.CommonAST ast)
Implements special processing for
NULL equality and inequality tests. |
void |
deleteStatement()
Matches the
DELETE FQL statements. |
void |
dmo() |
void |
equality_expr()
Implements the 3rd lowest precedence level of expressions - the equality operators.
|
void |
expr()
Implements the lowest (1st) precedence level of expressions:
OR (the logical OR
operator). |
void |
expression()
Parses an FQL expression and creates an AST that is suitable for further processing.
|
void |
from_expr()
Matches a from phrase embedded within a where clause as part of a select or subselect
statement.
|
void |
function()
Matches FQL function signatures: a SYMBOL followed by a parameter list in parentheses.
|
void |
groupBy_expr()
Matches a GROUP BY clause, including the optional HAVING clause.
|
void |
having_expr()
Matches a HAVING clause.
|
void |
insertStatement()
Matches the
INSERT FQL statements. |
void |
join_expr()
Matches a join phrase embedded within a where clause as part of a subselect statement.
|
void |
join_extent()
Special JOIN syntax between two OE tables ON a common property.
|
void |
literal()
Matches all variations of expression literals (constants).
|
void |
log_and_expr()
Implements the 2nd lowest precedence level of expressions:
AND (the logical AND operator). |
static java.lang.String |
lookupTokenName(int type)
Translates an integer value of a parser token type into the associated
human readable text representation.
|
static int |
lookupTokenType(java.lang.String tokenName)
Translates a text representation of a parser token type into the
actual integer value.
|
static void |
main(java.lang.String[] args)
Provides a command line interface for an end user to drive and/or test
the FQLParser class.
|
private static long[] |
mk_tokenSet_0() |
private static long[] |
mk_tokenSet_1() |
private static long[] |
mk_tokenSet_10() |
private static long[] |
mk_tokenSet_11() |
private static long[] |
mk_tokenSet_12() |
private static long[] |
mk_tokenSet_13() |
private static long[] |
mk_tokenSet_14() |
private static long[] |
mk_tokenSet_15() |
private static long[] |
mk_tokenSet_16() |
private static long[] |
mk_tokenSet_17() |
private static long[] |
mk_tokenSet_18() |
private static long[] |
mk_tokenSet_19() |
private static long[] |
mk_tokenSet_2() |
private static long[] |
mk_tokenSet_3() |
private static long[] |
mk_tokenSet_4() |
private static long[] |
mk_tokenSet_5() |
private static long[] |
mk_tokenSet_6() |
private static long[] |
mk_tokenSet_7() |
private static long[] |
mk_tokenSet_8() |
private static long[] |
mk_tokenSet_9() |
void |
on_expr()
Matches an
ON condition (logical expression) used for JOIN-ing the tables. |
void |
orderBy_expr()
Matches an ORDER-BY clause in a FQL statement.
|
void |
parentheses()
Matches a subexpression enclosed in parentheses.
|
void |
positional_param()
Matches and pre-processes a positional parameter.
|
void |
primary_expr()
Implements the 8th and highest precedence level of expressions, the parenthesis precedence
operators,
literal() , function() , ternary() , property() ,
selectStatement() , and parentheses() rules. |
void |
prod_expr()
Implements the 6th lowest precedence level of expressions - the multiplicative operators.
|
void |
property_list()
Matches the optional list of properties/columns in a INSERT INTO statement.
|
void |
property()
Matches a qualified or unqualified property name, with an optional
subscript() . |
void |
reportError(antlr.RecognitionException exc)
Parser error-reporting function.
|
void |
select_expr()
Matches a select phrase embedded within a where clause as part of a subselect statement.
|
void |
selectStatement()
Matches the
SELECT FQL statements. |
void |
set_expr()
Matches the SET phrase for an UPDATE statement.
|
void |
setListener(FqlToSqlConverter fql) |
void |
statement()
Matches all four FQL statements.
|
void |
subscript()
Matches a
property() subscript, for array-type properties. |
void |
substitution()
Matches a query substitution parameter placeholder.
|
void |
sum_expr()
Implements the 5th lowest precedence level of expressions - the additive operators.
|
void |
ternary()
Matches a ternary expression which uses the CASE WHEN construct in its ternary form.
|
void |
un_expr()
Implements the 7th lowest precedence level of expressions - the unary operators.
|
void |
update_field()
Matches the property assign in an UPDATE statement.
|
void |
updateStatement()
Matches the
UPDATE FQL statements. |
void |
values_list()
Matches the list of values in a INSERT INTO statement.
|
static void |
visit(antlr.CommonAST ast,
int level)
Simple walker to print out the contents of an AST for debugging.
|
void |
where_expr()
Matches a where phrase embedded within a where clause as part of a subselect statement.
|
addMessageListener, addParserListener, addParserMatchListener, addParserTokenListener, addSemanticPredicateListener, addSyntacticPredicateListener, addTraceListener, consumeUntil, consumeUntil, defaultDebuggingSetup, getAST, getASTFactory, getFilename, getInputState, getTokenName, getTokenNames, getTokenTypeToASTClassMap, isDebugMode, mark, match, match, matchNot, panic, recover, removeMessageListener, removeParserListener, removeParserMatchListener, removeParserTokenListener, removeSemanticPredicateListener, removeSyntacticPredicateListener, removeTraceListener, reportError, reportWarning, rewind, setASTFactory, setASTNodeClass, setASTNodeType, setDebugMode, setFilename, setIgnoreInvalidDebugCalls, setInputState, setTokenBuffer, traceIndent
private static final java.lang.Class<FQLAst> AST_CLASS
private static java.util.Map<java.lang.String,java.lang.Integer> tokenLookup
private int nextSubstitutionIndex
private FqlToSqlConverter listener
public static final java.lang.String[] _tokenNames
public static final antlr.collections.impl.BitSet _tokenSet_0
public static final antlr.collections.impl.BitSet _tokenSet_1
public static final antlr.collections.impl.BitSet _tokenSet_2
public static final antlr.collections.impl.BitSet _tokenSet_3
public static final antlr.collections.impl.BitSet _tokenSet_4
public static final antlr.collections.impl.BitSet _tokenSet_5
public static final antlr.collections.impl.BitSet _tokenSet_6
public static final antlr.collections.impl.BitSet _tokenSet_7
public static final antlr.collections.impl.BitSet _tokenSet_8
public static final antlr.collections.impl.BitSet _tokenSet_9
public static final antlr.collections.impl.BitSet _tokenSet_10
public static final antlr.collections.impl.BitSet _tokenSet_11
public static final antlr.collections.impl.BitSet _tokenSet_12
public static final antlr.collections.impl.BitSet _tokenSet_13
public static final antlr.collections.impl.BitSet _tokenSet_14
public static final antlr.collections.impl.BitSet _tokenSet_15
public static final antlr.collections.impl.BitSet _tokenSet_16
public static final antlr.collections.impl.BitSet _tokenSet_17
public static final antlr.collections.impl.BitSet _tokenSet_18
public static final antlr.collections.impl.BitSet _tokenSet_19
protected FQLParser(antlr.TokenBuffer tokenBuf, int k)
public FQLParser(antlr.TokenBuffer tokenBuf)
protected FQLParser(antlr.TokenStream lexer, int k)
public FQLParser(antlr.TokenStream lexer)
public FQLParser(antlr.ParserSharedInputState state)
public static void visit(antlr.CommonAST ast, int level)
ast
- The current node to print.level
- The number of levels down from the root (0 == root node),
which determines the indention level to print.public static int lookupTokenType(java.lang.String tokenName)
tokenName
- The text representation of the parser token type.public static java.lang.String lookupTokenName(int type)
type
- The integer token type.null
if no match was found.public void convertNullTest(antlr.CommonAST ast)
NULL
equality and inequality tests. If a
NULL
token is detected on either side of either of the operators, the result will
be rooted at an IS_NULL
(equality) or NOT_NULL
(inequality) node. The
operand that is NULL
will be dropped and the other operand will be the only child.
This is separated from the main processing and really is a kind of post-processing of the entire tree.
public void reportError(antlr.RecognitionException exc)
reportError
in class antlr.Parser
public void setListener(FqlToSqlConverter fql)
public static void main(java.lang.String[] args)
Syntax:
java FQLParser <expression>
args
- List of command line arguments.public final void statement() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void selectStatement() throws antlr.RecognitionException, antlr.TokenStreamException
SELECT
FQL statements.antlr.RecognitionException
antlr.TokenStreamException
public final void insertStatement() throws antlr.RecognitionException, antlr.TokenStreamException
INSERT
FQL statements.antlr.RecognitionException
antlr.TokenStreamException
public final void updateStatement() throws antlr.RecognitionException, antlr.TokenStreamException
UPDATE
FQL statements.antlr.RecognitionException
antlr.TokenStreamException
public final void deleteStatement() throws antlr.RecognitionException, antlr.TokenStreamException
DELETE
FQL statements.antlr.RecognitionException
antlr.TokenStreamException
public final void dmo() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void property_list() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void values_list() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void set_expr() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void where_expr() throws antlr.RecognitionException, antlr.TokenStreamException
selectStatement()
, updateStatement()
, and deleteStatement()
rules.
Recursively calls expr()
rule.antlr.RecognitionException
antlr.TokenStreamException
public final void from_expr() throws antlr.RecognitionException, antlr.TokenStreamException
selectStatement()
and deleteStatement()
rules.antlr.RecognitionException
antlr.TokenStreamException
public final void select_expr() throws antlr.RecognitionException, antlr.TokenStreamException
selectStatement()
rule.
At this moment we are unable to detect whether the SYMBOLS under SELECT are really alias
or
property
. It can be a alias/DMO (optionally with a package path) or a property
(optionally qualified with alias name). This needs to be done, at preprocessing time.
See FqlToSqlConverter.processSelect(FQLAst)
.
antlr.RecognitionException
antlr.TokenStreamException
public final void groupBy_expr() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void orderBy_expr() throws antlr.RecognitionException, antlr.TokenStreamException
Some dialects (PostgreSQL) allows complex expressions to be applied to properties.
antlr.RecognitionException
antlr.TokenStreamException
public final void expression() throws antlr.RecognitionException, antlr.TokenStreamException
FQLAst
).
The AST is structured with operator nodes as the root nodes and each operator (unary or binary) has the matching number of child nodes (1 or 2 respectively). Each child node is an operand and the semantics of left and right operands (for binary operators) is maintained.
Non-operator nodes in the tree can be literals or FQL functions. The list of literals can be
seen in the literal()
rule.
All of the following operators are supported and the precedence order follows that of SQL, which we assume is the same precedence order used by FQL.
lowest logical OR : or | conditional AND : and | equality : = | relational : <, >, ≤, ≥ | additive : +, - | multiplicative : *, / | unary operators : -, not V function call : function_name(...) highest parentheses : (...)
To handle the precedence issue, each precedence level (see the table above) is handled in a
separate rule. Starting at in this top level entry point, the lowest precedence rule is
referenced. This reference is made with an optional OR
operator. If this operator is
present, it is the root of the resulting tree. This means it is the last operator to be
evaluated since its operands will be processed first. This is the proper definition of lowest
precedence. If this operator is present, then a second operand is expected.
Each precedence level is similarly constructed, the left operand being required, all operators being optional and each operator choice an equal alternative. If any of the operators exists, then it is the root of the subtree and a right operand is expected. This holds true for all rules that process binary operators. Please note that this left-mandatory and optional right side (operator + right operand) is critical for allowing an expression to be as simple as a single variable, function call or literal. Alternatively, it can expand into a highly nested set of recursively parsed expressions that all evaluate to a single scalar result.
At the bottom of the hierarchy of rules are unary operators, these are implemented as an optional prefix operator and a mandatory right operand.
The final level is the primary expression. This is where the precedence operator parenthesis is handled. It also is where we allow a single literal, alias, or function reference.
The expr()
rule is called as the only rule reference.
antlr.RecognitionException
antlr.TokenStreamException
public final void expr() throws antlr.RecognitionException, antlr.TokenStreamException
OR
(the logical OR
operator). Valid expressions can contain sub-expressions and this entry point is properly
recursive without causing any ambiguity.
This rule is designed to allow recursion (the highest precedence levels function()
and
primary_expr()
reference this rule again, allowing infinite nesting of sub-expressions,
with proper parsing, evaluation and tree building.
This method is called by the top level expression()
rule. This method calls the
log_and_expr()
rule.
Implements special processing for NULL
equality and inequality tests. If a NULL
token is detected on either side of either of the operators, the result will be rooted at an
IS_NULL
(equality) or NOT_NULL
(inequality) node. The operand that is
NULL
will be dropped and the other operand will be the only child. This must be
implemented after the entire tree is created and the method convertNullTest(antlr.CommonAST)
is used
to implement this processing.
antlr.RecognitionException
antlr.TokenStreamException
public final void log_and_expr() throws antlr.RecognitionException, antlr.TokenStreamException
AND
(the logical AND operator).
This is only called by the expr()
rule. This method calls the equality_expr()
rule.
antlr.RecognitionException
antlr.TokenStreamException
public final void equality_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the log_and_expr()
rule. This method calls the compare_expr()
rule.
Provides the following operators:
= (equality) != (inequality)
antlr.RecognitionException
antlr.TokenStreamException
public final void compare_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the equality_expr()
rule. This method calls the concat_expr()
rule.
Provides the following operators:
> (greater than) < (less than) ≥ (greater than or equal to) ≤ (less than or equal to) like
antlr.RecognitionException
antlr.TokenStreamException
public final void concat_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the compare_expr()
rule. This method calls the sum_expr()
rule.
Provides the following operator:
|| (concatenation of two string operands)
antlr.RecognitionException
antlr.TokenStreamException
public final void sum_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the compare_expr()
rule. This method calls the prod_expr()
rule.
Provides the following operators:
+ (binary plus) - (binary minus)
antlr.RecognitionException
antlr.TokenStreamException
public final void prod_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the sum_expr()
rule. This method calls the un_expr()
rule.
Provides the following operators:
* (multiply) / (divide)
antlr.RecognitionException
antlr.TokenStreamException
public final void un_expr() throws antlr.RecognitionException, antlr.TokenStreamException
This is only called by the prod_expr()
rule. This method calls the primary_expr()
rule.
Provides the following operators:
- unary minus not logical NOT
antlr.RecognitionException
antlr.TokenStreamException
public final void primary_expr() throws antlr.RecognitionException, antlr.TokenStreamException
literal()
, function()
, ternary()
, property()
,
selectStatement()
, and parentheses()
rules.
This rule is different in structure from the previous levels, as the there is just a set of
alternatives and one of them allows direct recursion back to the expr
expression point.
This is only called by the un_expr()
rule.
See the rule expr()
for more details.
antlr.RecognitionException
antlr.TokenStreamException
public final void literal() throws antlr.RecognitionException, antlr.TokenStreamException
NUM_LITERAL LONG_LITERAL DEC_LITERAL STRING BOOL_TRUE BOOL_FALSE NULL SUBST POSITIONAL
antlr.RecognitionException
antlr.TokenStreamException
public final void cast() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void function() throws antlr.RecognitionException, antlr.TokenStreamException
primary_expr()
rule.antlr.RecognitionException
antlr.TokenStreamException
public final void ternary() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void property() throws antlr.RecognitionException, antlr.TokenStreamException
subscript()
. This
rule is called by the primary_expr()
rule, but only after the function()
rule is
invoked. This order is necessary to avoid ambiguity with the latter rule, which looks for a
leading SYMBOL * token.antlr.RecognitionException
antlr.TokenStreamException
public final void parentheses() throws antlr.RecognitionException, antlr.TokenStreamException
primary_expr()
rule;
recursively calls expr()
rule.antlr.RecognitionException
antlr.TokenStreamException
public final void aggregate() throws antlr.RecognitionException, antlr.TokenStreamException
select_expr()
rule.antlr.RecognitionException
antlr.TokenStreamException
public final void alias() throws antlr.RecognitionException, antlr.TokenStreamException
primary_expr()
rule, but only after the
function()
rule is invoked. This order is necessary to avoid ambiguity with the latter
rule, which looks for a leading SYMBOL token.antlr.RecognitionException
antlr.TokenStreamException
public final void subscript() throws antlr.RecognitionException, antlr.TokenStreamException
property()
subscript, for array-type properties.antlr.RecognitionException
antlr.TokenStreamException
public final void positional_param() throws antlr.RecognitionException, antlr.TokenStreamException
The positional parameters (Ex: ?8
) are matched and then annotated with index
annotation which represent its index/order.
antlr.RecognitionException
antlr.TokenStreamException
public final void substitution() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void as_expr() throws antlr.RecognitionException, antlr.TokenStreamException
from_expr()
rule. This portion of the phrase is optional if no other
part of the subselect phrase references an alias for the DMO.antlr.RecognitionException
antlr.TokenStreamException
public final void join_expr() throws antlr.RecognitionException, antlr.TokenStreamException
from_expr()
rule.antlr.RecognitionException
antlr.TokenStreamException
public final void join_extent() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void on_expr() throws antlr.RecognitionException, antlr.TokenStreamException
ON
condition (logical expression) used for JOIN-ing the tables.antlr.RecognitionException
antlr.TokenStreamException
public final void update_field() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void having_expr() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
protected void buildTokenTypeASTClassMap()
private static final long[] mk_tokenSet_0()
private static final long[] mk_tokenSet_1()
private static final long[] mk_tokenSet_2()
private static final long[] mk_tokenSet_3()
private static final long[] mk_tokenSet_4()
private static final long[] mk_tokenSet_5()
private static final long[] mk_tokenSet_6()
private static final long[] mk_tokenSet_7()
private static final long[] mk_tokenSet_8()
private static final long[] mk_tokenSet_9()
private static final long[] mk_tokenSet_10()
private static final long[] mk_tokenSet_11()
private static final long[] mk_tokenSet_12()
private static final long[] mk_tokenSet_13()
private static final long[] mk_tokenSet_14()
private static final long[] mk_tokenSet_15()
private static final long[] mk_tokenSet_16()
private static final long[] mk_tokenSet_17()
private static final long[] mk_tokenSet_18()
private static final long[] mk_tokenSet_19()