public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            Scope varScope = scope.Child();

            ForeachVar = new Var(foreachContext.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(foreachContext.name)), parseInfo);
            ForeachVar.VariableType = VariableType.ElementReference;
            ForeachVar.CodeType     = CodeType.GetCodeTypeFromContext(parseInfo, foreachContext.code_type());
            ForeachVar.Finalize(varScope);

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo, varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
Exemplo n.º 2
0
        public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            RawContinue = false;

            Scope varScope = scope.Child();

            ForeachVar = new ForeachVariable(varScope, new ForeachContextHandler(parseInfo, foreachContext));

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = parseInfo.GetExpression(scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
        public ForEachNode(DeltinScriptParser.ForeachContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context)))
        {
            errorRange = new Location(visitor.file, DocRange.GetRange(context.FOREACH()));
            Array      = visitor.Visit(context.expr());
            Variable   = new ParameterDefineNode(context.parameter_define(), visitor);
            Block      = (BlockNode)visitor.VisitBlock(context.block());

            Repeaters = 1;
            if (context.number() != null)
            {
                Repeaters = int.Parse(context.number().GetText());
            }
        }