Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }