예제 #1
0
        public override ScriptNode Visit(ScriptFunctionCall node)
        {
            if (_isScientific && !node.ExplicitCall)
            {
                var newNode = node.GetScientificExpression(_context);
                if (newNode != node)
                {
                    return(Visit((ScriptNode)newNode));
                }
            }

            var functionCall = (ScriptFunctionCall)base.Visit(node);

            // Make sure that we have always a parenthesis for function calls
            if (_isScientific)
            {
                if (_flags.HasFlags(ScriptFormatterFlags.ExplicitParenthesis) || functionCall.Arguments.Count > 1)
                {
                    functionCall.ExplicitCall = true;
                    functionCall.OpenParent ??= ScriptToken.OpenParen();
                    functionCall.CloseParen ??= ScriptToken.CloseParen();

                    // We remove any trailing spaces after the target cos (x) => cos(x)
                    functionCall.Target.RemoveTrailingSpace();
                    functionCall.Arguments.RemoveLeadingSpace();
                    functionCall.Arguments.MoveTrailingTriviasTo(functionCall.CloseParen, false);
                }
            }

            // Make sure that arguments are separated by a proper comma and space
            for (int i = 0; i < functionCall.Arguments.Count; i++)
            {
                var arg = functionCall.Arguments[i];

                // No need to nest expression for arguments
                arg = DeNestExpression(arg);

                if (i + 1 < functionCall.Arguments.Count)
                {
                    var lastToken = (IScriptTerminal)arg.FindLastTerminal();
                    if (_isScientific)
                    {
                        lastToken.AddCommaAfter();
                    }

                    if (_flags.HasFlags(ScriptFormatterFlags.AddSpaceBetweenOperators))
                    {
                        lastToken.AddSpaceAfter();
                    }
                }

                functionCall.Arguments[i] = arg;
            }

            return(functionCall);
        }
예제 #2
0
 public ScriptNestedExpression()
 {
     OpenParen  = ScriptToken.OpenParen();
     CloseParen = ScriptToken.CloseParen();
 }