Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmlScriptNode.cs
1using System;
2using System.Collections.Generic;
3using System.Numerics;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
12
14{
18 public abstract class XmlScriptNode : ScriptNode
19 {
27 : base(Start, Length, Expression)
28 {
29 }
30
37 {
38 return ObjectValue.Null;
39 }
40
47 internal abstract void Build(XmlDocument Document, XmlElement Parent, Variables Variables);
48
55 internal virtual Task BuildAsync(XmlDocument Document, XmlElement Parent, Variables Variables)
56 {
57 this.Build(Document, Parent, Variables);
58 return Task.CompletedTask;
59 }
60
67 public static string EvaluateString(ScriptNode Node, Variables Variables)
68 {
69 return EvaluateString(Node.Evaluate(Variables));
70 }
71
78 public static async Task<string> EvaluateStringAsync(ScriptNode Node, Variables Variables)
79 {
80 return EvaluateString(await Node.EvaluateAsync(Variables));
81 }
82
88 public static string EvaluateString(IElement Element)
89 {
90 object Obj = Element.AssociatedObjectValue;
91
92 if (Obj is string s)
93 return s;
94 else if (Obj is bool b)
95 return CommonTypes.Encode(b);
96 else if (Obj is double d)
97 return CommonTypes.Encode(d);
98 else if (Obj is DateTime TP)
99 return XML.Encode(TP, TP.TimeOfDay == TimeSpan.Zero);
100 else if (Obj is BigInteger I)
101 return I.ToString();
102 else
103 {
104 if (Obj is null)
105 return null;
106 else if (Obj is CaseInsensitiveString cis)
107 return cis.Value;
108 else
109 return Expression.ToString(Obj);
110 }
111 }
112
119 public abstract PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary<string, IElement> AlreadyFound);
120
126 public abstract bool IsApplicable(XmlNode CheckAgainst);
127
131 public virtual bool IsVector
132 {
133 get => false;
134 }
135 }
136}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:27
Represents a case-insensitive string.
Base class for all types of elements.
Definition: Element.cs:13
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:46
Class managing a script expression.
Definition: Expression.cs:39
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
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
ScriptNode Parent
Parent node.
Definition: ScriptNode.cs:126
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
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:86
Collection of variables.
Definition: Variables.cs:25
Base class for all XML Script nodes in a parsed script tree.
static string EvaluateString(ScriptNode Node, Variables Variables)
Evaluates a script node to a string.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static string EvaluateString(IElement Element)
Evaluates a script element to a string.
abstract bool IsApplicable(XmlNode CheckAgainst)
If the node is applicable in pattern matching against CheckAgainst .
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.
static async Task< string > EvaluateStringAsync(ScriptNode Node, Variables Variables)
Evaluates a script node to a string.
XmlScriptNode(int Start, int Length, Expression Expression)
Base class for all XML Script nodes in a parsed script tree.
Basic interface for all types of elements.
Definition: IElement.cs:20
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17