1 using Mercury.Nucleus.Trees;
4 using System.Collections.Generic;
7 namespace Mercury.Interpreting
23 if (var == null)
throw new ArgumentNullException(
"var");
24 if (value == null)
throw new ArgumentNullException(
"value");
34 :
this(var, wildmatch as object)
38 :
this(var, tree as object)
47 public object Value {
get;
private set; }
53 public override bool Equals(
object obj)
56 return other == null ?
false : Equals(other);
60 {
return Var.GetHashCode(); }
66 #region [ IEquatable ]
70 if ((other == null) || !Var.Equals(other.
Var))
75 var obja = Value as Tree<Symbol>[];
76 var objb = other.Value as Tree<Symbol>[];
78 return (obja.Length == objb.Length)
79 && (obja.Zip(objb, (a, b) => a.Equals(b)).
All(x => x));
82 return Value.Equals(other.Value);
98 private List<Instance> data;
99 private Dictionary<string, Instance> dict;
105 data =
new List<Instance>();
106 dict =
new Dictionary<string, Instance>();
112 public int Count {
get {
return data.Count; } }
120 public Instance this[
string name] {
get {
return dict[name]; } }
130 internal void Add(
Instance instance)
132 if (instance == null)
throw new ArgumentNullException(
"instance");
134 dict.Add(instance.Var.Name, instance);
139 internal void Clear()
150 internal void RemoveLast(
int count = 1)
152 for(
int ix = 0; (ix < count) && (data.Count > 0); ++ix)
154 Instance value = data[data.Count - 1];
155 data.RemoveAt(data.Count - 1);
156 dict.Remove(value.Var.Name);
162 #region [ IEnumerable ]
165 {
return data.GetEnumerator(); }
167 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
168 {
return data.GetEnumerator(); }
Represents a binding between a Mercury.Interpreting.Variable and its value
override int GetHashCode()
Maps token to symbol, keyword, number and string
Represents a variable element that captures value and can be used on the RHS of the RewriteRule as an...
bool Equals(Instance other)
An element that matches zero or more values. Can be used as a variable, but the actioncall must be of...
Represents the list of instances
IEnumerator< Instance > GetEnumerator()
override bool Equals(object obj)