示例#1
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var itemWhiteSpace = this.GetListWhiteSpace(ast);

            for (int i = 0; i < _tests.Length; i++)
            {
                if (itemWhiteSpace != null)
                {
                    format.ReflowComment(res, itemWhiteSpace[i]);
                }

                if (i == 0)
                {
                    res.Append("if");
                }
                else
                {
                    res.Append("elif");
                }
                _tests[i].AppendCodeString(res, ast, format);
            }

            if (_else != null)
            {
                format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
                res.Append("else");
                _else.AppendCodeString(res, ast, format);
            }
        }
示例#2
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            if (this.IsAltForm(ast))
            {
                ListExpression.AppendItems(res, ast, format, "", "", this, Items);
            }
            else
            {
                if (Items.Count == 0 &&
                    format.SpaceWithinEmptyTupleExpression != null)
                {
                    format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                    res.Append('(');
                    if (String.IsNullOrWhiteSpace(this.GetSecondWhiteSpace(ast)))
                    {
                        res.Append(format.SpaceWithinEmptyTupleExpression.Value ? " " : "");
                    }
                    else
                    {
                        format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                    }
                    res.Append(')');
                }
                else
                {
                    string delimWs =
                        format.SpacesWithinParenthesisedTupleExpression != null ?
                        format.SpacesWithinParenthesisedTupleExpression.Value ? " " : "" : null;

                    ListExpression.AppendItems(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? "" : ")", this, Items, delimWs);
                }
            }
        }
示例#3
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var decorateWhiteSpace = this.GetNamesWhiteSpace(ast);

            if (DecoratorsInternal != null)
            {
                for (int i = 0, curWhiteSpace = 0; i < DecoratorsInternal.Length; i++)
                {
                    if (decorateWhiteSpace != null)
                    {
                        format.ReflowComment(res, decorateWhiteSpace[curWhiteSpace++]);
                    }
                    res.Append('@');
                    if (DecoratorsInternal[i] != null)
                    {
                        DecoratorsInternal[i].AppendCodeString(res, ast, format);
                        if (decorateWhiteSpace != null)
                        {
                            format.ReflowComment(res, decorateWhiteSpace[curWhiteSpace++]);
                        }
                        else
                        {
                            res.Append(Environment.NewLine);
                        }
                    }
                }
            }
        }
示例#4
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var verbatimPieces   = this.GetVerbatimNames(ast);
            var verbatimComments = this.GetListWhiteSpace(ast);

            if (verbatimPieces != null)
            {
                // string+ / bytes+, such as "abc" "abc", which can spawn multiple lines, and
                // have comments in between the peices.
                for (var i = 0; i < verbatimPieces.Length; i++)
                {
                    if (verbatimComments != null && i < verbatimComments.Length)
                    {
                        format.ReflowComment(res, verbatimComments[i]);
                    }
                    res.Append(verbatimPieces[i]);
                }
            }
            else
            {
                format.ReflowComment(res, this.GetPreceedingWhiteSpaceDefaultNull(ast));
                if (this.GetExtraVerbatimText(ast) != null)
                {
                    res.Append(this.GetExtraVerbatimText(ast));
                }
                else
                {
                    RecursiveAppendRepr(res, ast, format);
                }
            }
        }
示例#5
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("try");
            _body.AppendCodeString(res, ast, format);

            if (_handlers != null)
            {
                for (int i = 0; i < _handlers.Length; i++)
                {
                    _handlers[i].AppendCodeString(res, ast, format);
                }
            }

            if (_else != null)
            {
                format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                res.Append("else");
                _else.AppendCodeString(res, ast, format);
            }

            if (_finally != null)
            {
                format.ReflowComment(res, this.GetThirdWhiteSpace(ast));
                res.Append("finally");
                _finally.AppendCodeString(res, ast, format);
            }
        }
示例#6
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            res.Append("try");
            Body.AppendCodeString(res, ast, format);

            foreach (var h in _handlers.MaybeEnumerate())
            {
                h.AppendCodeString(res, ast, format);
            }

            if (Else != null)
            {
                format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                res.Append("else");
                Else.AppendCodeString(res, ast, format);
            }

            if (Finally != null)
            {
                format.ReflowComment(res, this.GetThirdWhiteSpace(ast));
                res.Append("finally");
                Finally.AppendCodeString(res, ast, format);
            }
        }
示例#7
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("while");
     _test.AppendCodeString(res, ast, format);
     _body.AppendCodeString(res, ast, format);
     if (_else != null) {
         format.ReflowComment(res, this.GetSecondWhiteSpaceDefaultNull(ast));
         res.Append("else");
         _else.AppendCodeString(res, ast, format);
     }
 }
示例#8
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("while");
     _test.AppendCodeString(res, ast, format);
     _body.AppendCodeString(res, ast, format);
     if (_else != null)
     {
         format.ReflowComment(res, this.GetSecondWhiteSpaceDefaultNull(ast));
         res.Append("else");
         _else.AppendCodeString(res, ast, format);
     }
 }
示例#9
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("raise");
     if (ExceptType != null)
     {
         ExceptType.AppendCodeString(res, ast, format);
     }
     if (this.IsAltForm(ast))
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append("from");
         Cause.AppendCodeString(res, ast, format);
     }
     else
     {
         if (_value != null)
         {
             res.Append(this.GetSecondWhiteSpace(ast));
             res.Append(',');
             _value.AppendCodeString(res, ast, format);
             if (_traceback != null)
             {
                 res.Append(this.GetThirdWhiteSpace(ast));
                 res.Append(',');
                 _traceback.AppendCodeString(res, ast, format);
             }
         }
     }
 }
示例#10
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            if (Items.Count == 0 && format.SpacesWithinEmptyListExpression != null)
            {
                res.Append(this.GetPreceedingWhiteSpace(ast));
                res.Append('[');
                if (String.IsNullOrWhiteSpace(this.GetSecondWhiteSpace(ast)))
                {
                    res.Append(format.SpacesWithinEmptyListExpression.Value ? " " : "");
                }
                else
                {
                    format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                }
                res.Append(']');
            }
            else
            {
                string delimWs =
                    format.SpacesWithinListExpression != null ?
                    format.SpacesWithinListExpression.Value ? " " : "" : null;

                AppendItems(res, ast, format, "[", this.IsMissingCloseGrouping(ast) ? "" : "]", this, Items, delimWs);
            }
        }
示例#11
0
        internal static void AppendItems(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Node node, int itemCount, Action <int, StringBuilder> appendItem, bool?trailingWhiteSpace = null)
        {
            if (!String.IsNullOrEmpty(start))
            {
                format.ReflowComment(res, node.GetPreceedingWhiteSpace(ast));
                res.Append(start);
            }
            var listWhiteSpace = node.GetListWhiteSpace(ast);

            for (int i = 0; i < itemCount; i++)
            {
                if (i > 0)
                {
                    format.Append(res, format.SpaceBeforeComma, " ", "", listWhiteSpace?[i - 1]);
                    res.Append(",");
                }

                appendItem(i, res);
            }

            if (listWhiteSpace != null && listWhiteSpace.Length == itemCount && itemCount != 0)
            {
                // trailing comma
                format.Append(res, format.SpaceBeforeComma, " ", "", listWhiteSpace[listWhiteSpace.Length - 1]);
                res.Append(",");
            }

            if (!String.IsNullOrEmpty(end))
            {
                format.Append(res, trailingWhiteSpace, " ", "", node.GetSecondWhiteSpaceDefaultNull(ast));
                res.Append(end);
            }
        }
示例#12
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("lambda");
            var commaWhiteSpace = this.GetListWhiteSpace(ast);

            _function.ParamsToString(res, ast, commaWhiteSpace, format);
            string namedOnlyText = this.GetExtraVerbatimText(ast);

            if (namedOnlyText != null)
            {
                res.Append(namedOnlyText);
            }
            if (!this.IsIncompleteNode(ast))
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(":");
                if (_function.Body is ReturnStatement)
                {
                    ((ReturnStatement)_function.Body).Expression.AppendCodeString(res, ast, format);
                }
                else
                {
                    Debug.Assert(_function.Body is ExpressionStatement);
                    ((ExpressionStatement)_function.Body).Expression.AppendCodeString(res, ast, format);
                }
            }
        }
示例#13
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("except");
            if (_test != null)
            {
                _test.AppendCodeString(res, ast, format);
                if (_target != null)
                {
                    res.Append(this.GetSecondWhiteSpace(ast));
                    if (this.IsAltForm(ast))
                    {
                        res.Append("as");
                    }
                    else
                    {
                        res.Append(",");
                    }

                    _target.AppendCodeString(res, ast, format);
                }
            }

            _body.AppendCodeString(res, ast, format);
        }
示例#14
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            res.Append("exec");

            if (_codeTuple != null)
            {
                _codeTuple.AppendCodeString(res, ast, format);
            }
            else
            {
                _code.AppendCodeString(res, ast, format);
            }

            if (_globals != null)
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append("in");
                _globals.AppendCodeString(res, ast, format);
                if (_locals != null)
                {
                    res.Append(this.GetThirdWhiteSpace(ast));
                    res.Append(',');
                    _locals.AppendCodeString(res, ast, format);
                }
            }
        }
示例#15
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("with");
            var itemWhiteSpace = this.GetListWhiteSpace(ast);
            int whiteSpaceIndex = 0;
            for (int i = 0; i < _items.Length; i++) {
                var item = _items[i];
                if (i != 0) {
                    if (itemWhiteSpace != null) {
                        res.Append(itemWhiteSpace[whiteSpaceIndex++]);
                    }
                    res.Append(',');
                }

                item.ContextManager.AppendCodeString(res, ast, format);
                if (item.Variable != null) {
                    if (itemWhiteSpace != null) {
                        res.Append(itemWhiteSpace[whiteSpaceIndex++]);
                    } else {
                        res.Append(' ');
                    }
                    res.Append("as");
                    item.Variable.AppendCodeString(res, ast, format);
                }
            }

            _body.AppendCodeString(res, ast, format);
        }
