3using System.Threading.Tasks;
18 private readonly
bool hasWildcards =
false;
19 private Dictionary<string, ScriptNode> quick =
null;
49 foreach (KeyValuePair<string, ScriptNode> P
in Members)
50 P.Value?.SetParent(
this);
60 private void CalcIsAsync()
64 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
66 if (P.Value?.IsAsynchronous ??
false)
92 Dictionary<string, IElement> Result =
new Dictionary<string, IElement>();
94 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
95 Result[P.Key] = P.Value.Evaluate(
Variables);
110 Dictionary<string, IElement> Result =
new Dictionary<string, IElement>();
112 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
113 Result[P.Key] = await P.Value.EvaluateAsync(
Variables);
132 Loop = this.members?.FirstChunk;
134 while (!(Loop is
null))
136 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
146 bool RecalcIsAsync =
false;
148 if (!this.members.Update((ref KeyValuePair<string, ScriptNode> P, out
bool Keep) =>
152 ScriptNode Node = P.Value;
155 bool Result = Callback(Node, out ScriptNode NewNode, State);
156 if (!(NewNode is null))
158 P = new KeyValuePair<string, ScriptNode>(P.Key, NewNode);
159 NewNode.SetParent(this);
162 RecalcIsAsync = true;
165 if (!Result || (Order == SearchMethod.TreeOrder && !Node.ForAllChildNodes(Callback, State, Order)))
185 Loop = this.members?.FirstChunk;
187 while (!(Loop is
null))
189 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
206 this.hasWildcards != O.hasWildcards ||
212 IEnumerator<KeyValuePair<string, ScriptNode>> e1 = this.members.GetEnumerator();
213 IEnumerator<KeyValuePair<string, ScriptNode>> e2 = O.members.GetEnumerator();
219 bool b1 = e1.MoveNext();
220 bool b2 = e2.MoveNext();
228 KeyValuePair<string, ScriptNode> Item1 = e1.Current;
229 KeyValuePair<string, ScriptNode> Item2 = e2.Current;
231 if (!Item1.Key.Equals(Item2.Key) ||
232 !Item1.Value.Equals(Item2.Value))
248 int Result = base.GetHashCode();
250 Result ^= Result << 5 ^ this.hasWildcards.GetHashCode();
252 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
254 Result ^= Result << 5 ^ P.Key.GetHashCode();
255 Result ^= Result << 5 ^ P.Value.GetHashCode();
275 if (!this.hasWildcards)
277 foreach (KeyValuePair<string, IElement> P
in Object)
279 if (!this.quick.ContainsKey(P.Key))
284 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
286 if (Object.TryGetValue(P.Key, out
IElement E))
287 Result = P.Value.PatternMatch(E, AlreadyFound);
299 if (!this.hasWildcards)
301 foreach (KeyValuePair<string, object> P
in Object2)
303 if (!this.quick.ContainsKey(P.Key))
308 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
310 if (Object2.TryGetValue(P.Key, out
object E))
328 if (!this.hasWildcards)
330 foreach (KeyValuePair<string, string> P
in Object3)
332 if (!this.quick.ContainsKey(P.Key))
337 foreach (KeyValuePair<string, ScriptNode> P
in this.members)
339 if (Object3.TryGetValue(P.Key, out
string s))
340 Result = P.Value.PatternMatch(
new StringValue(s), AlreadyFound);
354 private void CheckQuick()
356 if (this.quick is
null)
358 Dictionary<string, ScriptNode> Quick =
new Dictionary<string, ScriptNode>();
360 foreach (KeyValuePair<string, ScriptNode> N
in this.members)
361 Quick[N.Key] = N.Value;
Node referencing a chunk in a ChunkedList<T>
ChunkNode< T > Next
Next chunk
int Pos
Index after the last element in chunk.
int Start
Index of first element in chunk.
A chunked list is a linked list of chunks of objects of type T .
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
int Start
Start position in script expression.
static readonly ObjectValue Null
Null value.
Creates an object from nothing.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
ObjectExNihilo(ChunkedList< KeyValuePair< string, ScriptNode > > Members, int Start, int Length, Expression Expression)
Creates an object from nothing.
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
override bool Equals(object obj)
ChunkedList< KeyValuePair< string, ScriptNode > > Members
Members, in order of definition.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
bool HasWildcards
If the object definition includes wildcards.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override int GetHashCode()
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
ObjectExNihilo(ChunkedList< KeyValuePair< string, ScriptNode > > Members, bool HasWildcards, int Start, int Length, Expression Expression)
Creates an object from nothing.
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
PatternMatchResult
Status result of a pattern matching operation.
SearchMethod
Method to traverse the expression structure