*
* @return
* @throws RecognitionException
*/
public RuleDescr query( PackageDescrBuilder pkg ) throws RecognitionException {
QueryDescrBuilder query = null;
try {
query = helper.start( pkg,
QueryDescrBuilder.class,
null );
// 'query'
match( input,
DRL5Lexer.ID,
DroolsSoftKeywords.QUERY,
null,
DroolsEditorType.KEYWORD );
if ( state.failed ) return null;
if ( helper.validateIdentifierKey( DroolsSoftKeywords.WHEN ) ||
helper.validateIdentifierKey( DroolsSoftKeywords.THEN ) ||
helper.validateIdentifierKey( DroolsSoftKeywords.END ) ) {
failMissingTokenException();
return null; // in case it is backtracking
}
String name = stringId();
if ( state.backtracking == 0 ) query.name( name );
if ( state.failed ) return null;
if ( state.backtracking == 0) {
helper.emit( Location.LOCATION_RULE_HEADER );
}
if ( speculateParameters( true ) ) {
// parameters
parameters( query,
true );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) {
helper.emit( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
}
} else if ( speculateParameters( false ) ) {
// parameters
parameters( query,
false );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) {
helper.emit( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
}
}
while ( input.LA( 1 ) == DRL5Lexer.AT ) {
// annotation*
annotation( query );
if ( state.failed ) return null;
}
if ( state.backtracking == 0 && input.LA( 1 ) != DRL5Lexer.EOF ) {
helper.emit( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
}
if (input.LA( 1 ) != DRL5Lexer.EOF ){
lhsExpression( query != null ? query.lhs() : null );
}
match( input,
DRL5Lexer.ID,
DroolsSoftKeywords.END,
null,
DroolsEditorType.KEYWORD );
if ( state.failed ) return null;
helper.emit( Location.LOCATION_RHS );
} catch ( RecognitionException re ) {
reportError( re );
} finally {
helper.end( QueryDescrBuilder.class,
query );
}
return (query != null) ? query.getDescr() : null;
}