Beispiel #1
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var namesWhiteSpace = this.GetNamesWhiteSpace(ast);

            if (namesWhiteSpace != null)
            {
                ListExpression.AppendItems(res, ast, format, "global", "", this, Names.Count, (i, sb) => {
                    sb.Append(namesWhiteSpace[i]);
                    Names[i].AppendCodeString(res, ast, format);
                });
            }
            else
            {
                ListExpression.AppendItems(res, ast, format, "global", "", this, Names.Count, (i, sb) => Names[i].AppendCodeString(sb, ast, format));
            }
        }
Beispiel #2
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);
 }
Beispiel #3
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);
         }
     }
 }
Beispiel #4
0
 public override void PostWalk(ListExpression node)
 {
     _ops.Add(new EndListOp());
     base.PostWalk(node);
 }
Beispiel #5
0
 public override bool Walk(ListExpression node)
 {
     _ops.Add(new StartListOp());
     return(base.Walk(node));
 }
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     ListExpression.AppendItems(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", this, Items);
 }
Beispiel #7
0
 internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     ListExpression.AppendItems(res, ast, format, "del", "", this, Expressions);
 }
Beispiel #8
0
 public override bool Walk(ListExpression node)
 {
     return(true);
 }
Beispiel #9
0
 public override bool Walk(ListExpression node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
Beispiel #10
0
 public override void PostWalk(ListExpression node)
 {
     _ops.Add(new EndUnionOp(ordered: true));
     base.PostWalk(node);
 }
        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);
        }