Skip to content

Commit 4aa5c21

Browse files
committed
Fix typo
1 parent 2c69d99 commit 4aa5c21

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Runtime/ExpressionParser.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public abstract class ExpressionParser<T>
1313
private readonly Dictionary<string, ExprBuilder> _builderCached = new Dictionary<string, ExprBuilder>();
1414
private Parser<ExprBuilder> _parserCached;
1515

16-
public Expression<bool> CompilePredicate(string input, ExpresionContext<T> context, bool cache)
16+
public Expression<bool> CompilePredicate(string input, ExpressionContext<T> context, bool cache)
1717
{
1818
var expr = Compile(input, context, cache);
1919
return () => IsTrue(expr.Invoke());
2020
}
2121

22-
public Expression<T> Compile(string input, ExpresionContext<T> context, bool cache)
22+
public Expression<T> Compile(string input, ExpressionContext<T> context, bool cache)
2323
{
24-
context = context ?? new ExpresionContext<T>();
24+
context = context ?? new ExpressionContext<T>();
2525

2626
_parserCached = _parserCached ?? CreateParser();
2727

@@ -177,7 +177,7 @@ select MakeUnary(Negate, fact)
177177
private T Min(T a, T b) => IsTrue(GreaterThan(a, b)) ? b : a;
178178
private T Max(T a, T b) => IsTrue(GreaterThan(b, a)) ? b : a;
179179

180-
private delegate Expression<T> ExprBuilder(ExpresionContext<T> context);
180+
private delegate Expression<T> ExprBuilder(ExpressionContext<T> context);
181181

182182
private delegate T UnaryFunc(T a);
183183

@@ -330,14 +330,14 @@ private static ExprBuilder MakeConstant(string valueString, Func<string, T> pars
330330
}
331331
}
332332

333-
public class ExpresionContext<T>
333+
public class ExpressionContext<T>
334334
{
335-
private readonly ExpresionContext<T> _parent;
335+
private readonly ExpressionContext<T> _parent;
336336
private readonly Func<string, Expression<T>> _unregisteredVariableResolver;
337337

338338
private readonly Dictionary<string, Expression<T>> _variables = new Dictionary<string, Expression<T>>();
339339

340-
public ExpresionContext(ExpresionContext<T> parent = null,
340+
public ExpressionContext(ExpressionContext<T> parent = null,
341341
Func<string, Expression<T>> unregisteredVariableResolver = null)
342342
{
343343
_parent = parent;
@@ -385,6 +385,11 @@ public Expression<T> GetVariable(string name, bool nullIsOk = false)
385385
}
386386
}
387387

388+
[Obsolete("ExpresionContext contains a typo. Use ExpressionContext instead", true)]
389+
public class ExpresionContext<T> : ExpressionContext<T>
390+
{
391+
}
392+
388393
public class VariableNotDefinedException : Exception
389394
{
390395
public VariableNotDefinedException(string name)

Tests/ParserTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class ParserTests
124124
[TestCase("NOT(a) AND NOT(b)", 1, 0, ExpectedResult = 0)]
125125
public float Parse_Variable(string input, float a, float b)
126126
{
127-
var context = new ExpresionContext<float>();
127+
var context = new ExpressionContext<float>();
128128
context.RegisterVariable("a", () => a);
129129
context.RegisterVariable("b", () => b);
130130
return Execute(input, context);
@@ -133,15 +133,15 @@ public float Parse_Variable(string input, float a, float b)
133133
[Test]
134134
public void ComplexVariableName()
135135
{
136-
var context = new ExpresionContext<float>();
136+
var context = new ExpressionContext<float>();
137137
context.RegisterVariable("Some_Variable", () => 1);
138138
Assert.AreEqual(1, Execute("Some_Variable", context));
139139
}
140140

141141
[Test]
142142
public void ReadmeSample()
143143
{
144-
var context = new ExpresionContext<float>();
144+
var context = new ExpressionContext<float>();
145145

146146
context.RegisterVariable("a", () => 1);
147147
context.RegisterVariable("b", () => 2);
@@ -157,7 +157,7 @@ public void ReadmeSample()
157157
[Test]
158158
public void Parse_Variable_Names()
159159
{
160-
var context = new ExpresionContext<float>();
160+
var context = new ExpressionContext<float>();
161161
context.RegisterVariable("o", () => 1);
162162
context.RegisterVariable("one", () => 1);
163163
context.RegisterVariable("one123", () => 1);
@@ -192,7 +192,7 @@ public void Parse_MinMax_Invalid()
192192
[Test]
193193
public void Parse_If()
194194
{
195-
var context = new ExpresionContext<float>();
195+
var context = new ExpressionContext<float>();
196196

197197
var n = 0;
198198
context.RegisterVariable("n", () => n);
@@ -218,8 +218,8 @@ public void Parse_If()
218218
[Test]
219219
public void ContextTree()
220220
{
221-
var rootContext = new ExpresionContext<float>();
222-
var subContext = new ExpresionContext<float>(rootContext);
221+
var rootContext = new ExpressionContext<float>();
222+
var subContext = new ExpressionContext<float>(rootContext);
223223

224224
var rootA = 1;
225225
var rootB = 2;
@@ -252,12 +252,12 @@ public bool Parse_Predicate(string input)
252252
return FloatExpressionParser.Instance.CompilePredicate(input, null, false).Invoke();
253253
}
254254

255-
private static float Execute(string input, ExpresionContext<float> context)
255+
private static float Execute(string input, ExpressionContext<float> context)
256256
{
257257
return Compile(input, context).Invoke();
258258
}
259259

260-
private static Expression<float> Compile(string input, ExpresionContext<float> context)
260+
private static Expression<float> Compile(string input, ExpressionContext<float> context)
261261
{
262262
return FloatExpressionParser.Instance.Compile(input, context, false);
263263
}

0 commit comments

Comments
 (0)