示例#16
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpaceDefaultNull(ast));
     if (format.UseVerbatimImage) {
         res.Append(this.GetVerbatimImage(ast) ?? _name);
     } else {
         res.Append(_name);
     }
 }
示例#17
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     var verbatimPieces = this.GetVerbatimNames(ast);
     var verbatimComments = this.GetListWhiteSpace(ast);
     if (verbatimPieces != null) {
         // string+ / bytes+, such as "abc" "abc", which can spawn multiple lines, and 
         // have comments in between the peices.
         for (int i = 0; i < verbatimPieces.Length; i++) {
             if (verbatimComments != null && i < verbatimComments.Length) {
                 format.ReflowComment(res, verbatimComments[i]);
             }
             res.Append(verbatimPieces[i]);
         }
     } else {
         format.ReflowComment(res, this.GetProceedingWhiteSpaceDefaultNull(ast));
         res.Append(this.GetExtraVerbatimText(ast) ?? GetConstantRepr(ast.LanguageVersion));
     }
 }
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var asNameWhiteSpace = this.GetNamesWhiteSpace(ast);

            if (format.ReplaceMultipleImportsWithMultipleStatements)
            {
                var proceeding           = this.GetPreceedingWhiteSpace(ast);
                var additionalProceeding = format.GetNextLineProceedingText(proceeding);

                for (int i = 0, asIndex = 0; i < _names.Length; i++)
                {
                    if (i == 0)
                    {
                        format.ReflowComment(res, proceeding);
                    }
                    else
                    {
                        res.Append(additionalProceeding);
                    }
                    res.Append("import");

                    _names[i].AppendCodeString(res, ast, format);
                    AppendAs(res, ast, format, asNameWhiteSpace, i, ref asIndex);
                }
                return;
            }
            else
            {
                format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
                res.Append("import");

                var itemWhiteSpace = this.GetListWhiteSpace(ast);
                for (int i = 0, asIndex = 0; i < _names.Length; i++)
                {
                    if (i > 0 && itemWhiteSpace != null)
                    {
                        res.Append(itemWhiteSpace[i - 1]);
                        res.Append(',');
                    }

                    _names[i].AppendCodeString(res, ast, format);
                    AppendAs(res, ast, format, asNameWhiteSpace, i, ref asIndex);
                }
            }
        }
示例#19
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append('`');
     _expression.AppendCodeString(res, ast, format);
     if (!this.IsMissingCloseGrouping(ast)) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append('`');
     }
 }
示例#20
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("for");
     _left.AppendCodeString(res, ast, format);
     if (!this.IsIncompleteNode(ast))
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append("in");
         _list.AppendCodeString(res, ast, format);
         _body.AppendCodeString(res, ast, format);   // colon is handled by suite statements...
         if (_else != null)
         {
             format.ReflowComment(res, this.GetThirdWhiteSpace(ast));
             res.Append("else");
             _else.AppendCodeString(res, ast, format);
         }
     }
 }
示例#21
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     var decorateWhiteSpace = this.GetNamesWhiteSpace(ast);
     if (Decorators != null) {
         for (int i = 0, curWhiteSpace = 0; i < Decorators.Count; i++) {
             if (decorateWhiteSpace != null) {
                 format.ReflowComment(res, decorateWhiteSpace[curWhiteSpace++]);
             }
             res.Append('@');
             if (Decorators[i] != null) {
                 Decorators[i].AppendCodeString(res, ast, format);
                 if (decorateWhiteSpace != null) {
                     format.ReflowComment(res, decorateWhiteSpace[curWhiteSpace++]);
                 } else {
                     res.Append(Environment.NewLine);
                 }
             }
         }
     }
 }
示例#22
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("assert");
     _test.AppendCodeString(res, ast, format);
     if (_message != null) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append(',');
         _message.AppendCodeString(res, ast, format);
     }
 }
示例#23
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append('`');
     _expression.AppendCodeString(res, ast, format);
     if (!this.IsMissingCloseGrouping(ast))
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append('`');
     }
 }
示例#24
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetPreceedingWhiteSpaceDefaultNull(ast));
     if (format.UseVerbatimImage)
     {
         res.Append(this.GetVerbatimImage(ast) ?? _name);
     }
     else
     {
         res.Append(_name);
     }
 }
示例#25
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            var itemWhiteSpace = this.GetListWhiteSpace(ast);
            for (int i = 0; i < _tests.Length; i++) {
                if (itemWhiteSpace != null) {
                    format.ReflowComment(res, itemWhiteSpace[i]);
                }

                if (i == 0) {
                    res.Append("if");
                } else {
                    res.Append("elif");
                }
                _tests[i].AppendCodeString(res, ast, format);
            }

            if (_else != null) {
                format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                res.Append("else");
                _else.AppendCodeString(res, ast, format);
            }
        }
