private Statement ParseYieldStmt() { NextToken(); Location start = GetStart(); FunctionDefinition current = CurrentFunction; int yieldId = 0; if (current == null) { ReportSyntaxError("'yield' outside function"); } else { yieldId = current.YieldCount++; } Expression e = ParseTestListAsExpr(false); YieldStatement ret = new YieldStatement(e, yieldId); ret.SetLoc(GetExternal(), start, GetEnd()); return ret; }
private Expression ParseGeneratorExpression(Expression test) { ForStatement root = ParseGenExprFor(); Statement current = root; for (; ; ) { if (PeekToken(Tokens.KeywordForToken)) { current = NestGenExpr(current, ParseGenExprFor()); } else if (PeekToken(Tokens.KeywordIfToken)) { current = NestGenExpr(current, ParseGenExprIf()); } else { YieldStatement ys = new YieldStatement(test, 0); ys.SetLoc(GetExternal(), test.Start, test.End); NestGenExpr(current, ys); break; } } SymbolId fname = SymbolTable.StringToId("__gen_" + System.Threading.Interlocked.Increment(ref genexp_counter)); NameExpression pname = new NameExpression(SymbolTable.GeneratorParmName); FunctionDefinition func = new FunctionDefinition(fname, new Expression[] { pname }, new Expression[] { }, FunctionAttributes.None, root, context.SourceFile); func.YieldCount = 1; func.SetLoc(GetExternal(), root.Start, GetEnd()); func.Header = root.End; // Transform the root "for" statement Expression outermost = root.List; root.List = pname; CallExpression gexp = FinishCallExpr(new NameExpression(fname), new Arg(outermost)); CallExpression iter = FinishCallExpr(new NameExpression(SymbolTable.Iter), new Arg(gexp)); GeneratorExpression ret = new GeneratorExpression(func, iter); ret.SetLoc(GetExternal(), root.Start, GetEnd()); return ret; }