*
* @return
* @throws RecognitionException
*/
public FunctionDescr function() throws RecognitionException {
FunctionDescrBuilder function = null;
try {
function = helper.start( FunctionDescrBuilder.class,
null,
null );
// 'function'
match( input,
DRLLexer.ID,
DroolsSoftKeywords.FUNCTION,
null,
DroolsEditorType.KEYWORD );
if ( state.failed ) return null;
if ( input.LA( 1 ) != DRLLexer.ID || input.LA( 2 ) != DRLLexer.LEFT_PAREN ) {
// type
String type = type();
if ( state.failed ) return null;
if ( state.backtracking == 0 ) function.returnType( type );
}
// name
Token id = match( input,
DRLLexer.ID,
null,
null,
DroolsEditorType.IDENTIFIER );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) {
function.name( id.getText() );
helper.setParaphrasesValue( DroolsParaphraseTypes.FUNCTION,
"\"" + id.getText() + "\"" );
}
// arguments
parameters( function,
true );
if ( state.failed ) return null;
// body
String body = chunk( DRLLexer.LEFT_CURLY,
DRLLexer.RIGHT_CURLY,
-1 );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) function.body( body );
if ( input.LA( 1 ) == DRLLexer.SEMICOLON ) {
match( input,
DRLLexer.SEMICOLON,
null,
null,
DroolsEditorType.SYMBOL );
if ( state.failed ) return null;
}
} catch ( RecognitionException re ) {
reportError( re );
} finally {
helper.end( DeclareDescrBuilder.class,
null );
}
return (function != null) ? function.getDescr() : null;
}