JQL.g revision ada1678a4262b208a7b87391f520a7767d25287c
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* JQL.g
*
* Created on March 8, 2000
*/
{
import antlr.MismatchedTokenException;
import antlr.MismatchedCharException;
import antlr.NoViableAltException;
import antlr.NoViableAltForCharException;
import antlr.TokenStreamRecognitionException;
}
//===== Lexical Analyzer Class Definitions =====
/**
* This class defines the lexical analysis for the JQL compiler.
*
* @author Michael Bouschen
* @author Shing Wai Chan
* @version 0.1
*/
{
k = 2;
exportVocab = JQL;
}
tokens {
// non-standard extensions
// types
// literals
// aggregate functions
}
{
/**
* I18N support
*/
JQLLexer.class);
/**
*
*/
/**
* The width of a tab stop.
* This value is used to calculate the correct column in a line
* conatining a tab character.
*/
protected static final int TABSIZE = 4;
/**
*
*/
{
}
/**
*
*/
public void tab()
{
}
/**
*
*/
{
}
/**
* Report lexer exception errors caught in nextToken()
*/
public void reportError(RecognitionException e)
{
}
/**
* Lexer error-reporting function
*/
public void reportError(String s)
{
}
/**
* Lexer warning-reporting function
*/
public void reportWarning(String s)
{
throw new JDOQueryException(s);
}
}
// OPERATORS
LPAREN : '(' ;
RPAREN : ')' ;
COMMA : ',' ;
//DOT : '.' ;
LNOT : '!' ;
BNOT : '~' ;
DIV : '/' ;
PLUS : '+' ;
MINUS : '-' ;
STAR : '*' ;
MOD : '%' ;
LT : '<' ;
BXOR : '^' ;
BOR : '|' ;
BAND : '&' ;
SEMI : ';' ;
// Whitespace -- ignored
: ( ' '
| '\t'
| '\f'
)
;
: ( "\r\n" //NOI18N
| '\r'
| '\n'
)
{
newline();
}
;
// character literals
;
// string literals
;
// escape sequence -- note that this is protected; it can only be called
// from another lexer rule -- it will not ever directly return a token to
// the parser
// There are various ambiguities hushed in this rule. The optional
// '0'...'9' digit matches should be matched here rather than letting
// them go back to STRING_LITERAL to be matched. ANTLR does the
// right thing by matching immediately; hence, it's ok to shut off
// the FOLLOW ambig warnings.
protected
: '\\'
( options { warnWhenFollowAmbig = false; }
: 'n'
| 'r'
| 't'
| 'b'
| 'f'
| '"' //NOI18N
| '\''
| '\\'
| ('0'..'3')
(
options {
warnWhenFollowAmbig = false;
}
: ('0'..'7')
(
options {
warnWhenFollowAmbig = false;
}
: '0'..'7'
)?
)?
| ('4'..'7')
(
options {
warnWhenFollowAmbig = false;
}
: ('0'..'9')
)?
)?
;
// hexadecimal digit (again, note it's protected!)
protected
: ('0'..'9'|'A'..'F'|'a'..'f')
;
// a numeric literal
{
boolean isDecimal=false;
int tokenType = DOUBLE_LITERAL;
}
(EXPONENT)?
( ('x'|'X')
( // hex
// the 'e'|'E' and float suffix stuff look
// like hex digits, hence the (...)+ doesn't
// know when to stop: ambig. ANTLR resolves
// it correctly by matching immediately. It
// is therefor ok to hush warning.
options {
warnWhenFollowAmbig=false;
}
)+
| ('0'..'7')+ // octal
)?
)
// only check to see if it's a float if looks like decimal so far
| {isDecimal}?
{tokenType = DOUBLE_LITERAL;}
)
)?
;
// a couple protected methods to assist in matching floating point numbers
protected
: ('e'|'E') ('+'|'-')? ('0'..'9')+
;
protected
;
// an identifier. Note that testLiterals is set to true! This means
// that after we match the rule, we look in the literals table to see
// if it's a literal or really an identifer
: ( 'a'..'z'
| 'A'..'Z'
| '_'
| '$'
{
}
}
)
( 'a'..'z'
| 'A'..'Z'
| '_'
| '$'
| '0'..'9'
{
}
}
)*
;
protected
{
try {
// problems using ANTLR feature $setText => use generated code
}
catch (NumberFormatException ex) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "jqlc.parser.invalidunicodestr"), ex); //NOI18N
}
}
;
//===== Parser Class Definitions =====
/**
* This class defines the syntax analysis (parser) of the JQL compiler.
*
* @author Michael Bouschen
* @version 0.1
*/
options {
k = 2; // two token lookahead
exportVocab = JQL;
buildAST = true;
}
{
// "imaginary" tokens, that have no corresponding real input
// operators
// special dot expressions
// identifier types
// constant value
// result definition
// non-standard extensions (operators)
LIKE;
ABS;
SQRT;
//
}
{
/**
* I18N support
*/
JQLParser.class);
/** */
/**
*
*/
/**
*
*/
{
}
/**
* ANTLR method called when an error was detected.
*/
{
}
/**
* ANTLR method called when an error was detected.
*/
public void reportError(String s)
{
}
/**
*
*/
{
}
/**
* ANTLR method called when a warning was detected.
*/
public void reportWarning(String s)
{
throw new JDOQueryException(s);
}
/**
*
*/
{
if (ex instanceof MismatchedCharException)
{
{
{
}
else
{
}
return;
}
}
else if (ex instanceof MismatchedTokenException)
{
{
}
else {
}
return;
}
}
else if (ex instanceof NoViableAltException)
{
{
{
}
else
{
}
return;
}
}
else if (ex instanceof NoViableAltForCharException)
{
}
else if (ex instanceof TokenStreamRecognitionException)
{
}
// no special handling from aboves matches the exception if this line is reached =>
// make it a syntax error
int line = 0;
int column = 0;
if (ex instanceof RecognitionException)
{
}
}
}
// ----------------------------------
// rules: import declaration
// ----------------------------------
{
}
;
{
#i.setType(IMPORT_DEF);
}
;
// ----------------------------------
// rules: parameter declaration
// ----------------------------------
{
}
;
;
// ----------------------------------
// rules: variables declaration
// ----------------------------------
{
}
;
;
// ----------------------------------
// rules ordering specification
// ----------------------------------
{
}
;
: e:expression d:direction
;
;
// ----------------------------------
// rules result expression
// ----------------------------------
{
}
{
// create RESULT_DEF node if there was a projection
if (#a != null) {
// skip a possible first distinct in case of an aggregate expr
}
else if (#e != null) {
}
}
;
;
: DISTINCT^ e:expression
;
// ----------------------------------
// rules filer expression
// ----------------------------------
{
}
: e:expression EOF!
;
// This is a list of expressions.
;
;
// conditional or ||
;
// conditional and &&
;
// bitwise or logical or |
;
// exclusive or ^
;
// bitwise or logical and &
;
// equality/inequality ==/!=
;
// boolean relational expressions
( ( LT^
| GT^
| LE^
| GE^
)
)*
;
// binary addition/subtraction
;
;
;
;
// qualified names, field access, method invocation
: primary
;
: LPAREN!
| /* empty list */
)
;
// the basic element of an expression
: IDENT
| literal
| THIS
;
: TRUE
| FALSE
| c:CHAR_LITERAL
{
// strip quotes from the token text
}
| s:STRING_LITERAL
{
// strip quotes from the token text
}
| NULL
;
;
;
// The primitive types.
: BOOLEAN
| BYTE
| CHAR
| SHORT
| INT
| FLOAT
| LONG
| DOUBLE
;