//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); }
public PrecedenceController(StringBuilder result, List<JavascriptOperationTypes> operandTypes, JavascriptOperationTypes op) { this.result = result; this.operandTypes = operandTypes; this.op = op; operandTypes.Add(op); this.WritePrecedenceChar('('); }
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('('); }
//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; }
/// <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)); }
/// <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)); }