public void TestToExpressionString() { for (int i = 0; i < identNodes.Length; i++) { identNodes[i].Validate(SupportExprValidationContextFactory.Make(container, streamTypeService)); } Assert.AreEqual("Mapped('a')", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(identNodes[0])); Assert.AreEqual("Nested.NestedValue", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(identNodes[1])); Assert.AreEqual("s2.Indexed[1]", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(identNodes[2])); Assert.AreEqual("s0.IntPrimitive", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(identNodes[3])); }
public override void ToPrecedenceFreeEPL(TextWriter writer) { writer.Write(ParameterName); writer.Write(":"); if (ChildNodes.Length > 1) { writer.Write("("); } ExprNodeUtilityPrint.ToExpressionStringParameterList(ChildNodes, writer); if (ChildNodes.Length > 1) { writer.Write(")"); } }
/// <summary> /// Validates the expression node subtree that has this /// node as root. Some of the nodes of the tree, including the /// root, might be replaced in the process. /// </summary> /// <param name="origin">validate origin</param> /// <param name="exprNode">node</param> /// <param name="validationContext">context</param> /// <returns>the root node of the validated subtree, possibly different than the root node of the unvalidated subtree /// </returns> /// <throws>ExprValidationException when the validation fails</throws> public static ExprNode GetValidatedSubtree( ExprNodeOrigin origin, ExprNode exprNode, ExprValidationContext validationContext) { if (exprNode is ExprLambdaGoesNode) { return exprNode; } try { return GetValidatedSubtreeInternal(exprNode, validationContext, true); } catch (ExprValidationException ex) { try { string text; if (exprNode is ExprSubselectNode subselect) { text = ExprNodeUtilityMake.GetSubqueryInfoText(subselect); } else { text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprNode); if (text.Length > 40) { string shortened = text.Substring(0, 35); text = shortened + "...(" + text.Length + " chars)"; } text = "'" + text + "'"; } var errorText = string.Format( "Failed to validate {0} expression {1}: {2}", origin.GetClauseName(), text, ex.Message); throw new ExprValidationException(errorText, ex); } catch (ExprValidationException) { throw; } catch (EPException) { throw; } catch (Exception rtex) { Log.Debug("Failed to render nice validation message text: " + rtex.Message, rtex); // fall through } throw; } }
private void HandleGetForge(IInvocation invocation) { var expressionToString = "undefined"; try { expressionToString = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(Proxy); } catch (EPException) { throw; } catch (Exception) { // no action } var forge = (ExprForge) invocation.Method.Invoke(Proxy, invocation.Arguments); invocation.ReturnValue = ExprForgeProxy.NewInstance(expressionToString, forge); }
private static void ValidatePlainExpression( ExprNodeOrigin origin, ExprNode expression, ExprNodeSummaryVisitor summaryVisitor) { expression.Accept(summaryVisitor); if (summaryVisitor.HasAggregation || summaryVisitor.HasSubselect || summaryVisitor.HasStreamSelect || summaryVisitor.HasPreviousPrior) { string text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expression); throw new ExprValidationException( "Invalid " + origin.GetClauseName() + " expression '" + text + "': Aggregation, sub-select, previous or prior functions are not supported in this context"); } }
public override void ToPrecedenceFreeEPL(TextWriter writer) { ExprNodeUtilityPrint.ToExpressionStringWFunctionName("grouping_id", ChildNodes, writer); }
private static ExprAssignment CheckGetStraightAssignment( ExprNode node, bool allowLHSVariables) { var prop = CheckGetAssignmentToProp(node); if (prop != null) { return new ExprAssignmentStraight(node, new ExprAssignmentLHSIdent(prop.First), prop.Second); } if (!(node is ExprEqualsNode)) { return null; } var equals = (ExprEqualsNode) node; var lhs = equals.ChildNodes[0]; var rhs = equals.ChildNodes[1]; if (lhs is ExprVariableNode) { var variableNode = (ExprVariableNode) equals.ChildNodes[0]; if (!allowLHSVariables) { throw new ExprValidationException( "Left-hand-side does not allow variables for variable '" + variableNode.VariableMetadata.VariableName + "'"); } var variableNameWSubprop = variableNode.VariableNameWithSubProp; var variableName = variableNameWSubprop; String subPropertyName = null; var indexOfDot = variableNameWSubprop.IndexOf('.'); if (indexOfDot != -1) { subPropertyName = variableNameWSubprop.Substring(indexOfDot + 1); variableName = variableNameWSubprop.Substring(0, indexOfDot); } ExprAssignmentLHS lhsAssign; if (subPropertyName != null) { lhsAssign = new ExprAssignmentLHSIdentWSubprop(variableName, subPropertyName); } else { lhsAssign = new ExprAssignmentLHSIdent(variableName); } return new ExprAssignmentStraight(node, lhsAssign, rhs); } if (lhs is ExprDotNode dot) { var chainables = dot.ChainSpec; if (chainables.Count == 2 && chainables[0] is ChainableName name && chainables[1] is ChainableArray array) { return new ExprAssignmentStraight(node, new ExprAssignmentLHSArrayElement(name.Name, array.Indexes), rhs); } if (allowLHSVariables && dot.ChildNodes[0] is ExprVariableNode variableNode && chainables.Count == 1 && chainables[0] is ChainableArray chainableArray) { return new ExprAssignmentStraight( node, new ExprAssignmentLHSArrayElement( variableNode.VariableMetadata.VariableName, chainableArray.Indexes), rhs); } throw new ExprValidationException( "Unrecognized left-hand-side assignment '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(dot) + "'"); } if (lhs is ExprTableAccessNode) { throw new ExprValidationException("Table access expression not allowed on the left hand side, please remove the table prefix"); } return null; }