Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NotEqualTo.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
7
9{
13 public class NotEqualTo : BinaryOperator
14 {
24 : base(Left, Right, Start, Length, Expression)
25 {
26 }
27
34 {
35 IElement Left = this.left.Evaluate(Variables);
36 IElement Right = this.right.Evaluate(Variables);
37
38 if (Left.Equals(Right))
39 return BooleanValue.False;
40 else
41 return BooleanValue.True;
42 }
43
49 public override async Task<IElement> EvaluateAsync(Variables Variables)
50 {
51 if (!this.isAsync)
52 return this.Evaluate(Variables);
53
54 IElement Left = await this.left.EvaluateAsync(Variables);
55 IElement Right = await this.right.EvaluateAsync(Variables);
56
57 if (Left.Equals(Right))
58 return BooleanValue.False;
59 else
60 return BooleanValue.True;
61 }
62
69 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
70 {
71 int i;
72
73 if (!(CheckAgainst.AssociatedSet is IOrderedSet S))
74 return PatternMatchResult.NoMatch;
75
76 if (this.left is ConstantElement LeftConstant)
77 {
78 i = S.Compare(LeftConstant.Constant, CheckAgainst);
79 if (i != 0)
80 return this.right.PatternMatch(CheckAgainst, AlreadyFound);
81 else
82 return PatternMatchResult.NoMatch;
83 }
84
85 if (this.right is ConstantElement RightConstant)
86 {
87 i = S.Compare(CheckAgainst, RightConstant.Constant);
88 if (i != 0)
89 return this.left.PatternMatch(CheckAgainst, AlreadyFound);
90 else
91 return PatternMatchResult.NoMatch;
92 }
93
94 if (this.left is VariableReference LeftReference &&
95 (AlreadyFound.TryGetValue(LeftReference.VariableName, out IElement Value) ||
96 Expression.TryGetConstant(LeftReference.VariableName, null, out Value)))
97 {
98 i = S.Compare(Value, CheckAgainst);
99 if (i != 0)
100 return this.right.PatternMatch(CheckAgainst, AlreadyFound);
101 else
102 return PatternMatchResult.NoMatch;
103 }
104
105 if (this.right is VariableReference RightReference &&
106 (AlreadyFound.TryGetValue(RightReference.VariableName, out Value) ||
107 Expression.TryGetConstant(RightReference.VariableName, null, out Value)))
108 {
109 i = S.Compare(CheckAgainst, Value);
110 if (i != 0)
111 return this.left.PatternMatch(CheckAgainst, AlreadyFound);
112 else
113 return PatternMatchResult.NoMatch;
114 }
115
116 return PatternMatchResult.NoMatch;
117 }
118 }
119}
Class managing a script expression.
Definition: Expression.cs:39
static bool TryGetConstant(string Name, Variables Variables, out IElement ValueElement)
Tries to get a constant value, given its name.
Definition: Expression.cs:3307
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Represents a constant element value.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
virtual PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: ScriptNode.cs:169
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Represents a variable reference.
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: NotEqualTo.cs:33
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: NotEqualTo.cs:69
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: NotEqualTo.cs:49
NotEqualTo(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Not Equal To.
Definition: NotEqualTo.cs:23
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for ordered sets.
Definition: IOrderedSet.cs:11
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17