private static Boolean?CheckIfFinishedOrEmptyLine(
            PainContext PainContext,
            PainState currentState)
        {
            if (currentState == null || PainContext.IsFinished)
            {
                PainContext.IsFinished = true;
                return(true);
            }

            PainCodeLines lines       = currentState.GetCurrentLines();
            PainCodeLine  currentLine = currentState.GetCurrentLine();

            if (currentLine == null)
            {
                return(ExitCurrentContext(
                           PainContext));
            }

            // jeśli linia jest pusta to przechodzimy do nastepnej
            if (currentLine.IsLineEmpty)
            {
                PainCodeLine nextLine = lines.NextLine(currentLine);
                if (nextLine == null)
                {
                    return(ExitCurrentContext(
                               PainContext));
                }
                else
                {
                    currentState.CurrentLineID = nextLine.ID;
                }
                return(true);
            }
            return(null);
        }
        //////////////////////////////////////////////

        private static Boolean GotoNextLine(
            PainContext PainContext,
            PainState currentState,
            Object currentValue)
        {
            try
            {
                PainCodeLines lines       = currentState.GetCurrentLines();
                PainCodeLine  currentLine = currentState.GetCurrentLine();

                // jesli return to konczymy
                if (currentLine.OperatorType == EOperatorType.RETURN)
                {
                    return(ExitCurrentContext(
                               PainContext,
                               currentValue));
                }
                // throw błędu
                else if (currentLine.OperatorType == EOperatorType.THROW)
                {
                    if (currentValue is Exception)
                    {
                        throw (Exception)currentValue;
                    }
                    else
                    {
                        String message = UniConvert.ToString(currentValue ?? "");
                        throw String.IsNullOrEmpty(message) ? new Exception() : new Exception(message);
                    }

                    /*return ExitCurrentContext(
                     *  PainContext,
                     *  new Exception(message));*/
                }

                if (currentLine.OperatorType == EOperatorType.WHILE ||
                    currentLine.OperatorType == EOperatorType.IF ||
                    currentLine.OperatorType == EOperatorType.ELIF)
                {
                    Boolean conditionResult = currentValue.IfTrue();
                    if (conditionResult)
                    {
                        PainCodeLine nextLine = lines.NextOnSameOrHigher(currentLine);
                        if (nextLine != null)
                        {
                            currentState.CurrentLineID = nextLine.ID;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    else
                    {
                        PainCodeLine nextLine = lines.NextOnSameOrLower(currentLine);
                        if (nextLine == null)
                        {
                            return(ExitCurrentContext(
                                       PainContext));
                        }
                        else
                        {
                            if (nextLine.Depth < currentLine.Depth)
                            {
                                while (
                                    nextLine != null &
                                    (nextLine.OperatorType == EOperatorType.ELSE ||
                                     nextLine.OperatorType == EOperatorType.ELIF /*||
                                                                                  * nextLine.OperatorType == EOperatorType.FINALLY*/))
                                {
                                    nextLine = lines.ExitParentIf(nextLine);

                                    if (nextLine == null)
                                    {
                                        break;
                                    }
                                }

                                if (nextLine == null)
                                {
                                    return(ExitCurrentContext(
                                               PainContext));
                                }

                                if (nextLine.Depth < currentLine.Depth)
                                {
                                    //PainCodeLine prevIf = lines.
                                    //    PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF);

                                    while (true)
                                    {
                                        PainCodeLine prevConditionLine = lines.
                                                                         PrevLineWithLessDepth(
                                            currentLine,
                                            l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE);

                                        if (prevConditionLine != null &&
                                            prevConditionLine.Depth >= nextLine.Depth &&
                                            prevConditionLine.OperatorType == EOperatorType.WHILE)
                                        {
                                            currentState.CurrentLineID = prevConditionLine.ID;
                                            break;
                                        }
                                        else if (prevConditionLine != null)
                                        {
                                            currentLine = prevConditionLine;
                                        }
                                        else
                                        {
                                            currentState.CurrentLineID = nextLine.ID;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    currentState.CurrentLineID = nextLine.ID;
                                }
                            }
                            else
                            {
                                currentState.CurrentLineID = nextLine.ID;
                            }
                        }
                    }
                }
                else if (
                    currentLine.OperatorType == EOperatorType.TRY ||
                    currentLine.OperatorType == EOperatorType.ELSE)
                {
                    PainCodeLine nextLine = lines.NextOnSameOrHigher(currentLine);
                    if (nextLine != null)
                    {
                        currentState.CurrentLineID = nextLine.ID;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else if (
                    (currentLine.OperatorType == EOperatorType.FINALLY))
                {
                    throw new NotImplementedException("FINALLY");
                }
                else if (
                    (currentLine.OperatorType == EOperatorType.CATCH))
                {
                    if (PainContext.Error != null)
                    {
                        PainContext.Error = null;
                        PainCodeLine nextLine = lines.NextOnSameOrHigher(currentLine);
                        if (nextLine != null)
                        {
                            currentState.CurrentLineID = nextLine.ID;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    else
                    {
                        PainCodeLine nextLine = lines.NextOnSameOrLower(currentLine);
                        if (nextLine != null)
                        {
                            currentState.CurrentLineID = nextLine.ID;
                        }
                        else
                        {
                            return(ExitCurrentContext(
                                       PainContext));
                        }
                    }
                }
                else if (currentLine.OperatorType == EOperatorType.NONE)
                {
                    PainCodeLine nextLine = lines.NextLine(currentLine);
                    if (nextLine != null)
                    {
                        while (
                            nextLine != null &
                            (nextLine.OperatorType == EOperatorType.ELSE ||
                             nextLine.OperatorType == EOperatorType.ELIF /*||
                                                                          * nextLine.OperatorType == EOperatorType.FINALLY*/))
                        {
                            nextLine = lines.ExitParentIf(nextLine);

                            if (nextLine == null)
                            {
                                return(ExitCurrentContext(
                                           PainContext));
                            }
                        }

                        if (nextLine == null)
                        {
                            return(ExitCurrentContext(
                                       PainContext));
                        }

                        if (nextLine.Depth < currentLine.Depth)
                        {
                            //PainCodeLine prevIf = lines.
                            //    PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF);

                            while (true)
                            {
                                PainCodeLine prevConditionLine = lines.
                                                                 PrevLineWithLessDepth(
                                    currentLine,
                                    l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE);

                                if (prevConditionLine != null &&
                                    prevConditionLine.Depth >= nextLine.Depth &&
                                    prevConditionLine.OperatorType == EOperatorType.WHILE)
                                {
                                    currentState.CurrentLineID = prevConditionLine.ID;
                                    break;
                                }
                                else if (prevConditionLine != null)
                                {
                                    currentLine = prevConditionLine;
                                }
                                else
                                {
                                    currentState.CurrentLineID = nextLine.ID;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            currentState.CurrentLineID = nextLine.ID;
                        }
                    }
                    // jeśli ostatnia linia i jesteśmy w while'u
                    else
                    {
                        //PainCodeLine prevIf = lines.
                        //    PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF);

                        while (true)
                        {
                            PainCodeLine prevConditionLine = lines.
                                                             PrevLineWithLessDepth(
                                currentLine,
                                l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE);

                            if (prevConditionLine != null &&
                                prevConditionLine.OperatorType == EOperatorType.WHILE)
                            {
                                currentState.CurrentLineID = prevConditionLine.ID;
                                break;
                            }
                            else if (prevConditionLine != null)
                            {
                                currentLine = prevConditionLine;
                            }
                            else
                            {
                                return(ExitCurrentContext(
                                           PainContext));
                            }
                        }
                    }
                }
                return(false);
            }
            catch
            {
                throw;
            }
        }