Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetDefinition.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
8
10{
15 {
25 {
26 }
27
34 {
35 LinkedList<IElement> Elements = new LinkedList<IElement>();
36
37 foreach (ScriptNode N in this.Elements)
38 Elements.AddLast(N.Evaluate(Variables));
39
40 return Encapsulate(Elements);
41 }
42
48 public override async Task<IElement> EvaluateAsync(Variables Variables)
49 {
50 if (!this.isAsync)
51 return this.Evaluate(Variables);
52
53 LinkedList<IElement> Elements = new LinkedList<IElement>();
54
55 foreach (ScriptNode N in this.Elements)
56 Elements.AddLast(await N.EvaluateAsync(Variables));
57
58 return Encapsulate(Elements);
59 }
65 public static IElement Encapsulate(ICollection<IElement> Elements)
66 {
67 return new FiniteSet(Elements);
68 }
69
76 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
77 {
79
80 int? Size;
81
82 if (!(CheckAgainst is ISet Set))
83 return PatternMatchResult.NoMatch;
84
85 if (!(Size = Set.Size).HasValue)
86 return PatternMatchResult.Unknown;
87
88 if (Size.Value != Elements.Length)
89 return PatternMatchResult.NoMatch;
90
91 PatternMatchResult Result;
92 int i = 0;
93
94 foreach (IElement E in Set.ChildElements)
95 {
96 Result = Elements[i++].PatternMatch(E, AlreadyFound);
97 if (Result != PatternMatchResult.Match)
98 return Result;
99 }
100
101 return PatternMatchResult.Match;
102 }
103
104 }
105}
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:92
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: Set.cs:73
Class managing a script expression.
Definition: Expression.cs:39
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
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:20
Basic interface for all types of sets.
Definition: ISet.cs:10
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17