private void processTokenToExpression(LogicalExpressionNode current, Token token) { if (LETokenType.Literal == token.Type) { current.Children.Add(new LiteralNode {Literal = token.Value, Negative = token.Negation}); return; } if (LETokenType.Number == token.Type) { current.Children.Add(new LiteralNode { Literal = token.Value, IsNumber=true, Negative = token.Negation }); return; } if (LETokenType.And == token.Type || LETokenType.Block == token.Type) { var conj = new ConjunctionNode {Negative = token.Negation}; current.Children.Add(conj); foreach (var child in token.Children) { processTokenToExpression(conj, child); } return; } if (LETokenType.Or == token.Type) { var disj = new DisjunctionNode {Negative = token.Negation}; current.Children.Add(disj); foreach (var child in token.Children) { processTokenToExpression(disj, child); } return; } if (0!=(token.Type & LETokenType.Compare)) { var fst = token.Children[0]; var sec = token.Children[1]; LogicalExpressionNode n; if (token.Type == LETokenType.Regex) { n = new RegexTestNode { First = fst.Value, Second = sec.Value, FirstIsLiteral = fst.Type == LETokenType.Literal, SecondIsLiteral = sec.Type == LETokenType.Literal }; }else if (fst.Type == LETokenType.Number) { var eq = new EqualValueNode(); n = eq; eq.Literal = sec.Value; eq.Value = fst.Value; eq.IsNumber = true; } else if (sec.Type == LETokenType.Number) { var eq = new EqualValueNode(); n = eq; eq.Literal = fst.Value; eq.Value = sec.Value; eq.IsNumber = true; } else if (sec.Type == LETokenType.Literal) { var eq = new EqualNode(); n = eq; if (fst.Type == LETokenType.String) { var eq2= new EqualValueNode(); eq2.Literal = sec.Value; eq2.Value = fst.Value; n = eq2; } else { eq.FirstLiteral = fst.Value; eq.SecondLiteral = sec.Value; } } else { var eq = new EqualValueNode(); n = eq; eq.Literal = fst.Value; eq.Value = sec.Value; } n.Negative = token.Negation; n.Operation = token.Type; if (token.Type != LETokenType.Neq && token.Type != LETokenType.Eq) { n.IsNumber = true; } if (LETokenType.Neq == token.Type) { n.Negative = !n.Negative; } current.Children.Add(n); } }
private void processTokenToExpression(LogicalExpressionNode current, Token token) { if (LETokenType.Literal == token.Type) { current.Children.Add(new LiteralNode { Literal = token.Value, Negative = token.Negation }); return; } if (LETokenType.Number == token.Type) { current.Children.Add(new LiteralNode { Literal = token.Value, IsNumber = true, Negative = token.Negation }); return; } if (LETokenType.And == token.Type || LETokenType.Block == token.Type) { var conj = new ConjunctionNode { Negative = token.Negation }; current.Children.Add(conj); foreach (var child in token.Children) { processTokenToExpression(conj, child); } return; } if (LETokenType.Or == token.Type) { var disj = new DisjunctionNode { Negative = token.Negation }; current.Children.Add(disj); foreach (var child in token.Children) { processTokenToExpression(disj, child); } return; } if (0 != (token.Type & LETokenType.Compare)) { var fst = token.Children[0]; var sec = token.Children[1]; LogicalExpressionNode n; if (token.Type == LETokenType.Regex) { n = new RegexTestNode { First = fst.Value, Second = sec.Value, FirstIsLiteral = fst.Type == LETokenType.Literal, SecondIsLiteral = sec.Type == LETokenType.Literal }; } else if (fst.Type == LETokenType.Number) { var eq = new EqualValueNode(); n = eq; eq.Literal = sec.Value; eq.Value = fst.Value; eq.IsNumber = true; } else if (sec.Type == LETokenType.Number) { var eq = new EqualValueNode(); n = eq; eq.Literal = fst.Value; eq.Value = sec.Value; eq.IsNumber = true; } else if (sec.Type == LETokenType.Literal) { var eq = new EqualNode(); n = eq; if (fst.Type == LETokenType.String) { var eq2 = new EqualValueNode(); eq2.Literal = sec.Value; eq2.Value = fst.Value; n = eq2; } else { eq.FirstLiteral = fst.Value; eq.SecondLiteral = sec.Value; } } else { var eq = new EqualValueNode(); n = eq; eq.Literal = fst.Value; eq.Value = sec.Value; } n.Negative = token.Negation; n.Operation = token.Type; if (token.Type != LETokenType.Neq && token.Type != LETokenType.Eq) { n.IsNumber = true; } if (LETokenType.Neq == token.Type) { n.Negative = !n.Negative; } current.Children.Add(n); } }