*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public FunctionDescr function( PackageDescrBuilder pkg ) throws RecognitionException {
FunctionDescrBuilder function = null;
try {
function = helper.start( pkg,
FunctionDescrBuilder.class,
null );
// 'function'
match( input,
DRL6Lexer.ID,
DroolsSoftKeywords.FUNCTION,
null,
DroolsEditorType.KEYWORD );
if ( state.failed ) return null;
if ( input.LA( 1 ) != DRL6Lexer.ID || input.LA( 2 ) != DRL6Lexer.LEFT_PAREN ) {
// type
String type = type();
if ( state.failed ) return null;
if ( state.backtracking == 0 ) function.returnType( type );
}
// name
Token id = match( input,
DRL6Lexer.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( DRL6Lexer.LEFT_CURLY,
DRL6Lexer.RIGHT_CURLY,
-1 );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) function.body( body );
} catch ( RecognitionException re ) {
reportError( re );
} finally {
helper.end( FunctionDescrBuilder.class,
function );
}
return (function != null) ? function.getDescr() : null;
}