Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63bc30aa7f | |||
| 44f3d58db4 | |||
| 551da30a7e | |||
| e7736f26b7 | |||
| 1a878fe4e7 | |||
| 75f5c948ed | |||
| ad9e3e6bad | |||
| 953a9340cc | |||
| 0440b418cb | |||
| 57c5f677f5 |
13
.idea/.idea.VAR.ExpressionEvaluator/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.VAR.ExpressionEvaluator/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/.idea.VAR.ExpressionEvaluator.iml
|
||||||
|
/modules.xml
|
||||||
|
/contentModel.xml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
4
.idea/.idea.VAR.ExpressionEvaluator/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.VAR.ExpressionEvaluator/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.VAR.ExpressionEvaluator/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.VAR.ExpressionEvaluator/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.VAR.ExpressionEvaluator/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.VAR.ExpressionEvaluator/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2019-2020 Valeriano Alfonso Rodriguez
|
Copyright (c) 2019-2021 Valeriano Alfonso Rodriguez
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -241,6 +241,19 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.Equal(4m, result);
|
Assert.Equal(4m, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Functions__ZeroParameters()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetFunction("constant", (parameters) =>
|
||||||
|
{
|
||||||
|
return 9m;
|
||||||
|
});
|
||||||
|
string expression = "constant()";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.Equal(9m, result);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Functions
|
#endregion Functions
|
||||||
|
|
||||||
#region Strings
|
#region Strings
|
||||||
@@ -253,6 +266,14 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.Equal("Hello World", result);
|
Assert.Equal("Hello World", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Strings__Contatenate_Hello_World_SimpleQuotes()
|
||||||
|
{
|
||||||
|
string expression = "'Hello' + ' ' +'World'";
|
||||||
|
object result = Parser.EvaluateString(expression);
|
||||||
|
Assert.Equal("Hello World", result);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Strings__Contatenate_Hello_World_WithVariables()
|
public void Strings__Contatenate_Hello_World_WithVariables()
|
||||||
{
|
{
|
||||||
@@ -547,6 +568,11 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.False((bool?)Parser.EvaluateString("true and false"));
|
Assert.False((bool?)Parser.EvaluateString("true and false"));
|
||||||
Assert.True((bool?)Parser.EvaluateString("true and true"));
|
Assert.True((bool?)Parser.EvaluateString("true and true"));
|
||||||
|
|
||||||
|
Assert.False((bool?)Parser.EvaluateString("False And False"));
|
||||||
|
Assert.False((bool?)Parser.EvaluateString("False And True"));
|
||||||
|
Assert.False((bool?)Parser.EvaluateString("True And False"));
|
||||||
|
Assert.True((bool?)Parser.EvaluateString("True And True"));
|
||||||
|
|
||||||
Assert.False((bool?)Parser.EvaluateString("false && false"));
|
Assert.False((bool?)Parser.EvaluateString("false && false"));
|
||||||
Assert.False((bool?)Parser.EvaluateString("false && true"));
|
Assert.False((bool?)Parser.EvaluateString("false && true"));
|
||||||
Assert.False((bool?)Parser.EvaluateString("true && false"));
|
Assert.False((bool?)Parser.EvaluateString("true && false"));
|
||||||
@@ -561,6 +587,11 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.True((bool?)Parser.EvaluateString("true or false"));
|
Assert.True((bool?)Parser.EvaluateString("true or false"));
|
||||||
Assert.True((bool?)Parser.EvaluateString("true or true"));
|
Assert.True((bool?)Parser.EvaluateString("true or true"));
|
||||||
|
|
||||||
|
Assert.False((bool?)Parser.EvaluateString("False Or False"));
|
||||||
|
Assert.True((bool?)Parser.EvaluateString("False Or True"));
|
||||||
|
Assert.True((bool?)Parser.EvaluateString("True Or False"));
|
||||||
|
Assert.True((bool?)Parser.EvaluateString("True Or True"));
|
||||||
|
|
||||||
Assert.False((bool?)Parser.EvaluateString("false || false"));
|
Assert.False((bool?)Parser.EvaluateString("false || false"));
|
||||||
Assert.True((bool?)Parser.EvaluateString("false || true"));
|
Assert.True((bool?)Parser.EvaluateString("false || true"));
|
||||||
Assert.True((bool?)Parser.EvaluateString("true || false"));
|
Assert.True((bool?)Parser.EvaluateString("true || false"));
|
||||||
@@ -577,7 +608,6 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.False((bool?)Parser.EvaluateString("not true"));
|
Assert.False((bool?)Parser.EvaluateString("not true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion BooleanOps
|
#endregion BooleanOps
|
||||||
|
|
||||||
#region Null value
|
#region Null value
|
||||||
@@ -621,7 +651,41 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Excepctions
|
#region String coercions
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void StringCoercions__Var1NullEqualsStringEmpty_EqualsTrue()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("v1", null);
|
||||||
|
string expression = "v1 = \"\"";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.True((bool?)result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void StringCoercions__Var1TrueStringEqualsTrue_EqualsTrue()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("v1", "True");
|
||||||
|
string expression = "v1 = true";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.True((bool?)result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void StringCoercions__Var1FalseStringEqualsFalse_EqualsTrue()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("v1", "False");
|
||||||
|
string expression = "v1 = false";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.True((bool?)result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion String coercions
|
||||||
|
|
||||||
|
#region Exceptions
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Exceptions__HelloAtEnd__UnexpectedCharactersAtEndException()
|
public void Exceptions__HelloAtEnd__UnexpectedCharactersAtEndException()
|
||||||
@@ -805,6 +869,33 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion Exceptions
|
||||||
|
|
||||||
|
#region Misc
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void Misc__MixedExpression_EqualsFalse()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("QI_86", null);
|
||||||
|
evaluationContex.SetVariable("QI_87", null);
|
||||||
|
evaluationContex.SetVariable("QI_104", null);
|
||||||
|
string expression = "( QI_86 = 0 Or QI_86 = null ) And ( QI_87 = 0 Or QI_87 = null ) And QI_104 > 0";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.False((bool?)result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void Misc__ProductWithStringDecimals_EqualsFalse()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("$1109", "1933");
|
||||||
|
evaluationContex.SetVariable("$1150", "02.00000");
|
||||||
|
string expression = "$1109 * $1150";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.Equal(3866.00000M, result);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Misc
|
#endregion Misc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
namespace VAR.ExpressionEvaluator
|
||||||
|
|
||||||
namespace VAR.ExpressionEvaluator
|
|
||||||
{
|
{
|
||||||
public class ExpressionEqualsNode : ExpressionBinaryNode
|
public class ExpressionEqualsNode : ExpressionBinaryNode
|
||||||
{
|
{
|
||||||
@@ -9,49 +7,17 @@ namespace VAR.ExpressionEvaluator
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object EqualsOp(object leftValue, object rightValue)
|
public static object EqualsOp(object leftValue, object rightValue)
|
||||||
{
|
{
|
||||||
if (leftValue is string && rightValue is string)
|
// Null
|
||||||
{
|
if (leftValue is string && string.IsNullOrEmpty(leftValue as string))
|
||||||
return string.Compare((string)leftValue, (string)rightValue) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((leftValue is string && rightValue == null) || (leftValue == null && rightValue is string))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftValue is string)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty((string)leftValue))
|
|
||||||
{
|
{
|
||||||
leftValue = null;
|
leftValue = null;
|
||||||
}
|
}
|
||||||
else
|
if (rightValue is string && string.IsNullOrEmpty(rightValue as string))
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
rightValue = null;
|
||||||
{
|
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
|
||||||
}
|
}
|
||||||
leftValue = dec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rightValue is string)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty((string)rightValue))
|
|
||||||
{
|
|
||||||
leftValue = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
|
||||||
{
|
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
|
||||||
}
|
|
||||||
rightValue = dec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftValue == null && rightValue == null)
|
if (leftValue == null && rightValue == null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -61,11 +27,85 @@ namespace VAR.ExpressionEvaluator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String
|
||||||
|
if (leftValue is string && rightValue is string)
|
||||||
|
{
|
||||||
|
return string.Compare((string)leftValue, (string)rightValue) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool
|
||||||
|
if (leftValue is bool || rightValue is bool)
|
||||||
|
{
|
||||||
|
bool? leftBool = ConvertToNullableBool(leftValue);
|
||||||
|
bool? rightBool = ConvertToNullableBool(rightValue);
|
||||||
|
return leftBool == rightBool;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decimal
|
||||||
|
if (leftValue is string)
|
||||||
|
{
|
||||||
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
|
{
|
||||||
|
leftValue = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leftValue = dec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rightValue is string)
|
||||||
|
{
|
||||||
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
|
{
|
||||||
|
rightValue = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rightValue = dec;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((leftValue is decimal) == false || (rightValue is decimal) == false)
|
if ((leftValue is decimal) == false || (rightValue is decimal) == false)
|
||||||
{
|
{
|
||||||
throw new Exception("Can't compare non decimal values");
|
return false;
|
||||||
}
|
}
|
||||||
return (decimal)leftValue == (decimal)rightValue;
|
return (decimal)leftValue == (decimal)rightValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool? ConvertToNullableBool(object value)
|
||||||
|
{
|
||||||
|
if (value is bool)
|
||||||
|
{
|
||||||
|
return (bool)value;
|
||||||
|
}
|
||||||
|
if (value is string)
|
||||||
|
{
|
||||||
|
string text = value as string;
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
decimal decValue;
|
||||||
|
if (decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decValue))
|
||||||
|
{
|
||||||
|
return decValue != 0;
|
||||||
|
}
|
||||||
|
string textLower = text.ToLower();
|
||||||
|
if (textLower == "false" || textLower == "no" || textLower == "ez" || textLower == "non" || textLower == "nein")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (textLower == "true" || textLower == "si" || textLower == "sí" || textLower == "yes" || textLower == "bai" || textLower == "oui" || textLower == "ja")
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (value is decimal)
|
||||||
|
{
|
||||||
|
return ((decimal)value) != 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
namespace VAR.ExpressionEvaluator
|
||||||
|
|
||||||
namespace VAR.ExpressionEvaluator
|
|
||||||
{
|
{
|
||||||
public class ExpressionNotEqualsNode : ExpressionBinaryNode
|
public class ExpressionNotEqualsNode : ExpressionBinaryNode
|
||||||
{
|
{
|
||||||
@@ -11,56 +9,8 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
private static object NotEqualsOp(object leftValue, object rightValue)
|
private static object NotEqualsOp(object leftValue, object rightValue)
|
||||||
{
|
{
|
||||||
if (leftValue is string && rightValue is string)
|
bool result = (bool)ExpressionEqualsNode.EqualsOp(leftValue, rightValue);
|
||||||
{
|
return !result;
|
||||||
return string.Compare((string)leftValue, (string)rightValue) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftValue is string)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty((string)leftValue))
|
|
||||||
{
|
|
||||||
leftValue = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
|
||||||
{
|
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
|
||||||
}
|
|
||||||
leftValue = dec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rightValue is string)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty((string)rightValue))
|
|
||||||
{
|
|
||||||
leftValue = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
|
||||||
{
|
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
|
||||||
}
|
|
||||||
rightValue = dec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftValue == null && rightValue == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (leftValue == null || rightValue == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((leftValue is decimal) == false || (rightValue is decimal) == false)
|
|
||||||
{
|
|
||||||
throw new Exception("Can't compare non decimal values");
|
|
||||||
}
|
|
||||||
return (decimal)leftValue != (decimal)rightValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (value is string)
|
if (value is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)value, out decimal dec) == false)
|
if (decimal.TryParse((string)value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
#region Creator
|
#region Creator
|
||||||
|
|
||||||
private ITokenizer _tokenizer;
|
private readonly ITokenizer _tokenizer;
|
||||||
|
|
||||||
public Parser(ITokenizer tokenizer)
|
public Parser(ITokenizer tokenizer)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
IExpressionNode rightNode = ParseRelations();
|
IExpressionNode rightNode = ParseRelations();
|
||||||
leftNode = new ExpressionBooleanAndNode(leftNode, rightNode);
|
leftNode = new ExpressionBooleanAndNode(leftNode, rightNode);
|
||||||
}
|
}
|
||||||
if (_tokenizer.Token == Token.Or)
|
else if (_tokenizer.Token == Token.Or)
|
||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
IExpressionNode rightNode = ParseRelations();
|
IExpressionNode rightNode = ParseRelations();
|
||||||
@@ -84,6 +84,13 @@ namespace VAR.ExpressionEvaluator
|
|||||||
IExpressionNode rightNode = ParsePlusAndMinus();
|
IExpressionNode rightNode = ParsePlusAndMinus();
|
||||||
leftNode = new ExpressionEqualsNode(leftNode, rightNode);
|
leftNode = new ExpressionEqualsNode(leftNode, rightNode);
|
||||||
}
|
}
|
||||||
|
else if (_tokenizer.Token == Token.ExclusiveEquals)
|
||||||
|
{
|
||||||
|
// TODO: Implement ExpressionExclusiveEqualsNode
|
||||||
|
_tokenizer.NextToken();
|
||||||
|
IExpressionNode rightNode = ParsePlusAndMinus();
|
||||||
|
leftNode = new ExpressionEqualsNode(leftNode, rightNode);
|
||||||
|
}
|
||||||
else if (_tokenizer.Token == Token.NotEquals)
|
else if (_tokenizer.Token == Token.NotEquals)
|
||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
@@ -232,6 +239,8 @@ namespace VAR.ExpressionEvaluator
|
|||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
var parameters = new List<IExpressionNode>();
|
var parameters = new List<IExpressionNode>();
|
||||||
|
if (_tokenizer.Token != Token.ParenthesisEnd)
|
||||||
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
parameters.Add(ParseBooleanOp());
|
parameters.Add(ParseBooleanOp());
|
||||||
@@ -242,6 +251,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (_tokenizer.Token != Token.ParenthesisEnd)
|
if (_tokenizer.Token != Token.ParenthesisEnd)
|
||||||
{
|
{
|
||||||
throw new MissingCloseParenthesisException();
|
throw new MissingCloseParenthesisException();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageId>VAR.ExpressionEvaluator</PackageId>
|
<PackageId>VAR.ExpressionEvaluator</PackageId>
|
||||||
<Title>VAR.ExpressionEvaluator</Title>
|
<Title>VAR.ExpressionEvaluator</Title>
|
||||||
<Version>0.2.4</Version>
|
<Version>0.2.8</Version>
|
||||||
<Description>Expression Evaluation Library</Description>
|
<Description>Expression Evaluation Library</Description>
|
||||||
<Authors>VAR</Authors>
|
<Authors>VAR</Authors>
|
||||||
<Company>VAR</Company>
|
<Company>VAR</Company>
|
||||||
|
|||||||
Reference in New Issue
Block a user