private RuntimeResult VisitForEachNode(ForEachNode node, Context context) { RuntimeResult iterResult = Visit(node.Iteratable, context); if (iterResult.HasError) { return(iterResult); } int elementCount = iterResult.Value.GetElementCount(); string varName = node.Token.Value.ToString(); for (int i = 0; i < elementCount; i++) { RuntimeResult runtimeResult = iterResult.Value.GetElementAt(i); if (runtimeResult.HasError) { return(runtimeResult); } context.AddSymbol(varName, runtimeResult.Value); RuntimeResult bodyResult = Visit(node.Body, context); if (bodyResult.HasError) { return(bodyResult); } } return(new RuntimeResult(iterResult.Value)); }
private IEnumerable <Parser <Node <TContext, TRequest, TResponse> > > GetParsers() { return(new[] { IfSetNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), EndIfSetNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), ForEachNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), EndForEachNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), IncludeNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), ModelNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), RootNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), ParentNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions), ChildNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions) } .Concat(ViewOptions.CustomExpressionParsers.Select(_ => _.Select(e => new CustomExpressionNode <TContext, TRequest, TResponse>(Options, ViewOptions, e)))) .Concat(new[] { ContentNode <TContext, TRequest, TResponse> .GetParser(Options, ViewOptions) })); }
public ForEachCompiler(ForEachNode node) { this.node = node; }
private static void GenerateForEach(ForEachNode node, DataContext data) { WriteLine(data, "context.DeclareVariable(\"{0}\");", node.VariableDeclaration.VariableName); data.VariableMap.DeclareVariable(node.VariableDeclaration.VariableName, node.Line, node.Column); StartLine(data, "foreach (dynamic {0} in ", data.VariableMap.GetVariableName(node.VariableDeclaration.VariableName)); data.CodeBlock.DisableNewLines = true; GenerateExpression(node.SourceExpression, data); data.CodeBlock.DisableNewLines = false; EndLine(data, ") {{"); data.CodeBlock.Padding++; WriteLine(data, "context.SetVariable(\"{0}\", {1});", node.VariableDeclaration.VariableName, data.VariableMap.GetVariableName(node.VariableDeclaration.VariableName)); GenerateStatementBlock(node.BodyStatementBlock, data); data.CodeBlock.Padding--; WriteLine(data, "}}"); }