示例#26
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("assert");
     _test.AppendCodeString(res, ast, format);
     if (_message != null)
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append(',');
         _message.AppendCodeString(res, ast, format);
     }
 }
示例#27
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("await");
     if (!this.IsAltForm(ast)) {
         _expression.AppendCodeString(res, ast, format);
         var itemWhiteSpace = this.GetListWhiteSpace(ast);
         if (itemWhiteSpace != null) {
             res.Append(",");
             res.Append(itemWhiteSpace[0]);
         }
     }
 }
示例#28
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            if (this.IsAltForm(ast)) {
                ListExpression.AppendItems(res, ast, format, "", "", this, Items);
            } else {
                if (Items.Count == 0 && 
                    format.SpaceWithinEmptyTupleExpression != null) {
                    format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                    res.Append('(');
                    if (String.IsNullOrWhiteSpace(this.GetSecondWhiteSpace(ast))) {
                        res.Append(format.SpaceWithinEmptyTupleExpression.Value ? " " : "");
                    } else {
                        format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                    }
                    res.Append(')');
                } else {
                    string delimWs =
                     format.SpacesWithinParenthesisedTupleExpression != null ?
                     format.SpacesWithinParenthesisedTupleExpression.Value ? " " : "" : null;

                    ListExpression.AppendItems(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? "" : ")", this, Items, delimWs);
                } 
            }
        }
示例#29
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("print");
     if (_dest != null) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append(">>");
         _dest.AppendCodeString(res, ast, format);
         if (_expressions.Length > 0) {
             res.Append(this.GetThirdWhiteSpace(ast));
             res.Append(',');
         }
     }
     ListExpression.AppendItems(res, ast, format, "", "", this, Expressions);
 }
示例#30
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("return");
            if (_expression != null) {
                int len = res.Length;

                _expression.AppendCodeString(res, ast, format);
                if (this.IsAltForm(ast)) {
                    // remove the leading white space and insert a single space
                    res.Remove(len, _expression.GetLeadingWhiteSpace(ast).Length);
                    res.Insert(len, ' ');
                }
            }
        }
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
     res.Append("yield");
     if (!this.IsAltForm(ast))
     {
         _expression.AppendCodeString(res, ast, format);
         var itemWhiteSpace = this.GetListWhiteSpace(ast);
         if (itemWhiteSpace != null)
         {
             res.Append(",");
             res.Append(itemWhiteSpace[0]);
         }
     }
 }
示例#32
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("exec");
     _code.AppendCodeString(res, ast, format);
     if (_globals != null) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append("in");
         _globals.AppendCodeString(res, ast, format);
         if (_locals != null) {
             res.Append(this.GetThirdWhiteSpace(ast));
             res.Append(',');
             _locals.AppendCodeString(res, ast, format);
         }
     }
 }
示例#33
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("for");
     _left.AppendCodeString(res, ast, format);
     if (!this.IsIncompleteNode(ast)) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append("in");
         _list.AppendCodeString(res, ast, format);
         _body.AppendCodeString(res, ast, format);   // colon is handled by suite statements...
         if (_else != null) {
             format.ReflowComment(res, this.GetThirdWhiteSpace(ast));
             res.Append("else");
             _else.AppendCodeString(res, ast, format);
         }
     }
 }
示例#34
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
     res.Append("print");
     if (_dest != null)
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append(">>");
         _dest.AppendCodeString(res, ast, format);
         if (_expressions.Length > 0)
         {
             res.Append(this.GetThirdWhiteSpace(ast));
             res.Append(',');
         }
     }
     ListExpression.AppendItems(res, ast, format, "", "", this, Expressions);
 }
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
     res.Append("print");
     if (Destination != null)
     {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append(">>");
         Destination.AppendCodeString(res, ast, format);
         if (Expressions.Count > 0)
         {
             res.Append(this.GetThirdWhiteSpace(ast));
             res.Append(',');
         }
     }
     ListExpression.AppendItems(res, ast, format, string.Empty, string.Empty, this, Expressions);
 }
示例#36
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("return");
            if (_expression != null)
            {
                int len = res.Length;

                _expression.AppendCodeString(res, ast, format);
                if (this.IsAltForm(ast))
                {
                    // remove the leading white space and insert a single space
                    res.Remove(len, _expression.GetLeadingWhiteSpace(ast).Length);
                    res.Insert(len, ' ');
                }
            }
        }
