示例#1
0
        private static int GetParentScopeIndent(InterpreterScope scope, PythonAst tree)
        {
            if (scope is ClassScope)
            {
                // Return column of "class" statement
                return(tree.IndexToLocation(scope.GetStart(tree)).Column);
            }

            var function = scope as FunctionScope;

            if (function != null && !((FunctionDefinition)function.Node).IsLambda)
            {
                // Return column of "def" statement
                return(tree.IndexToLocation(scope.GetStart(tree)).Column);
            }

            var isinstance = scope as IsInstanceScope;

            if (isinstance != null && isinstance._effectiveSuite != null)
            {
                int col = tree.IndexToLocation(isinstance._startIndex).Column;
                if (isinstance._effectiveSuite.StartIndex < isinstance._startIndex)
                {
                    // "assert isinstance", so scope is before the test
                    return(col - 1);
                }
                else
                {
                    // "if isinstance", so scope is at the test
                    return(col);
                }
            }

            return(-1);
        }