Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PatternMatch.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
6
8{
13 {
23 : base(Left, Right, Start, Length, Expression)
24 {
25 }
26
33 {
34 IElement Result = this.right.Evaluate(Variables);
35 Match(this.left, Result, Variables, this);
36 return Result;
37 }
38
44 public override async Task<IElement> EvaluateAsync(Variables Variables)
45 {
46 if (!this.isAsync)
47 return this.Evaluate(Variables);
48
49 IElement Result = await this.right.EvaluateAsync(Variables);
50 Match(this.left, Result, Variables, this);
51 return Result;
52 }
60 public static void Match(ScriptNode Branch, IElement Value, Variables Variables, ScriptNode Node)
61 {
62 Dictionary<string, IElement> AlreadyFound = new Dictionary<string, IElement>();
63
64 switch (Branch.PatternMatch(Value, AlreadyFound))
65 {
66 case PatternMatchResult.Match:
67 foreach (KeyValuePair<string, IElement> P in AlreadyFound)
68 Variables[P.Key] = P.Value;
69 break;
70
71 case PatternMatchResult.NoMatch:
72 throw new ScriptRuntimeException("Pattern mismatch.", Node);
73
74 case PatternMatchResult.Unknown:
75 default:
76 throw new ScriptRuntimeException("Unable to compute pattern match.", Node);
77 }
78 }
79 }
80}
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
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
PatternMatch(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Assignment operator.
Definition: PatternMatch.cs:22
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: PatternMatch.cs:44
static void Match(ScriptNode Branch, IElement Value, Variables Variables, ScriptNode Node)
Performs a pattern-matching operation
Definition: PatternMatch.cs:60
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: PatternMatch.cs:32
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17