Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetDefinition.cs
3using System.Threading.Tasks;
9
11{
16 {
26 {
27 }
28
35 {
37
38 foreach (ScriptNode N in this.Elements)
39 Elements.Add(N.Evaluate(Variables));
40
41 return Encapsulate(Elements);
42 }
43
49 public override async Task<IElement> EvaluateAsync(Variables Variables)
50 {
51 if (!this.isAsync)
52 return this.Evaluate(Variables);
53
55
56 foreach (ScriptNode N in this.Elements)
57 Elements.Add(await N.EvaluateAsync(Variables));
58
59 return Encapsulate(Elements);
60 }
61
67 public static IElement Encapsulate(ICollection<IElement> Elements)
68 {
69 return new FiniteSet(Elements);
70 }
71
77 public static IElement Encapsulate(IEnumerable Elements)
78 {
79 return new FiniteSet(Elements);
80 }
81
88 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
89 {
91
92 int? Size;
93
94 if (!(CheckAgainst is ISet Set))
95 return PatternMatchResult.NoMatch;
96
97 if (!(Size = Set.Size).HasValue)
98 return PatternMatchResult.Unknown;
99
100 if (Size.Value != Elements.Length)
101 return PatternMatchResult.NoMatch;
102
103 PatternMatchResult Result;
104 int i = 0;
105
106 foreach (IElement E in Set.ChildElements)
107 {
108 Result = Elements[i++].PatternMatch(E, AlreadyFound);
109 if (Result != PatternMatchResult.Match)
110 return Result;
111 }
112
113 return PatternMatchResult.Match;
114 }
115
116 }
117}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Base class for all types of sets.
Definition: Set.cs:14
virtual ? int Size
Size of set, if finite and known, otherwise null is returned.
Definition: Set.cs:100
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: Set.cs:84
Class managing a script expression.
Definition: Expression.cs:41
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 finite set.
Definition: FiniteSet.cs:13
Represents a list of elements.
Definition: ElementList.cs:15
bool isAsync
If any of the elements are asynchronous
Definition: ElementList.cs:22
ScriptNode[] Elements
Elements.
Definition: ElementList.cs:59
static IElement Encapsulate(IEnumerable Elements)
Encapsulates the elements of a set.
SetDefinition(ScriptNode[] Elements, int Start, int Length, Expression Expression)
Creates a set.
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static IElement Encapsulate(ICollection< IElement > Elements)
Encapsulates the elements of a set.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21
Basic interface for all types of sets.
Definition: ISet.cs:10
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17