/// <summary>The <see cref="NegationNode"/> visit implementation</summary> /// <param name="negationNode">The negation node.</param> /// <returns>The modified AST node if modified otherwise the original node</returns> public override AstNode VisitNegationNode(NegationNode negationNode) { // negation // : NOT S* negation_arg S* ')' // ; _printerFormatter.Append(CssConstants.Colon); _printerFormatter.Append(CssConstants.Not); _printerFormatter.Append(CssConstants.OpenRoundBracket); negationNode.NegationArgNode.Accept(this); _printerFormatter.Append(CssConstants.CloseRoundBracket); return(negationNode); }
/// <summary>Creates the list of hash class attrib pseudo nodes.</summary> /// <param name="hashClassAttribPseudoNegationTreeNodes">The hash class attrib pseudo node tree.</param> /// <returns>The list of hash class attrib pseudo nodes.</returns> private static IEnumerable <HashClassAtNameAttribPseudoNegationNode> CreateHashClassAttribPseudoNegationNodes(IEnumerable <CommonTree> hashClassAttribPseudoNegationTreeNodes) { return(hashClassAttribPseudoNegationTreeNodes.Select(hashClassAttribPseudoNegationNode => { var child = hashClassAttribPseudoNegationNode.Children().FirstOrDefault(); string hash = null; string replacementToken = null; string cssClass = null; string atName = null; AttribNode attribNode = null; PseudoNode pseudoNode = null; NegationNode negationNode = null; if (child != null) { var nodeText = child.Text; if (nodeText == T(CssParser.HASHIDENTIFIER)) { hash = child.FirstChildText(); } else if (nodeText == T(CssParser.CLASSIDENTIFIER)) { cssClass = child.FirstChildText(); } else if (nodeText == T(CssParser.ATIDENTIFIER)) { atName = child.FirstChildText(); } else if (nodeText == T(CssParser.ATTRIBIDENTIFIER)) { attribNode = CreateAttribNode(child); } else if (nodeText == T(CssParser.PSEUDOIDENTIFIER)) { pseudoNode = CreatePseudoNode(child); } else if (nodeText == T(CssParser.NEGATIONIDENTIFIER)) { negationNode = CreateNegationNode(child); } else if (nodeText == T(CssParser.REPLACEMENTTOKENIDENTIFIER)) { replacementToken = child.FirstChildText(); } } return new HashClassAtNameAttribPseudoNegationNode(hash, cssClass, replacementToken, atName, attribNode, pseudoNode, negationNode); })); }
private Value Negation(NegationNode exp) { Value val = Eval(exp.InnerNode); Constant obj = val.GetRValue(); switch (obj.ConstantType) { case Constant.Type.Complex: return(ComplexValue.OpNeg((ComplexValue)obj)); case Constant.Type.Int: return(IntValue.OpNeg((IntValue)obj)); case Constant.Type.Float: return(FloatValue.OpNeg((FloatValue)obj)); } throw new ModelInterpreterException($"Отрицание не определено для типа \"{obj.ConstantType.ToString()}\"") { Line = exp.Line, Position = exp.Position }; }
/// <summary>The <see cref="NegationNode"/> visit implementation</summary> /// <param name="negationNode">The negation node.</param> /// <returns>The modified AST node if modified otherwise the original node</returns> public virtual AstNode VisitNegationNode(NegationNode negationNode) { return(negationNode); }
public void NegationNodeTest() { StreamLocation expectedLocation = new StreamLocation(3, 2, 1); Expression expectedExpr = Expression.Constant(true); NegationNode sut = new NegationNode(new TestNode(expectedExpr), expectedLocation); Assert.AreEqual(TNode.NEGATIVE, sut.NodeType); Assert.AreEqual(expectedLocation, sut.Location); Assert.IsTrue(sut.Description.Contains("NEGATIVE")); Assert.IsInstanceOfType(sut.SubExpression, typeof(UnaryExpression)); Assert.AreEqual(ExpressionType.Not, sut.SubExpression.NodeType); Assert.AreEqual(typeof(bool), sut.SubExpression.Type); Assert.AreEqual(expectedExpr, ((UnaryExpression)sut.SubExpression).Operand); }
/// <summary>The <see cref="NegationNode"/> visit implementation</summary> /// <param name="negationNode">The negation node.</param> /// <returns>The modified AST node if modified otherwise the original node</returns> public override AstNode VisitNegationNode(NegationNode negationNode) { return(new NegationNode((NegationArgNode)negationNode.NegationArgNode.Accept(this))); }