public static ConditionBlockNode Create(ContextNode context, ExpressionNode condition, CodeBlockNode trueBlock, CodeBlockNode falseBlock, SequencePoint point)
        {
            var instance = new ConditionBlockNode(point);

            if (!condition.IsGettable || !condition.ExpressionReturnType.IsAssignableTo(context.Parser.Bool))
            {
                ErrorCode.InvalidCondition.ReportAndThrow(point, "Condition must be a gettable boolean expression");
            }
            instance.condition  = condition;
            instance.trueBlock  = trueBlock;
            instance.falseBlock = falseBlock;
            return(instance);
        }
        public CodeBlockNode AddNode(IAbstractSyntaxTree lexerNode)
        {
            switch (lexerNode.Type)
            {
            case Lexer.TokenType.WhileLoop:
                return(AddNode(WhileBlock.Parse(this, lexerNode)));

            case Lexer.TokenType.ConditionalSentence:
                return(AddNode(ConditionBlockNode.Parse(this, lexerNode)));

            case Lexer.TokenType.CodeBlockNode:
                return(AddNode(CodeBlockNode.Parse(this, lexerNode)));

            case Lexer.TokenType.ForLoop:
                return(AddNode(ForLoopNode.Parse(this, lexerNode)));

            case Lexer.TokenType.ForEachLoop:
                return(AddNode(ForEachNode.Parse(this, lexerNode)));

            case Lexer.TokenType.StatementWithEndOfLine:
                if (lexerNode.Children.Count == 2)
                {
                    return(AddStatement(lexerNode.Children[0]));
                }
                else
                {
                    //empty statement a.k.a ";"
                    return(this);
                }

            case Lexer.TokenType.UnknownNode:
                ErrorCode.InvalidStructure.ReportAndThrow(Parser.GetSequencePoint(lexerNode), "Could not parse as a statement");
                return(null);   //unreachable

            default:
                ErrorCode.InvalidStructure.ReportAndThrow(Parser.GetSequencePoint(lexerNode), "Unexpected node {0} in while parsing code block", lexerNode.Type);
                return(null);   //unreachable
            }
        }