public ExpressionTreeNode(DeltinScriptParser.ExprContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context)))
 {
     Tree = new Node[context.expr().Length];
     for (int i = 0; i < Tree.Length; i++)
     {
         Tree[i] = visitor.VisitExpr(context.expr(i));
     }
 }
        Element ParseExpression(DeltinScriptParser.ExprContext context)
        {
            // If the expression is a(n)...

            #region Operation

            //   0       1      2
            // (expr operation expr)
            // count == 3
            if (context.ChildCount == 3 &&
                (Constants.MathOperations.Contains(context.GetChild(1).GetText()) ||
                 Constants.CompareOperations.Contains(context.GetChild(1).GetText()) ||
                 Constants.BoolOperations.Contains(context.GetChild(1).GetText())))
            {
                Element left      = ParseExpression(context.GetChild(0) as DeltinScriptParser.ExprContext);
                string  operation = context.GetChild(1).GetText();
                Element right     = ParseExpression(context.GetChild(2) as DeltinScriptParser.ExprContext);

                if (Constants.BoolOperations.Contains(context.GetChild(1).GetText()))
                {
                    if (left.ElementData.ValueType != Elements.ValueType.Any && left.ElementData.ValueType != Elements.ValueType.Boolean)
                    {
                        throw new SyntaxErrorException($"Expected boolean datatype, got {left .ElementData.ValueType.ToString()} instead.", context.start);
                    }
                    if (right.ElementData.ValueType != Elements.ValueType.Any && right.ElementData.ValueType != Elements.ValueType.Boolean)
                    {
                        throw new SyntaxErrorException($"Expected boolean datatype, got {right.ElementData.ValueType.ToString()} instead.", context.start);
                    }
                }

                switch (operation)
                {
                case "^":
                    return(Element.Part <V_RaiseToPower>(left, right));

                case "*":
                    return(Element.Part <V_Multiply>(left, right));

                case "/":
                    return(Element.Part <V_Divide>(left, right));

                case "+":
                    return(Element.Part <V_Add>(left, right));

                case "-":
                    return(Element.Part <V_Subtract>(left, right));

                case "%":
                    return(Element.Part <V_Modulo>(left, right));

                // COMPARE : '<' | '<=' | '==' | '>=' | '>' | '!=';

                case "&":
                    return(Element.Part <V_And>(left, right));

                case "|":
                    return(Element.Part <V_Or>(left, right));

                case "<":
                    return(Element.Part <V_Compare>(left, Operators.LessThan, right));

                case "<=":
                    return(Element.Part <V_Compare>(left, Operators.LessThanOrEqual, right));

                case "==":
                    return(Element.Part <V_Compare>(left, Operators.Equal, right));

                case ">=":
                    return(Element.Part <V_Compare>(left, Operators.GreaterThanOrEqual, right));

                case ">":
                    return(Element.Part <V_Compare>(left, Operators.GreaterThan, right));

                case "!=":
                    return(Element.Part <V_Compare>(left, Operators.NotEqual, right));
                }
            }

            #endregion

            #region Not

            if (context.GetChild(0) is DeltinScriptParser.NotContext)
            {
                return(Element.Part <V_Not>(ParseExpression(context.GetChild(1) as DeltinScriptParser.ExprContext)));
            }

            #endregion

            #region Number

            if (context.GetChild(0) is DeltinScriptParser.NumberContext)
            {
                var number = context.GetChild(0);

                double num = double.Parse(number.GetChild(0).GetText());

                /*
                 * // num will have the format expr(number(X)) if positive, expr(number(neg(X))) if negative.
                 * if (number.GetChild(0) is DeltinScriptParser.NegContext)
                 *  // Is negative, use '-' before int.parse to make it negative.
                 *  num = -double.Parse(number.GetChild(0).GetText());
                 * else
                 *  // Is positive
                 *  num = double.Parse(number.GetChild(0).GetText());
                 */

                return(new V_Number(num));
            }

            #endregion

            #region Boolean

            // True
            if (context.GetChild(0) is DeltinScriptParser.TrueContext)
            {
                return(new V_True());
            }

            // False
            if (context.GetChild(0) is DeltinScriptParser.FalseContext)
            {
                return(new V_False());
            }

            #endregion

            #region String

            if (context.GetChild(0) is DeltinScriptParser.StringContext)
            {
                return(V_String.ParseString(
                           context.start,
                           // String will look like "hey this is the contents", trim the quotes.
                           (context.GetChild(0) as DeltinScriptParser.StringContext).STRINGLITERAL().GetText().Trim('\"'),
                           null
                           ));
            }

            #endregion

            #region Formatted String

            if (context.GetChild(1) is DeltinScriptParser.StringContext)
            {
                Element[] values = context.expr().Select(expr => ParseExpression(expr)).ToArray();
                return(V_String.ParseString(
                           context.start,
                           (context.GetChild(1) as DeltinScriptParser.StringContext).STRINGLITERAL().GetText().Trim('\"'),
                           values
                           ));
            }

            #endregion

            #region null

            if (context.GetChild(0) is DeltinScriptParser.NullContext)
            {
                return(new V_Null());
            }

            #endregion

            #region Group ( expr )

            if (context.ChildCount == 3 && context.GetChild(0).GetText() == "(" &&
                context.GetChild(1) is DeltinScriptParser.ExprContext &&
                context.GetChild(2).GetText() == ")")
            {
                Console.WriteLine("Group type:" + context.GetChild(0).GetType());
                return(ParseExpression(context.GetChild(1) as DeltinScriptParser.ExprContext));
            }

            #endregion

            #region Method

            if (context.GetChild(0) is DeltinScriptParser.MethodContext)
            {
                return(ParseMethod(context.GetChild(0) as DeltinScriptParser.MethodContext, true));
            }

            #endregion

            #region Variable

            if (context.GetChild(0) is DeltinScriptParser.VariableContext)
            {
                return(DefinedVar.GetVar((context.GetChild(0) as DeltinScriptParser.VariableContext).PART().GetText(), context.start).GetVariable(new V_EventPlayer()));
            }

            #endregion

            #region Array

            if (context.ChildCount == 4 && context.GetChild(1).GetText() == "[" && context.GetChild(3).GetText() == "]")
            {
                return(Element.Part <V_ValueInArray>(
                           ParseExpression(context.expr(0) as DeltinScriptParser.ExprContext),
                           ParseExpression(context.expr(1) as DeltinScriptParser.ExprContext)));
            }

            #endregion

            #region Create Array

            if (context.ChildCount >= 4 && context.GetChild(0).GetText() == "[")
            {
                var      expressions = context.expr();
                V_Append prev        = null;
                V_Append current     = null;

                for (int i = 0; i < expressions.Length; i++)
                {
                    current = new V_Append()
                    {
                        ParameterValues = new object[2]
                    };

                    if (prev != null)
                    {
                        current.ParameterValues[0] = prev;
                    }
                    else
                    {
                        current.ParameterValues[0] = new V_EmptyArray();
                    }

                    current.ParameterValues[1] = ParseExpression(expressions[i]);
                    prev = current;
                }

                return(current);
            }

            #endregion

            #region Empty Array

            if (context.ChildCount == 2 && context.GetText() == "[]")
            {
                return(Element.Part <V_EmptyArray>());
            }

            #endregion

            #region Seperator/enum

            if (context.ChildCount == 3 && context.GetChild(1).GetText() == ".")
            {
                Element left         = ParseExpression(context.GetChild(0) as DeltinScriptParser.ExprContext);
                string  variableName = context.GetChild(2).GetChild(0).GetText();

                DefinedVar var = DefinedVar.GetVar(variableName, context.start);

                return(var.GetVariable(left));
            }

            #endregion

            throw new Exception($"What's a {context.GetType().Name}?");
        }
        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);
        }