public ForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForContext forContext)
        {
            Scope varScope = scope.Child();

            if (forContext.define() != null)
            {
                DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, forContext.define()));
            }
            else if (forContext.initialVarset != null)
            {
                InitialVarSet = new SetVariableAction(parseInfo, varScope, forContext.initialVarset);
            }

            if (forContext.expr() != null)
            {
                Condition = DeltinScript.GetExpression(parseInfo, varScope, forContext.expr());
            }

            if (forContext.endingVarset != null)
            {
                SetVariableAction = new SetVariableAction(parseInfo, varScope, forContext.endingVarset);
            }

            // Get the block.
            if (forContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, forContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(forContext.FOR()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected a block.", DocRange.GetRange(forContext.RIGHT_PAREN()));
            }
        }
Exemplo n.º 2
0
        public override Node VisitFor(DeltinScriptParser.ForContext context)
        {
            BlockNode block = (BlockNode)VisitBlock(context.block());

            VarSetNode varSet = null;

            if (context.varset() != null)
            {
                varSet = (VarSetNode)VisitVarset(context.varset());
            }

            DefineNode defineNode = null;

            if (context.define() != null)
            {
                defineNode = (DefineNode)VisitDefine(context.define());
            }

            Node expression = null;

            if (context.expr() != null)
            {
                expression = VisitExpr(context.expr());
            }

            VarSetNode statement = null;

            if (context.forEndStatement() != null)
            {
                statement = (VarSetNode)VisitVarset(context.forEndStatement().varset());
            }

            return(new ForNode(varSet, defineNode, expression, statement, block, new Location(file, Range.GetRange(context))));
        }
        public ForNode(DeltinScriptParser.ForContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context)))
        {
            errorRange = new Location(visitor.file, DocRange.GetRange(context.FOR()));
            Block      = (BlockNode)visitor.VisitBlock(context.block());

            if (context.varset() != null)
            {
                VarSetNode = (VarSetNode)visitor.VisitVarset(context.varset());
            }

            if (context.define() != null)
            {
                DefineNode = (DefineNode)visitor.VisitDefine(context.define());
            }

            if (context.expr() != null)
            {
                Expression = visitor.VisitExpr(context.expr());
            }

            if (context.forEndStatement() != null)
            {
                Statement = (VarSetNode)visitor.VisitVarset(context.forEndStatement().varset());
            }
        }
Exemplo n.º 4
0
        public override Node VisitFor(DeltinScriptParser.ForContext context)
        {
            Node      node;
            BlockNode block = (BlockNode)VisitBlock(context.block());

            if (context.IN() != null)
            {
                IExpressionNode array    = (IExpressionNode)Visit(context.expr());
                string          variable = context.PART().GetText();

                node = new ForEachNode(variable, array, block, Range.GetRange(context));
            }
            else
            {
                VarSetNode varSet = null;
                if (context.varset() != null)
                {
                    varSet = (VarSetNode)VisitVarset(context.varset());
                }

                ScopedDefineNode defineNode = null;
                if (context.define() != null)
                {
                    defineNode = (ScopedDefineNode)VisitDefine(context.define());
                }

                IExpressionNode expression = null;
                if (context.expr() != null)
                {
                    expression = (IExpressionNode)VisitExpr(context.expr());
                }

                IStatementNode statement = null;
                if (context.statement() != null)
                {
                    statement = (IStatementNode)VisitStatement(context.statement());
                }

                node = new ForNode(varSet, defineNode, expression, statement, block, Range.GetRange(context));
            }

            CheckRange(node);
            return(node);
        }