示例#37
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            res.Append("lambda");
            var commaWhiteSpace = this.GetListWhiteSpace(ast);

            if (_function.ParametersInternal.Length > 0)
            {
                var paramStr = new StringBuilder();
                _function.ParamsToString(paramStr, ast, commaWhiteSpace, format);
                if (paramStr.Length > 0 && !char.IsWhiteSpace(paramStr[0]) && !(_function.ParametersInternal[0] is ErrorParameter))
                {
                    res.Append(' ');
                }
                res.Append(paramStr.ToString());
            }
            string namedOnlyText = this.GetExtraVerbatimText(ast);

            if (namedOnlyText != null)
            {
                res.Append(namedOnlyText);
            }
            format.Append(res, format.SpaceBeforeLambdaColon, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast) ?? "");
            if (!this.IsIncompleteNode(ast))
            {
                res.Append(":");
                string afterColon = null;
                if (format.SpaceAfterLambdaColon == true)
                {
                    afterColon = " ";
                }
                else if (format.SpaceAfterLambdaColon == false)
                {
                    afterColon = "";
                }
                if (_function.Body is ReturnStatement)
                {
                    ((ReturnStatement)_function.Body).Expression.AppendCodeString(res, ast, format, afterColon);
                }
                else
                {
                    Debug.Assert(_function.Body is ExpressionStatement);
                    ((ExpressionStatement)_function.Body).Expression.AppendCodeString(res, ast, format, afterColon);
                }
            }
        }
示例#38
0
        internal void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Expression item) {
            if (!String.IsNullOrEmpty(start)) {
                format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                res.Append(start);
            }

            item.AppendCodeString(res, ast, format);

            for (int i = 0; i < Iterators.Count; i++) {
                Iterators[i].AppendCodeString(res, ast, format);
            }

            if (!String.IsNullOrEmpty(end)) {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(end);
            }
        }
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            if (IsAsync)
            {
                res.Append("async");
                res.Append(this.GetSecondWhiteSpace(ast));
            }
            res.Append("with");
            var itemWhiteSpace  = this.GetListWhiteSpace(ast);
            var whiteSpaceIndex = 0;

            for (var i = 0; i < _items.Length; i++)
            {
                var item = _items[i];
                if (i != 0)
                {
                    if (itemWhiteSpace != null)
                    {
                        res.Append(itemWhiteSpace[whiteSpaceIndex++]);
                    }
                    res.Append(',');
                }

                item.ContextManager.AppendCodeString(res, ast, format);
                if (item.Variable != null)
                {
                    if (itemWhiteSpace != null)
                    {
                        res.Append(itemWhiteSpace[whiteSpaceIndex++]);
                    }
                    else
                    {
                        res.Append(' ');
                    }
                    res.Append("as");
                    item.Variable.AppendCodeString(res, ast, format);
                }
            }

            Body.AppendCodeString(res, ast, format);
        }
示例#40
0
        internal override void AppendCodeStringStmt(StringBuilder res, JAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("return");
            if (_expression != null) {
                int len = res.Length;
                _expression.AppendCodeString(res, ast, format);
                if (this.IsAltForm(ast)) {
                    for (int i = len; i < res.Length; i++) {
                        if (!Char.IsWhiteSpace(res[i])) {
                            res.Remove(len, i - len);
                            break;
                        }
                    }

                    // ensure a space between the return and the expression
                    res.Insert(len, ' ');
                }
            }
        }
示例#41
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("lambda");
            var commaWhiteSpace = this.GetListWhiteSpace(ast);

            _function.ParamsToString(res, ast, commaWhiteSpace, format);
            string namedOnlyText = this.GetExtraVerbatimText(ast);
            if (namedOnlyText != null) {
                res.Append(namedOnlyText);
            }
            if (!this.IsIncompleteNode(ast)) {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(":");
                if (_function.Body is ReturnStatement) {
                    ((ReturnStatement)_function.Body).Expression.AppendCodeString(res, ast, format);
                } else {
                    Debug.Assert(_function.Body is ExpressionStatement);
                    ((ExpressionStatement)_function.Body).Expression.AppendCodeString(res, ast, format);
                }
            }
        }
示例#42
0
        internal void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Expression item)
        {
            if (!String.IsNullOrEmpty(start))
            {
                format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                res.Append(start);
            }

            item.AppendCodeString(res, ast, format);

            for (int i = 0; i < Iterators.Count; i++)
            {
                Iterators[i].AppendCodeString(res, ast, format);
            }

            if (!String.IsNullOrEmpty(end))
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(end);
            }
        }
示例#43
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append('(');
            
            _expression.AppendCodeString(
                res, 
                ast, 
                format,
                format.SpacesWithinParenthesisExpression != null ? format.SpacesWithinParenthesisExpression.Value ? " " : "" : null
            );
            if (!this.IsMissingCloseGrouping(ast)) {
                format.Append(
                    res,
                    format.SpacesWithinParenthesisExpression,
                    " ",
                    "",
                    this.GetSecondWhiteSpace(ast)
                );

                res.Append(')');
            }
        }
示例#44
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     if (this.IsAltForm(ast))
     {
         ListExpression.AppendItems(res, ast, format, "", "", this, Items);
     }
     else
     {
         if (Items.Count == 0 &&
             format.SpaceWithinEmptyTupleExpression != null)
         {
             format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
             res.Append('(');
             format.Append(res, format.SpaceWithinEmptyTupleExpression, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast));
             res.Append(')');
         }
         else
         {
             ListExpression.AppendItems(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? "" : ")", this, Items, format.SpacesWithinParenthesisedTupleExpression);
         }
     }
 }
