Skip to content

Commit 370882f

Browse files
author
Sébastien Geiser
committed
(#37) Correction of lettered operators before parentheses
1 parent e26c26c commit 370882f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,27 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
18751875
.SetCategory("inherits ExpressionEvaluator")
18761876
.SetCategory("Custom operators");
18771877

1878+
yield return new TestCaseData(xExpressionEvaluator2
1879+
, "Not true", null)
1880+
.Returns(false)
1881+
.SetCategory("ExpressionEvaluator extend")
1882+
.SetCategory("inherits ExpressionEvaluator")
1883+
.SetCategory("Custom operators");
1884+
1885+
yield return new TestCaseData(xExpressionEvaluator2
1886+
, "Not(true)", null)
1887+
.Returns(false)
1888+
.SetCategory("ExpressionEvaluator extend")
1889+
.SetCategory("inherits ExpressionEvaluator")
1890+
.SetCategory("Custom operators");
1891+
1892+
yield return new TestCaseData(xExpressionEvaluator2
1893+
, "Not(1 == 1)", null)
1894+
.Returns(false)
1895+
.SetCategory("ExpressionEvaluator extend")
1896+
.SetCategory("inherits ExpressionEvaluator")
1897+
.SetCategory("Custom operators");
1898+
18781899
#endregion
18791900

18801901
#region Add a complex operator or change the parsing process

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/XExpressionEvaluator2.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected override void Init()
3131
{
3232
operatorsDictionary.Add("#", XExpressionOperator2.Sharp);
3333
operatorsDictionary.Add("love", XExpressionOperator2.Love);
34+
operatorsDictionary.Add("Not", ExpressionOperator.LogicalNegation);
3435
}
3536
}
3637

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,8 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
17131713
&& (!varFuncMatch.Groups["sign"].Success
17141714
|| stack.Count == 0
17151715
|| stack.Peek() is ExpressionOperator)
1716-
&& !operatorsDictionary.ContainsKey(varFuncMatch.Value.Trim()))
1716+
&& !operatorsDictionary.ContainsKey(varFuncMatch.Value.Trim())
1717+
&& (!operatorsDictionary.ContainsKey(varFuncMatch.Groups["name"].Value) || varFuncMatch.Groups["inObject"].Success))
17171718
{
17181719
string varFuncName = varFuncMatch.Groups["name"].Value;
17191720
string genericsTypes = varFuncMatch.Groups["isgeneric"].Value;

TryWindow/MainWindow.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
4545
evaluator.Namespaces.Add("System.Diagnostics");
4646

4747
evaluator.EvaluateVariable += Evaluator_EvaluateVariable;
48+
evaluator.EvaluateFunction += Evaluator_EvaluateFunction;
4849

4950
Stopwatch stopWatch = new Stopwatch();
5051

@@ -55,7 +56,7 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
5556
Exception exception = null;
5657
cancellationTokenSource = new CancellationTokenSource();
5758
cancellationTokenSource.Token.ThrowIfCancellationRequested();
58-
string result = await Task.Run<string>(() =>
59+
string result = await Task.Run(() =>
5960
{
6061
if (!int.TryParse(sIteration, out int iterations))
6162
iterations = 1;
@@ -104,6 +105,11 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
104105
CancelButton.IsEnabled = false;
105106
}
106107

108+
private void Evaluator_EvaluateFunction(object sender, FunctionEvaluationEventArg e)
109+
{
110+
111+
}
112+
107113
private void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e)
108114
{
109115
if (e.This != null)

0 commit comments

Comments
 (0)