2using System.Threading.Tasks;
19 private readonly
string name;
20 private readonly
int nrAttributes;
41 this.attributes = Attributes;
44 this.nrAttributes = Attributes.
Length;
49 private void CalcIsAsync()
58 for (i = 0; i < this.nrAttributes; i++)
69 while (!(Loop is
null))
71 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
96 if (this.children is
null)
99 this.children.
Add(Node);
122 for (i = 0; i < this.nrAttributes; i++)
130 while (!(Loop is
null))
132 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
143 bool RecalcIsAsync =
false;
146 if (!(this.xmlns is
null))
148 b = !Callback(this.xmlns, out NewNode, State);
151 this.xmlns = NewAttr;
154 RecalcIsAsync =
true;
157 if (b || (Order ==
SearchMethod.TreeOrder && !
this.xmlns.ForAllChildNodes(Callback, State, Order)))
166 for (i = 0; i < this.nrAttributes; i++)
168 b = !Callback(this.attributes[i], out NewNode, State);
171 this.attributes[i] = Attr;
172 Attr.SetParent(
this);
174 RecalcIsAsync =
true;
177 if (b || (Order ==
SearchMethod.TreeOrder && !
this.attributes[i].ForAllChildNodes(Callback, State, Order)))
187 while (!(Loop is
null))
189 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
191 b = !Callback(Loop[i], out NewNode, State);
195 Node2.SetParent(
this);
197 RecalcIsAsync =
true;
200 if (b || (Order ==
SearchMethod.TreeOrder && !Loop[i].ForAllChildNodes(Callback, State, Order)))
220 for (i = 0; i < this.nrAttributes; i++)
228 while (!(Loop is
null))
230 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
251 string ns = this.xmlns?.GetValue(
Variables) ??
null;
256 if (
Parent is
null ||
string.IsNullOrEmpty(ns =
Parent.NamespaceURI))
262 if (
string.IsNullOrEmpty(ns))
263 E = Document.CreateElement(this.name);
265 E = Document.CreateElement(this.name, ns);
268 E = Document.CreateElement(this.name, ns);
271 Document.AppendChild(E);
275 foreach (XmlScriptAttribute Attr
in this.attributes)
278 if (!(this.children is
null))
280 foreach (XmlScriptNode Node
in this.children)
302 if (this.xmlns is
null)
305 ns = await this.xmlns.GetValueAsync(
Variables);
309 if (
Parent is
null ||
string.IsNullOrEmpty(ns =
Parent.NamespaceURI))
315 if (
string.IsNullOrEmpty(ns))
316 E = Document.CreateElement(this.name);
318 E = Document.CreateElement(this.name, ns);
321 E = Document.CreateElement(this.name, ns);
324 Document.AppendChild(E);
328 foreach (XmlScriptAttribute Attr
in this.attributes)
329 await Attr.BuildAsync(Document, E,
Variables);
331 if (!(this.children is
null))
333 foreach (XmlScriptNode Node
in this.children)
334 await Node.BuildAsync(Document, E,
Variables);
348 if (CheckAgainst is
null)
350 if (!(this.xmlns is
null))
364 if (!(this.children is
null))
376 if (!(CheckAgainst is XmlElement E))
379 if (E.LocalName !=
this.name)
382 if (!(this.xmlns is
null))
384 Result = this.xmlns.
PatternMatch(CheckAgainst.NamespaceURI, AlreadyFound);
389 bool Wildcard =
false;
393 if (
string.IsNullOrEmpty(Attr.
Name))
397 XmlAttribute Attr2 = E.Attributes[Attr.
Name];
407 foreach (XmlAttribute Attr
in E.Attributes)
409 if (Attr.Name ==
"xmlns")
416 if (Attr2.
Name == Attr.Name)
428 XmlNode N = E.FirstChild;
431 if (!(this.children is
null))
448 if (N is XmlElement E2)
457 else if (N is XmlElement E3)
464 else if ((N is XmlText &&
string.IsNullOrWhiteSpace(N.InnerText)) ||
475 else if ((N is XmlText &&
string.IsNullOrWhiteSpace(N.InnerText)) ||
494 else if ((N is XmlText &&
string.IsNullOrWhiteSpace(N.InnerText)) ||
516 if (N is XmlWhitespace || N is XmlSignificantWhitespace || N is XmlComment ||
517 ((N is XmlText || N is XmlCDataSection) &&
string.IsNullOrWhiteSpace(N.InnerXml)))
535 public override bool IsApplicable(XmlNode CheckAgainst, XmlElement First)
537 if (!(CheckAgainst is XmlElement E))
542 if (this.name != E.LocalName)
545 if (this.xmlns is
null)
548 return this.xmlns.
IsApplicable(CheckAgainst.NamespaceURI);
553 E.LocalName == First.LocalName &&
554 E.NamespaceURI == First.NamespaceURI;
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 .
ChunkNode< T > FirstChunk
First chunk
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
Class managing a script expression.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
ScriptNode Parent
Parent node.
int Start
Start position in script expression.
virtual bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed or created.
Contains information about a variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Abstract base class for XML Script attribute nodes.
string Name
Attribute name.
abstract PatternMatchResult PatternMatch(string CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
override bool IsApplicable(XmlNode CheckAgainst, XmlElement First)
If the node is applicable in pattern matching against CheckAgainst .
XmlScriptElement(string Name, XmlScriptAttribute Xmlns, XmlScriptAttribute[] Attributes, int Start, int Length, Expression Expression)
XML Script element node.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
override bool IsApplicable(XmlNode CheckAgainst, XmlElement First)
If the node is applicable in pattern matching against CheckAgainst .
void Add(XmlScriptNode Node)
Adds a XML Script node to the element.
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
Base class for all XML Script nodes in a parsed script tree.
virtual bool IsWhitespace
If the node represents whitespace.
abstract PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
virtual bool IsVector
If the node represents a vector of nodes.
abstract bool IsApplicable(XmlNode CheckAgainst, XmlElement First)
If the node is applicable in pattern matching against CheckAgainst .
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