示例#1
0
        public override Node VisitExpr(DeltinScriptParser.ExprContext context)
        {
            Node node;

            // Operations
            if (context.ChildCount == 3 && Constants.AllOperations.Contains(context.GetChild(1).GetText()))
            {
                IExpressionNode left      = (IExpressionNode)Visit(context.GetChild(0));
                string          operation = context.GetChild(1).GetText();
                IExpressionNode right     = (IExpressionNode)Visit(context.GetChild(2));


                node = new OperationNode(left, operation, right, Range.GetRange(context));
            }

            // Getting values in arrays
            else if (context.ChildCount == 4 &&
                     context.GetChild(0) is DeltinScriptParser.ExprContext &&
                     context.GetChild(1).GetText() == "[" &&
                     context.GetChild(2) is DeltinScriptParser.ExprContext &&
                     context.GetChild(3).GetText() == "]")
            {
                IExpressionNode value = (IExpressionNode)Visit(context.GetChild(0));
                IExpressionNode index = (IExpressionNode)Visit(context.GetChild(2));

                node = new ValueInArrayNode(value, index, Range.GetRange(context));
            }

            // Seperator
            else if (context.ChildCount == 3 &&
                     context.GetChild(0) is DeltinScriptParser.ExprContext &&
                     context.GetChild(1).GetText() == "." &&
                     context.GetChild(2) is DeltinScriptParser.VariableContext)
            {
                string          name   = context.GetChild(2).GetText();
                IExpressionNode target = (IExpressionNode)Visit(context.GetChild(0));

                node = new VariableNode(name, target, Range.GetRange(context));
            }

            // Not
            else if (context.ChildCount == 2 &&
                     context.GetChild(0).GetText() == "!" &&
                     context.GetChild(1) is DeltinScriptParser.ExprContext)
            {
                IExpressionNode value = (IExpressionNode)Visit(context.GetChild(1));
                node = new NotNode(value, Range.GetRange(context));
            }

            else
            {
                return(Visit(context.GetChild(0)));
            }

            CheckRange(node);
            return(node);
        }
        public override Node VisitExpr(DeltinScriptParser.ExprContext context)
        {
            Node node;

            // Operations
            if (context.ChildCount == 3 && Constants.AllOperations.Contains(context.GetChild(1).GetText()))
            {
                Node   left      = Visit(context.GetChild(0));
                string operation = context.GetChild(1).GetText();
                Node   right     = Visit(context.GetChild(2));

                node = new OperationNode(left, operation, right, new Location(file, Range.GetRange(context)));
            }

            // Getting values in arrays
            else if (context.ChildCount == 4 &&
                     context.GetChild(0) is DeltinScriptParser.ExprContext &&
                     context.GetChild(1).GetText() == "[" &&
                     context.GetChild(2) is DeltinScriptParser.ExprContext &&
                     context.GetChild(3).GetText() == "]")
            {
                Node value = Visit(context.GetChild(0));
                Node index = Visit(context.GetChild(2));

                node = new ValueInArrayNode(value, index, new Location(file, Range.GetRange(context)));
            }

            // Seperator
            else if (context.SEPERATOR() != null && context.expr().Length >= 2)
            {
                node = new ExpressionTreeNode(context, this);
            }

            // Not
            else if (context.ChildCount == 2 &&
                     context.GetChild(0).GetText() == "!" &&
                     context.GetChild(1) is DeltinScriptParser.ExprContext)
            {
                Node value = Visit(context.GetChild(1));
                node = new NotNode(value, new Location(file, Range.GetRange(context)));
            }

            // Ternary Condition
            else if (context.ChildCount == 5 &&
                     context.GetChild(0) is DeltinScriptParser.ExprContext &&
                     context.GetChild(1).GetText() == "?" &&
                     context.GetChild(2) is DeltinScriptParser.ExprContext &&
                     context.GetChild(3).GetText() == ":" &&
                     context.GetChild(4) is DeltinScriptParser.ExprContext)
            {
                Node condition   = VisitExpr(context.expr(0));
                Node consequent  = VisitExpr(context.expr(1));
                Node alternative = VisitExpr(context.expr(2));
                node = new TernaryConditionalNode(condition, consequent, alternative, new Location(file, Range.GetRange(context)));
            }

            // This
            else if (context.THIS() != null)
            {
                node = new ThisNode(new Location(file, Range.GetRange(context)));
            }

            else
            {
                return(Visit(context.GetChild(0)));
            }

            return(node);
        }