예제 #1
0
        //private static readonly ExpressionType[] assign = new[]
        //    {
        //        ExpressionType.Assign,
        //        ExpressionType.AddAssign,
        //        ExpressionType.AddAssignChecked,
        //        ExpressionType.AndAssign,
        //        ExpressionType.DivideAssign,
        //        ExpressionType.ExclusiveOrAssign,
        //        ExpressionType.LeftShiftAssign,
        //        ExpressionType.ModuloAssign,
        //        ExpressionType.MultiplyAssign,
        //        ExpressionType.MultiplyAssignChecked,
        //        ExpressionType.OrAssign,
        //        ExpressionType.PostDecrementAssign,
        //        ExpressionType.PostIncrementAssign,
        //        ExpressionType.PowerAssign,
        //        ExpressionType.PreDecrementAssign,
        //        ExpressionType.PreIncrementAssign,
        //        ExpressionType.RightShiftAssign,
        //        ExpressionType.SubtractAssign,
        //        ExpressionType.SubtractAssignChecked,
        //    };

        public static bool CurrentHasPrecedence(JavascriptOperationTypes current, JavascriptOperationTypes parent)
        {
            if (current == JavascriptOperationTypes.Call && parent == JavascriptOperationTypes.IndexerProperty)
            {
                return(true);
            }

            if (current == JavascriptOperationTypes.TernaryOp)
            {
                return(JavascriptOperationTypes.TernaryOp > parent);
            }

            if (current == JavascriptOperationTypes.TernaryTest ||
                current == JavascriptOperationTypes.TernaryTrueValue ||
                current == JavascriptOperationTypes.TernaryFalseValue)
            {
                return(true);
            }

            if (current == JavascriptOperationTypes.TernaryOp && parent == JavascriptOperationTypes.TernaryTrueValue)
            {
                return(false);
            }

            if (current == JavascriptOperationTypes.AddSubtract && parent == JavascriptOperationTypes.Concat)
            {
                return(false);
            }
            if (current == JavascriptOperationTypes.Concat && parent == JavascriptOperationTypes.AddSubtract)
            {
                return(false);
            }

            return(current >= parent);
        }
예제 #2
0
 public PrecedenceController(StringBuilder result, List<JavascriptOperationTypes> operandTypes, JavascriptOperationTypes op)
 {
     this.result = result;
     this.operandTypes = operandTypes;
     this.op = op;
     operandTypes.Add(op);
     this.WritePrecedenceChar('(');
 }
예제 #3
0
 public Precedence(StringBuilder result, List <JavascriptOperationTypes> operandTypes, JavascriptOperationTypes op)
 {
     this.result       = result;
     this.operandTypes = operandTypes;
     this.op           = op;
     operandTypes.Add(op);
     this.WritePrecedenceCharIfNeeded('(');
 }
 public PrecedenceController(StringBuilder result, List <JavascriptOperationTypes> operandTypes, JavascriptOperationTypes op)
 {
     _result       = result;
     _operandTypes = operandTypes;
     _op           = op;
     operandTypes.Add(op);
     WritePrecedenceCharIfNeeded('(');
 }
예제 #5
0
        //private static readonly ExpressionType[] assign = new[]
        //    {
        //        ExpressionType.Assign,
        //        ExpressionType.AddAssign,
        //        ExpressionType.AddAssignChecked,
        //        ExpressionType.AndAssign,
        //        ExpressionType.DivideAssign,
        //        ExpressionType.ExclusiveOrAssign,
        //        ExpressionType.LeftShiftAssign,
        //        ExpressionType.ModuloAssign,
        //        ExpressionType.MultiplyAssign,
        //        ExpressionType.MultiplyAssignChecked,
        //        ExpressionType.OrAssign,
        //        ExpressionType.PostDecrementAssign,
        //        ExpressionType.PostIncrementAssign,
        //        ExpressionType.PowerAssign,
        //        ExpressionType.PreDecrementAssign,
        //        ExpressionType.PreIncrementAssign,
        //        ExpressionType.RightShiftAssign,
        //        ExpressionType.SubtractAssign,
        //        ExpressionType.SubtractAssignChecked,
        //    };
        public static bool CurrentHasPrecedence(JavascriptOperationTypes current, JavascriptOperationTypes parent)
        {
            if (current == JavascriptOperationTypes.Call && parent == JavascriptOperationTypes.IndexerProperty)
                return true;

            if (current == JavascriptOperationTypes.TernaryCondition)
                return JavascriptOperationTypes.TernaryCondition > parent;

            if (current == JavascriptOperationTypes.AddSubtract && parent == JavascriptOperationTypes.Concat)
                return false;
            if (current == JavascriptOperationTypes.Concat && parent == JavascriptOperationTypes.AddSubtract)
                return false;

            return current >= parent;
        }
예제 #6
0
 /// <summary>
 /// Uses the precedence operator only if needed. i.e. '(' operations ')'.
 /// <para> - Writes '(' immediately, and returns a disposable that writes the ending ')'.</para>
 /// <para> - Pushes the operation into the stack, and pops it when disposed.</para>
 /// </summary>
 /// <param name="op">The operation that is going to be rendered inside the using block.</param>
 /// <returns>Disposable that renders the ending ')' of the precedence operator.</returns>
 public PrecedenceController Operation(JavascriptOperationTypes op)
 {
     return(new PrecedenceController(this.result, this.operandTypes, op));
 }
예제 #7
0
 /// <summary>
 /// Encloses the following write calls in an operation context,
 /// that will automatically write precedence operators '(' and ')' if needed,
 /// depening on the operations stack.
 /// <para>
 /// For example, a sum (+)
 /// inside a multiplication (*) requires the precedence operators.
 /// </para>
 /// <para>
 /// To isolate operations, you can pass 0 to the <paramref name="op"/> parameter,
 /// making neither the current nor the inner operation need precedence operators.
 /// </para>
 /// </summary>
 /// <param name="context">Context of the conversion.</param>
 /// <param name="op">The operation that you want to render in the scope.</param>
 /// <returns>A disposable object that renders the ending ')' when needed.</returns>
 public static IDisposable Operation(
     this JavascriptConversionContext context,
     JavascriptOperationTypes op)
 {
     return(context.GetWriter().Operation(op));
 }