示例#45
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("raise");
     if (ExceptType != null) {
         ExceptType.AppendCodeString(res, ast, format);
     }
     if (this.IsAltForm(ast)) {
         res.Append(this.GetSecondWhiteSpace(ast));
         res.Append("from");
         Cause.AppendCodeString(res, ast, format);
     } else {
         if (_value != null) {
             res.Append(this.GetSecondWhiteSpace(ast));
             res.Append(',');
             _value.AppendCodeString(res, ast, format);
             if (_traceback != null) {
                 res.Append(this.GetThirdWhiteSpace(ast));
                 res.Append(',');
                 _traceback.AppendCodeString(res, ast, format);
             }
         }
     }
 }
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            res.Append('(');

            _expression.AppendCodeString(
                res,
                ast,
                format,
                format.SpacesWithinParenthesisExpression != null ? format.SpacesWithinParenthesisExpression.Value ? " " : string.Empty : null
                );
            if (!this.IsMissingCloseGrouping(ast))
            {
                format.Append(
                    res,
                    format.SpacesWithinParenthesisExpression,
                    " ",
                    string.Empty,
                    this.GetSecondWhiteSpace(ast)
                    );

                res.Append(')');
            }
        }
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
            res.Append("from");
            Root.AppendCodeString(res, ast, format);

            if (!this.IsIncompleteNode(ast))
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append("import");
                if (!this.IsAltForm(ast))
                {
                    res.Append(this.GetThirdWhiteSpace(ast));
                    res.Append('(');
                }

                var asNameWhiteSpace = this.GetNamesWhiteSpace(ast);
                int asIndex          = 0;
                for (int i = 0; i < Names.Count; i++)
                {
                    if (i > 0)
                    {
                        if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                        {
                            res.Append(asNameWhiteSpace[asIndex++]);
                        }
                        res.Append(',');
                    }

                    if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                    {
                        res.Append(asNameWhiteSpace[asIndex++]);
                    }
                    else
                    {
                        res.Append(' ');
                    }

                    Names[i].AppendCodeString(res, ast, format);
                    if (AsNames != null && AsNames[i] != null)
                    {
                        if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                        {
                            res.Append(asNameWhiteSpace[asIndex++]);
                        }
                        res.Append("as");
                        if (AsNames[i].Name.Length != 0)
                        {
                            if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                            {
                                res.Append(asNameWhiteSpace[asIndex++]);
                            }
                            AsNames[i].AppendCodeString(res, ast, format);
                        }
                        else
                        {
                            asIndex++;
                        }
                    }
                }

                if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                {
                    // trailing comma
                    res.Append(asNameWhiteSpace[asNameWhiteSpace.Length - 1]);
                    res.Append(",");
                }

                if (!this.IsAltForm(ast) && !this.IsMissingCloseGrouping(ast))
                {
                    res.Append(this.GetFourthWhiteSpace(ast));
                    res.Append(')');
                }
            }
        }
示例#48
0
 public static void AppendTrailingNewLine(this Statement node, StringBuilder res, JAst ast, CodeFormattingOptions options)
 {
     if (options == null) {
         AppendTrailingNewLine(node, res, ast);
     } else {
         var trailingNewLine = node.GetTrailingNewLine(ast);
         if (trailingNewLine != null) {
             options.ReflowComment(res, trailingNewLine);
         }
     }
 }
示例#49
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            var asNameWhiteSpace = this.GetNamesWhiteSpace(ast);
            if (format.ReplaceMultipleImportsWithMultipleStatements) {
                var proceeding = this.GetProceedingWhiteSpace(ast);
                var additionalProceeding = format.GetNextLineProceedingText(proceeding);
                
                for (int i = 0, asIndex = 0; i < _names.Length; i++) {
                    if (i == 0) {
                        format.ReflowComment(res, proceeding) ;
                    } else {
                        res.Append(additionalProceeding);
                    }
                    res.Append("import");

                    _names[i].AppendCodeString(res, ast, format);
                    AppendAs(res, ast, format, asNameWhiteSpace, i, ref asIndex);
                }
                return;
            } else {
                format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
                res.Append("import");

                var itemWhiteSpace = this.GetListWhiteSpace(ast);
                for (int i = 0, asIndex = 0; i < _names.Length; i++) {
                    if (i > 0 && itemWhiteSpace != null) {
                        res.Append(itemWhiteSpace[i - 1]);
                        res.Append(',');
                    }

                    _names[i].AppendCodeString(res, ast, format);
                    AppendAs(res, ast, format, asNameWhiteSpace, i, ref asIndex);
                }
            }
        }
