Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Matches.cs
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading.Tasks;
8
10{
14 public class Matches : BinaryOperator
15 {
25 : base(Left, Right, Start, Length, Expression)
26 {
27 }
28
35 {
36 IElement Left = this.left.Evaluate(Variables);
37 return this.EvaluateMatches(Left, Variables);
38 }
39
40 private BooleanValue EvaluateMatches(IElement Left, Variables Variables)
41 {
42 Dictionary<string, IElement> AlreadyFound = new Dictionary<string, IElement>();
43
44 switch (this.right.PatternMatch(Left, AlreadyFound))
45 {
46 case PatternMatchResult.Match:
47 foreach (KeyValuePair<string, IElement> P in AlreadyFound)
48 Variables[P.Key] = P.Value;
49
50 return BooleanValue.True;
51
52 case PatternMatchResult.NoMatch:
53 case PatternMatchResult.Unknown:
54 default:
55 return BooleanValue.False;
56 }
57 }
58
64 public override async Task<IElement> EvaluateAsync(Variables Variables)
65 {
66 if (!this.isAsync)
67 return this.Evaluate(Variables);
68 else
69 {
70 IElement Left = await this.left.EvaluateAsync(Variables);
71 return this.EvaluateMatches(Left, Variables);
72 }
73 }
74 }
75}
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
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
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 operator.
Definition: Matches.cs:34
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the operator.
Definition: Matches.cs:64
Matches(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Matches operator.
Definition: Matches.cs:24
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17