Пример #1
0
        private static string FormatInternal(string code)
        {
            var cSharpParser = new CSharpParser();
            var expr         = cSharpParser.ParseExpression(code);

            if (cSharpParser.HasErrors)
            {
                throw new ArgumentException(string.Join(Environment.NewLine, cSharpParser.Errors.Select(e => e.ErrorType + " " + e.Message + " " + e.Region)));
            }

            // Wrap expression in parenthesized expression, this is necessary because the transformations
            // can't replace the root node of the syntax tree
            expr = new ParenthesizedExpression(expr);
            // Apply transformations
            new IntroduceQueryExpressions().Run(expr);
            new CombineQueryExpressions().Run(expr);
            new IntroduceParenthesisForNestedQueries().Run(expr);

            new RemoveQueryContinuation().Run(expr);

            // Unwrap expression
            expr = ((ParenthesizedExpression)expr).Expression;

            var format = expr.GetText(FormattingOptionsFactory.CreateAllman());

            if (format.Substring(0, 3) == "\r\n\t")
            {
                format = format.Remove(0, 3);
            }
            format = format.Replace("\r\n\t", "\n");
            return(format);
        }
Пример #2
0
        public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
        {
            var lp          = parenthesizedExpression.LParToken;
            var expr        = parenthesizedExpression.Expression;
            int extraSpaces = 0;

            if (lp.StartLocation.Line == expr.StartLocation.Line)
            {
                ForceSpacesAfter(lp, policy.SpacesWithinParentheses);
            }
            else
            {
                extraSpaces           += options.IndentSize;
                curIndent.ExtraSpaces += extraSpaces;
                FixIndentation(expr);
            }

            base.VisitParenthesizedExpression(parenthesizedExpression);

            var rp = parenthesizedExpression.RParToken;

            curIndent.ExtraSpaces -= extraSpaces;
            if (rp.StartLocation.Line == expr.EndLocation.Line)
            {
                ForceSpacesBefore(rp, policy.SpacesWithinParentheses);
            }
            else
            {
                FixIndentation(rp);
            }
        }
            bool IsSingleRangeVariable(Expression expr)
            {
                if (currentTransparentType.Count > 1)
                {
                    return(false);
                }
                var unpacked = ParenthesizedExpression.UnpackParenthesizedExpression(expr);

                return(unpacked is IdentifierExpression && ((IdentifierExpression)unpacked).Identifier == currentTransparentType[0].Item1.Name);
            }
Пример #4
0
        S IAstVisitor <T, S> .VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data)
        {
            var handler = ParenthesizedExpressionVisited;

            if (handler != null)
            {
                handler(parenthesizedExpression, data);
            }
            return(VisitChildren(parenthesizedExpression, data));
        }
Пример #5
0
            private static AstNode IntroduceParenthesis(AstNode node)
            {
                for (AstNode child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    child = IntroduceParenthesis(child);
                }

                if (node is QueryExpression && node.Parent is QueryFromClause)
                {
                    var parenthesizedExpression = new ParenthesizedExpression();
                    node.ReplaceWith(parenthesizedExpression);
                    parenthesizedExpression.Expression = (Expression)node;
                }

                return(node);
            }
Пример #6
0
 public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     ForceSpacesAfter(parenthesizedExpression.LParToken, policy.SpacesWithinParentheses);
     ForceSpacesBefore(parenthesizedExpression.RParToken, policy.SpacesWithinParentheses);
     base.VisitParenthesizedExpression(parenthesizedExpression);
 }
Пример #7
0
 void IAstVisitor.VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     Visit(EnterParenthesizedExpression, LeaveParenthesizedExpression, parenthesizedExpression);
 }
Пример #8
0
 public virtual S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data)
 {
     return(VisitChildren(parenthesizedExpression, data));
 }
Пример #9
0
 public override ConstantExpression VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
 {
     return(parenthesizedExpression.Expression.AcceptVisitor(this, data));
 }
 public virtual S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data)
 {
     throw new NotImplementedException();
 }