示例#50
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var decorateWhiteSpace = this.GetNamesWhiteSpace(ast);

            if (Decorators != null)
            {
                Decorators.AppendCodeString(res, ast, format);
            }
            format.ReflowComment(res, this.GetProceedingWhiteSpaceDefaultNull(ast));
            if (IsCoroutine)
            {
                res.Append("async");
                res.Append(NodeAttributes.GetWhiteSpace(this, ast, WhitespaceAfterAsync));
            }
            res.Append("def");
            var name = this.GetVerbatimImage(ast) ?? Name;

            if (!String.IsNullOrEmpty(name))
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(name);
                if (!this.IsIncompleteNode(ast))
                {
                    format.Append(
                        res,
                        format.SpaceBeforeFunctionDeclarationParen,
                        " ",
                        "",
                        this.GetThirdWhiteSpaceDefaultNull(ast)
                        );

                    res.Append('(');
                    if (Parameters.Count != 0)
                    {
                        var commaWhiteSpace = this.GetListWhiteSpace(ast);
                        ParamsToString(res,
                                       ast,
                                       commaWhiteSpace,
                                       format,
                                       format.SpaceWithinFunctionDeclarationParens != null ?
                                       format.SpaceWithinFunctionDeclarationParens.Value ? " " : "" :
                                       null
                                       );
                    }

                    string namedOnly = this.GetExtraVerbatimText(ast);
                    if (namedOnly != null)
                    {
                        res.Append(namedOnly);
                    }

                    if (!this.IsMissingCloseGrouping(ast))
                    {
                        format.Append(
                            res,
                            Parameters.Count != 0 ?
                            format.SpaceWithinFunctionDeclarationParens :
                            format.SpaceWithinEmptyParameterList,
                            " ",
                            "",
                            this.GetFourthWhiteSpaceDefaultNull(ast)
                            );

                        res.Append(')');
                    }
                    if (ReturnAnnotation != null)
                    {
                        format.Append(
                            res,
                            format.SpaceAroundAnnotationArrow,
                            " ",
                            "",
                            this.GetFifthWhiteSpace(ast)
                            );
                        res.Append("->");
                        _returnAnnotation.AppendCodeString(
                            res,
                            ast,
                            format,
                            format.SpaceAroundAnnotationArrow != null ?
                            format.SpaceAroundAnnotationArrow.Value ? " " : "" :
                            null
                            );
                    }
                    if (Body != null)
                    {
                        Body.AppendCodeString(res, ast, format);
                    }
                }
            }
        }
示例#51
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append(_op.ToCodeString());
     _expression.AppendCodeString(res, ast, format);
 }
示例#52
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast));
     res.Append("pass");
 }
示例#53
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            if (Decorators != null) {
                Decorators.AppendCodeString(res, ast, format);
            }

            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("class");
            res.Append(this.GetSecondWhiteSpace(ast));
            res.Append(this.GetVerbatimImage(ast) ?? Name);

            if (!this.IsAltForm(ast)) {
                format.Append(
                    res,
                    format.SpaceBeforeClassDeclarationParen,
                    " ",
                    "",
                    this.GetThirdWhiteSpace(ast)
                );

                res.Append('(');
            }

            if (Bases.Count != 0) {
                ListExpression.AppendItems(
                    res,
                    ast,
                    format,
                    "",
                    "",
                    this,
                    this.Bases.Count,
                    (i, sb) => {
                        if(format.SpaceWithinClassDeclarationParens != null && i == 0) {
                            // need to remove any leading whitespace which was preserved for
                            // the 1st param, and then force the correct whitespace.
                            Bases[i].AppendCodeString(sb, ast, format, format.SpaceWithinClassDeclarationParens.Value ? " " : "");
                        } else {
                            Bases[i].AppendCodeString(sb, ast, format);
                        }
                    }
                );
            } else if (!this.IsAltForm(ast)) {
                if (format.SpaceWithinEmptyBaseClassList != null && format.SpaceWithinEmptyBaseClassList.Value) {
                    res.Append(' ');
                }
            }
            
            if (!this.IsAltForm(ast) && !this.IsMissingCloseGrouping(ast)) {
                if (Bases.Count != 0 || 
                    format.SpaceWithinEmptyBaseClassList == null ||
                    !String.IsNullOrWhiteSpace(this.GetFourthWhiteSpace(ast))) {
                    format.Append(
                        res,
                        format.SpaceWithinClassDeclarationParens,
                        " ",
                        "",
                        this.GetFourthWhiteSpace(ast)
                    );
                }

                res.Append(')');
            }

            _body.AppendCodeString(res, ast, format);
        }
示例#54
0
        internal override void AppendCodeStringStmt(StringBuilder res, JAst ast, CodeFormattingOptions format)
        {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("from");
            Root.AppendCodeString(res, ast, format);

            if (!this.IsIncompleteNode(ast)) {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append("import");
                if (!this.IsAltForm(ast)) {
                    res.Append(this.GetThirdWhiteSpace(ast));
                    res.Append('(');
                }

                var asNameWhiteSpace = this.GetNamesWhiteSpace(ast);
                int asIndex = 0;
                for (int i = 0; i < _names.Length; i++) {
                    if (i > 0) {
                        if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) {
                            res.Append(asNameWhiteSpace[asIndex++]);
                        }
                        res.Append(',');
                    }

                    if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) {
                        res.Append(asNameWhiteSpace[asIndex++]);
                    } else {
                        res.Append(' ');
                    }

                    _names[i].AppendCodeString(res, ast, format);
                    if (AsNames != null && AsNames[i] != null) {
                        if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) {
                            res.Append(asNameWhiteSpace[asIndex++]);
                        }
                        res.Append("as");
                        if (_asNames[i].Name.Length != 0) {
                            if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) {
                                res.Append(asNameWhiteSpace[asIndex++]);
                            }
                            _asNames[i].AppendCodeString(res, ast, format);
                        } else {
                            asIndex++;
                        }
                    }
                }

                if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) {
                    // trailing comma
                    res.Append(asNameWhiteSpace[asNameWhiteSpace.Length - 1]);
                    res.Append(",");
                }

                if (!this.IsAltForm(ast) && !this.IsMissingCloseGrouping(ast)) {
                    res.Append(this.GetFourthWhiteSpace(ast));
                    res.Append(')');
                }
            }
        }
示例#55
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            var decorateWhiteSpace = this.GetNamesWhiteSpace(ast);
            if (Decorators != null) {
                Decorators.AppendCodeString(res, ast, format);
            }
            format.ReflowComment(res, this.GetProceedingWhiteSpaceDefaultNull(ast));
            if (IsCoroutine) {
                res.Append("async");
                res.Append(NodeAttributes.GetWhiteSpace(this, ast, WhitespaceAfterAsync));
            }
            res.Append("def");
            var name = this.GetVerbatimImage(ast) ?? Name;
            if (!String.IsNullOrEmpty(name)) {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(name);
                if (!this.IsIncompleteNode(ast)) {
                    format.Append(
                        res, 
                        format.SpaceBeforeFunctionDeclarationParen, 
                        " ", 
                        "", 
                        this.GetThirdWhiteSpaceDefaultNull(ast)
                    );

                    res.Append('(');
                    if (Parameters.Count != 0) {
                        var commaWhiteSpace = this.GetListWhiteSpace(ast);
                        ParamsToString(res,
                            ast,
                            commaWhiteSpace,
                            format,
                            format.SpaceWithinFunctionDeclarationParens != null ?
                                format.SpaceWithinFunctionDeclarationParens.Value ? " " : "" :
                                null
                        );
                    }

                    string namedOnly = this.GetExtraVerbatimText(ast);
                    if (namedOnly != null) {
                        res.Append(namedOnly);
                    }

                    if (!this.IsMissingCloseGrouping(ast)) {                        
                        format.Append(
                            res,
                            Parameters.Count != 0 ? 
                                format.SpaceWithinFunctionDeclarationParens :
                                format.SpaceWithinEmptyParameterList,
                            " ",
                            "",
                            this.GetFourthWhiteSpaceDefaultNull(ast)
                        ); 
                        
                        res.Append(')');
                    }
                    if (ReturnAnnotation != null) {
                        format.Append(
                            res,
                            format.SpaceAroundAnnotationArrow,
                            " ",
                            "",
                            this.GetFifthWhiteSpace(ast)
                        ); 
                        res.Append("->");
                        _returnAnnotation.AppendCodeString(
                            res, 
                            ast, 
                            format,
                            format.SpaceAroundAnnotationArrow != null ?
                                format.SpaceAroundAnnotationArrow.Value ? " " : "" :
                                null
                        );
                    }
                    if (Body != null) {
                        Body.AppendCodeString(res, ast, format);
                    }
                }
            }
        }
示例#56
0
        internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("except");
            if (_test != null) {
                _test.AppendCodeString(res, ast, format);
                if (_target != null) {
                    res.Append(this.GetSecondWhiteSpace(ast));
                    if (this.IsAltForm(ast)) {
                        res.Append("as");
                    } else {
                        res.Append(",");
                    }

                    _target.AppendCodeString(res, ast, format);
                }
            }

            _body.AppendCodeString(res, ast, format);
        }
示例#57
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
     format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
     res.Append("break");            
 }
示例#58
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("try");
            _body.AppendCodeString(res, ast, format);

            if (_handlers != null) {
                for (int i = 0; i < _handlers.Length; i++) {
                    _handlers[i].AppendCodeString(res, ast, format);
                }
            }

            if (_else != null) {
                format.ReflowComment(res, this.GetSecondWhiteSpace(ast));
                res.Append("else");
                _else.AppendCodeString(res, ast, format);
            }

            if (_finally != null) {
                format.ReflowComment(res, this.GetThirdWhiteSpace(ast));
                res.Append("finally");
                _finally.AppendCodeString(res, ast, format);
            }
        }