public override object VisitLoopEachStatement(LoopEachStatementContext context) { var obj = ""; var arr = (Result)(Visit(context.expression())); var target = arr.text; var id = "ea"; if (context.id().Length == 2) { target = (new System.Text.StringBuilder().Append("range(").Append(target).Append(")")).to_str(); id = (new System.Text.StringBuilder().Append("(").Append(((Result)(Visit(context.id(0)))).text).Append(", ").Append(((Result)(Visit(context.id(1)))).text).Append(")")).to_str(); } else if (context.id().Length == 1) { id = ((Result)(Visit(context.id(0)))).text; } obj += (new System.Text.StringBuilder().Append("foreach (var ").Append(id).Append(" in ").Append(target).Append(")")).to_str(); obj += BlockLeft + Wrap; this.add_current_set(); obj += ProcessFunctionSupport(context.functionSupportStatement()); this.delete_current_set(); obj += BlockRight + Wrap; if (context.loopElseStatement() != null) { var elseContent = (string)(Visit(context.loopElseStatement())); obj = (new System.Text.StringBuilder().Append("if (!can_range(").Append(target).Append(")) ").Append(elseContent).Append(" else ").Append(BlockLeft).Append(Wrap).Append(obj).Append(BlockRight).Append(Wrap)).to_str(); } return(obj); }
public override object VisitLoopEachStatement([NotNull] LoopEachStatementContext context) { var obj = ""; var arr = (Visit(context.expression()) as Result); var target = arr.text; var id = "ea"; if (context.id().Length == 2) { target += ".range()"; id = $"({((Result)Visit(context.id(0))).text},{((Result)Visit(context.id(1))).text})"; } else if (context.id().Length == 1) { id = ((Result)Visit(context.id(0))).text; } obj += $"foreach (var {id} in {target})"; obj += $"{Wrap} {BlockLeft} {Wrap}"; obj += ProcessFunctionSupport(context.functionSupportStatement()); obj += $"{BlockRight} {Terminate} {Wrap}"; return(obj); }