protected Statement nested_function()
{
Statement stmt;
IToken def = null;
IToken id = null;
stmt = null;
BlockExpression be = null;
Block body = null;
TypeReference rt = null;
try { // for error handling
def = LT(1);
match(DEF);
id = LT(1);
match(ID);
if (0==inputState.guessing)
{
be = new BlockExpression(ToLexicalInfo(id));
body = be.Body;
}
{
switch ( LA(1) )
{
case LPAREN:
{
match(LPAREN);
parameter_declaration_list(be.Parameters);
match(RPAREN);
{
switch ( LA(1) )
{
case AS:
{
match(AS);
rt=type_reference();
if (0==inputState.guessing)
{
be.ReturnType = rt;
}
break;
}
case COLON:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
break;
}
case COLON:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
compound_stmt(body);
if (0==inputState.guessing)
{
string name = id.getText();
stmt = new DeclarationStatement(
ToLexicalInfo(def),
new Declaration(
ToLexicalInfo(id),
name),
be);
be[BlockExpression.ClosureNameAnnotation] = name;
}
}
catch (RecognitionException ex)
{
if (0 == inputState.guessing)
{
reportError(ex, "nested_function");
recover(ex,tokenSet_82_);
}
else
{
throw ex;
}
}
return stmt;
}