internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { Target.AppendCodeString(res, ast, format); format.Append( res, format.SpaceBeforeIndexBracket, " ", "", this.GetPreceedingWhiteSpace(ast) ); res.Append('['); _index.AppendCodeString( res, ast, format, format.SpaceWithinIndexBrackets != null ? format.SpaceWithinIndexBrackets.Value ? " " : "" : null ); if (!this.IsMissingCloseGrouping(ast)) { format.Append( res, format.SpaceWithinIndexBrackets, " ", "", this.GetSecondWhiteSpace(ast) ); res.Append(']'); } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (_sliceStart != null) { _sliceStart.AppendCodeString(res, ast, format); } if (!this.IsIncompleteNode(ast)) { res.Append(this.GetProceedingWhiteSpace(ast)); res.Append(':'); if (_sliceStop != null) { _sliceStop.AppendCodeString(res, ast, format); } if (_stepProvided) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append(':'); if (_sliceStep != null) { _sliceStep.AppendCodeString(res, ast, format); } } } }
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); } } }
internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _left.AppendCodeString(res, ast, format); res.Append(this.GetProceedingWhiteSpace(ast)); res.Append(_op.ToCodeString()); res.Append('='); _right.AppendCodeString(res, ast, format); }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (_preceeding != null) { _preceeding.AppendCodeString(res, ast, format); } res.Append(_verbatimImage ?? "<error>"); }
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('`'); } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _target.AppendCodeString(res, ast, format); res.Append(this.GetProceedingWhiteSpaceDefaultNull(ast)); res.Append('.'); if (!this.IsIncompleteNode(ast)) { res.Append(this.GetSecondWhiteSpaceDefaultNull(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { res.Append(this.GetProceedingWhiteSpace(ast)); res.Append("for"); _lhs.AppendCodeString(res, ast, format); if (!this.IsIncompleteNode(ast)) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append("in"); _list.AppendCodeString(res, ast, format); } }
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); } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (_name != null) { if (Name == "*" || Name == "**") { _name.AppendCodeString(res, ast, format); _expression.AppendCodeString(res, ast, format); } else { // keyword arg _name.AppendCodeString(res, ast, format); res.Append(this.GetPreceedingWhiteSpace(ast)); res.Append('='); _expression.AppendCodeString(res, ast, format); } } else { _expression.AppendCodeString(res, ast, format); } }
internal static void BinaryToCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, Expression node, Expression left, Expression right, string op1, string op2 = null) { left.AppendCodeString(res, ast, format); format.Append( res, format.SpacesAroundBinaryOperators, " ", Char.IsLetter(op1[0]) ? " " : "", // spaces required for is not, not in, etc... node.GetProceedingWhiteSpace(ast) ); if (op2 == null) { res.Append(op1); right.AppendCodeString( res, ast, format, format.SpacesAroundBinaryOperators != null ? format.SpacesAroundBinaryOperators.Value ? " " : (Char.IsLetter(op1[0]) ? " " : "") : null ); } else { Debug.Assert(Char.IsLetter(op1[0])); res.Append(op1); res.Append(node.GetSecondWhiteSpace(ast)); res.Append(op2); right.AppendCodeString(res, ast, format, format.SpacesAroundBinaryOperators != null ? " " : null); // force single space if setting is on or off } }
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 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 AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _target.AppendCodeString(res, ast, format); format.Append(res, format.SpaceBeforeDot, " ", "", this.GetPreceedingWhiteSpaceDefaultNull(ast)); res.Append('.'); if (!this.IsIncompleteNode(ast)) { format.Append(res, format.SpaceAfterDot, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast)); if (format.UseVerbatimImage) { res.Append(this.GetVerbatimImage(ast) ?? _name); } else { res.Append(_name); } } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _expression.AppendCodeString(res, ast, format); if (_annotation != null) { // For now, use same formatting as around an assignment if (format.SpacesAroundAssignmentOperator == null) { res.Append(this.GetSecondWhiteSpaceDefaultNull(ast) ?? ""); } else if (format.SpacesAroundAssignmentOperator == true) { res.Append(' '); } res.Append(':'); _annotation.AppendCodeString(res, ast, format); } }
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); } } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _trueExpr.AppendCodeString(res, ast, format); res.Append(this.GetProceedingWhiteSpace(ast)); res.Append("if"); if (!ast.HasVerbatim) { res.Append(' '); } _testExpr.AppendCodeString(res, ast, format); res.Append(this.GetSecondWhiteSpace(ast)); if (!this.IsIncompleteNode(ast)) { res.Append("else"); if (!ast.HasVerbatim) { res.Append(' '); } _falseExpr.AppendCodeString(res, ast, format); } }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (_sliceStart != null) { _sliceStart.AppendCodeString(res, ast, format); } if (!this.IsIncompleteNode(ast)) { format.Append(res, format.SpaceBeforeSliceColon, " ", "", this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); res.Append(':'); if (_sliceStop != null) { string ws = null; if (format.SpaceAfterSliceColon.HasValue) { ws = ""; format.Append(res, format.SpaceAfterSliceColon, " ", "", ""); } _sliceStop.AppendCodeString(res, ast, format, ws); } if (_stepProvided) { format.Append(res, format.SpaceBeforeSliceColon, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast) ?? ""); res.Append(':'); if (_sliceStep != null) { string ws = null; if (format.SpaceAfterSliceColon.HasValue) { ws = ""; format.Append(res, format.SpaceAfterSliceColon, " ", "", ""); } _sliceStep.AppendCodeString(res, ast, format, ws); } } } }
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); }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { res.Append(this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); res.Append(new string('*', StarCount)); Expression.AppendCodeString(res, ast, format); }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _test.AppendCodeString(res, ast, format); _body.AppendCodeString(res, ast, format); }
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) { string kwOnlyText = this.GetExtraVerbatimText(ast); if (kwOnlyText != null) { if (leadingWhiteSpace != null) { res.Append(leadingWhiteSpace); res.Append(kwOnlyText.TrimStart()); leadingWhiteSpace = null; } else { res.Append(kwOnlyText); } } switch (Kind) { case ParameterKind.Dictionary: res.Append(leadingWhiteSpace ?? this.GetProceedingWhiteSpace(ast)); res.Append("**"); res.Append(this.GetSecondWhiteSpace(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); AppendAnnotation(res, ast, format); break; case ParameterKind.List: res.Append(leadingWhiteSpace ?? this.GetProceedingWhiteSpace(ast)); res.Append('*'); res.Append(this.GetSecondWhiteSpace(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); AppendAnnotation(res, ast, format); break; case ParameterKind.Normal: if (this.IsAltForm(ast)) { res.Append(leadingWhiteSpace ?? this.GetProceedingWhiteSpace(ast)); res.Append('('); res.Append(this.GetThirdWhiteSpace(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); if (!this.IsMissingCloseGrouping(ast)) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append(')'); } } else { res.Append(leadingWhiteSpace ?? this.GetProceedingWhiteSpaceDefaultNull(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); AppendAnnotation(res, ast, format); } break; case ParameterKind.KeywordOnly: res.Append(leadingWhiteSpace ?? this.GetProceedingWhiteSpace(ast)); res.Append(this.GetVerbatimImage(ast) ?? _name); AppendAnnotation(res, ast, format); break; default: throw new InvalidOperationException(); } if (_defaultValue != null) { format.Append( res, format.SpaceAroundDefaultValueEquals, " ", "", this.GetSecondWhiteSpace(ast) ); res.Append('='); if (format.SpaceAroundDefaultValueEquals != null) { _defaultValue.AppendCodeString(res, ast, format, format.SpaceAroundDefaultValueEquals.Value ? " " : ""); } else { _defaultValue.AppendCodeString(res, ast, format); } } }