11 Commits
0_1_0 ... 0.2.2

28 changed files with 508 additions and 70 deletions

8
SharedAssemblyInfo.cs Normal file
View File

@@ -0,0 +1,8 @@
using System.Reflection;
[assembly: AssemblyCompany("VAR")]
[assembly: AssemblyCopyright("Copyright © VAR 2019-2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.2.2.0")]
[assembly: AssemblyFileVersion("0.2.2.0")]

View File

@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace VAR.ExpressionEvaluator.Tests
{
@@ -171,6 +171,17 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(50m, result);
}
[TestMethod()]
public void Variables__Var1DivideVar2()
{
EvaluationContext evaluationContex = new EvaluationContext();
evaluationContex.SetVariable("_v1", 100);
evaluationContex.SetVariable("$v2", 20);
string expression = "_v1 / $v2";
object result = Parser.EvaluateString(expression, evaluationContex);
Assert.AreEqual(5m, result);
}
#endregion Variables
#region Funcitions
@@ -188,6 +199,29 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(10m, result);
}
[TestMethod()]
public void Functions__NestedTest()
{
EvaluationContext evaluationContex = new EvaluationContext();
evaluationContex.SetVariable("linea1", 1);
evaluationContex.SetVariable("linea2", 1);
evaluationContex.SetVariable("linea4", 4);
evaluationContex.SetFunction("iif", (parameters) =>
{
if (((bool)parameters[0]) == true)
{
return parameters[1];
}
else
{
return parameters[2];
}
});
string expression = "iif(linea1>linea2,iif(linea1>linea4, linea1, iif(linea4>linea2,linea4,linea2)),iif(linea2>linea4,linea2,linea4))";
object result = Parser.EvaluateString(expression, evaluationContex);
Assert.AreEqual(4m, result);
}
#endregion Functions
#region Strings
@@ -266,6 +300,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyGreatherThan1_EqualsFalse()
{
string expression = "\"\">1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreatherThanStringEmpty_EqualsFalse()
{
string expression = "1>\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1Equals1_EqualsTrue()
{
@@ -274,6 +324,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyEquals1_EqualsFalse()
{
string expression = "\"\"=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1EqualsStringEmpty_EqualsFalse()
{
string expression = "1=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_10NotEquals1_EqualsTrue()
{
@@ -282,6 +348,46 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyNotEquals1_EqualsTrue()
{
string expression = "\"\"!=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_1NotEqualsStringEmpty_EqualsTrue()
{
string expression = "1!=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_10Different1_EqualsTrue()
{
string expression = "10<>1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyDifferent1_EqualsTrue()
{
string expression = "\"\"<>1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_1DifferentStringEmpty_EqualsTrue()
{
string expression = "1<>\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_10LessThan1_EqualsFalse()
{
@@ -290,6 +396,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyLessThan1_EqualsFalse()
{
string expression = "\"\"<1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessThanStringEmpty_EqualsFalse()
{
string expression = "1<\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreaterOrEqualThan1_EqualsTrue()
{
@@ -298,6 +420,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyGreaterOrEqualThan1_EqualsFalse()
{
string expression = "\"\">=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreaterOrEqualThanStringEmpty_EqualsFalse()
{
string expression = "1>=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessOrEqualThan1_EqualsTrue()
{
@@ -322,6 +460,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyLessOrEqualThan1_EqualsFalse()
{
string expression = "\"\"<=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessOrEqualThanStringEmpty_EqualsFalse()
{
string expression = "1<=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
#endregion Relations
#region BooleanOps
@@ -367,5 +521,45 @@ namespace VAR.ExpressionEvaluator.Tests
#endregion BooleanOps
#region Null value
[TestMethod()]
public void NullValue_NullPlusAnything_EqualsNull()
{
Assert.AreEqual(null, Parser.EvaluateString("null + 1"));
Assert.AreEqual(null, Parser.EvaluateString("null + 100"));
Assert.AreEqual(null, Parser.EvaluateString("1 + null"));
Assert.AreEqual(null, Parser.EvaluateString("100 + null"));
Assert.AreEqual(null, Parser.EvaluateString("null + null"));
}
[TestMethod()]
public void NullValue_NullMinusAnything_EqualsNull()
{
Assert.AreEqual(null, Parser.EvaluateString("null - 1"));
Assert.AreEqual(null, Parser.EvaluateString("null - 100"));
Assert.AreEqual(null, Parser.EvaluateString("1 - null"));
Assert.AreEqual(null, Parser.EvaluateString("100 - null"));
Assert.AreEqual(null, Parser.EvaluateString("null - null"));
}
[TestMethod()]
public void NullValue_NullByAnything_EqualsNull()
{
Assert.AreEqual(null, Parser.EvaluateString("null * 1"));
Assert.AreEqual(null, Parser.EvaluateString("null * 100"));
Assert.AreEqual(null, Parser.EvaluateString("1 * null"));
Assert.AreEqual(null, Parser.EvaluateString("100 * null"));
Assert.AreEqual(null, Parser.EvaluateString("null * null"));
Assert.AreEqual(null, Parser.EvaluateString("null / 1"));
Assert.AreEqual(null, Parser.EvaluateString("null / 100"));
Assert.AreEqual(null, Parser.EvaluateString("1 / null"));
Assert.AreEqual(null, Parser.EvaluateString("100 / null"));
Assert.AreEqual(null, Parser.EvaluateString("null / null"));
}
#endregion
}
}

View File

@@ -4,12 +4,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("VAR.ExpressionEvaluator.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VAR.ExpressionEvaluator.Tests")]
[assembly: AssemblyCopyright("Copyright © VAR 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("3195f0e0-9489-49ce-8fc2-627a73f80cc7")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]

View File

@@ -1,5 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace VAR.ExpressionEvaluator.Tests
{
@@ -90,9 +90,9 @@ namespace VAR.ExpressionEvaluator.Tests
}
[TestMethod()]
public void Tokenizer__Keywords()
public void Tokenizer__Identifiers()
{
var testString = "null true false";
var testString = "null true false _$variable1 $variable2 [;{}#]";
var t = new Tokenizer(new StringReader(testString));
// "null"
@@ -110,6 +110,21 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(t.Text, "false");
t.NextToken();
// "_$variable1"
Assert.AreEqual(t.Token, Token.Identifier);
Assert.AreEqual(t.Text, "_$variable1");
t.NextToken();
// "$variable2"
Assert.AreEqual(t.Token, Token.Identifier);
Assert.AreEqual(t.Text, "$variable2");
t.NextToken();
// ";{}#"
Assert.AreEqual(t.Token, Token.Identifier);
Assert.AreEqual(t.Text, ";{}#");
t.NextToken();
Assert.AreEqual(t.Token, Token.EOF);
}

View File

@@ -51,6 +51,9 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ExpressionBinaryNodeTests.cs" />
<Compile Include="ExpressionNumberNodeTests.cs" />
<Compile Include="ExpressionStringNodeTests.cs" />

View File

@@ -5,6 +5,7 @@ if exist "%windir%\Microsoft.Net\Framework\v4.0.30319" set MsBuildPath=%windir%\
if exist "%windir%\Microsoft.Net\Framework64\v4.0.30319" set MsBuildPath=%windir%\Microsoft.NET\Framework64\v4.0.30319
if exist "C:\Program Files (x86)\MSBuild\14.0\Bin" set MsBuildPath=C:\Program Files (x86)\MSBuild\14.0\Bin
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin" set MsBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin" set MsBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
set PATH=%MsBuildPath%;%PATH%
echo %MsBuildPath%

View File

@@ -39,6 +39,11 @@ namespace VAR.ExpressionEvaluator
public void SetVariable(string name, object value)
{
if (value is DBNull)
{
value = null;
}
if (value is DateTime)
{
value = ((DateTime)value).ToString("s");
@@ -60,7 +65,7 @@ namespace VAR.ExpressionEvaluator
{
if (_variables.ContainsKey(name) == false)
{
return null;
throw new Exception(string.Format("Variable {0} not found", name));
}
return _variables[name];
}

View File

@@ -9,9 +9,10 @@
private static object BooleanAndOp(object leftValue, object rightValue)
{
bool bLeftValue = ExpressionBooleanNode.ConvertToBoolean(leftValue);
bool brightValue = ExpressionBooleanNode.ConvertToBoolean(rightValue);
return bLeftValue && brightValue;
bool? bLeftValue = ExpressionBooleanNode.ConvertToBoolean(leftValue);
bool? brightValue = ExpressionBooleanNode.ConvertToBoolean(rightValue);
if (bLeftValue == null || bLeftValue == null) { return null; }
return bLeftValue.Value && brightValue.Value;
}
}
}

View File

@@ -14,8 +14,13 @@
return _value;
}
public static bool ConvertToBoolean(object value)
public static bool? ConvertToBoolean(object value)
{
if (value == null)
{
return null;
}
if (value is bool)
{
return (bool)value;

View File

@@ -10,6 +10,7 @@
private static object BooleanNotOp(object value)
{
value = ExpressionBooleanNode.ConvertToBoolean(value);
if (value == null) { return null; }
return !(bool)value;
}
}

View File

@@ -9,9 +9,10 @@
private static object BooleanOrOp(object leftValue, object rightValue)
{
bool bLeftValue = ExpressionBooleanNode.ConvertToBoolean(leftValue);
bool brightValue = ExpressionBooleanNode.ConvertToBoolean(rightValue);
return bLeftValue || brightValue;
bool? bLeftValue = ExpressionBooleanNode.ConvertToBoolean(leftValue);
bool? brightValue = ExpressionBooleanNode.ConvertToBoolean(rightValue);
if (bLeftValue == null || bLeftValue == null) { return null; }
return bLeftValue.Value || brightValue.Value;
}
}
}

View File

@@ -11,6 +11,11 @@ namespace VAR.ExpressionEvaluator
private static object DivisionOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return null;
}
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)

View File

@@ -18,19 +18,42 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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 true;
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -18,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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 is decimal) == false || (rightValue is decimal) == false)

View File

@@ -18,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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 is decimal) == false || (rightValue is decimal) == false)

View File

@@ -18,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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 is decimal) == false || (rightValue is decimal) == false)

View File

@@ -18,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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 is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,6 +11,11 @@ namespace VAR.ExpressionEvaluator
private static object MinusOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return null;
}
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)

View File

@@ -11,6 +11,11 @@ namespace VAR.ExpressionEvaluator
private static object MultiplyOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return null;
}
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)

View File

@@ -18,19 +18,42 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (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;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
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)

View File

@@ -0,0 +1,10 @@
namespace VAR.ExpressionEvaluator
{
public class ExpressionNullNode : IExpressionNode
{
public object Eval(IEvaluationContext evaluationContext)
{
return null;
}
}
}

View File

@@ -11,6 +11,11 @@ namespace VAR.ExpressionEvaluator
private static object NumberNegateOp(object value)
{
if (value == null)
{
return null;
}
if (value is string)
{
if (decimal.TryParse((string)value, out decimal dec) == false)

View File

@@ -11,6 +11,11 @@ namespace VAR.ExpressionEvaluator
private static object PlusOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return null;
}
if (leftValue is string || rightValue is string)
{
return string.Concat(Convert.ToString(leftValue), Convert.ToString(rightValue));

View File

@@ -14,10 +14,6 @@ namespace VAR.ExpressionEvaluator
public object Eval(IEvaluationContext evaluationContext)
{
object value = evaluationContext.GetVariable(_name);
if (value == null)
{
throw new Exception(string.Format("Variable {0} not found", _name));
}
return value;
}
}

View File

@@ -197,6 +197,11 @@ namespace VAR.ExpressionEvaluator
_tokenizer.NextToken();
return new ExpressionBooleanNode(false);
}
if (identifierToLower == "null")
{
_tokenizer.NextToken();
return new ExpressionNullNode();
}
string identifier = _tokenizer.Text;
_tokenizer.NextToken();
@@ -211,7 +216,7 @@ namespace VAR.ExpressionEvaluator
var parameters = new List<IExpressionNode>();
while (true)
{
parameters.Add(ParsePlusAndMinus());
parameters.Add(ParseBooleanOp());
if (_tokenizer.Token == Token.Comma)
{
_tokenizer.NextToken();

View File

@@ -4,12 +4,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("VAR.ExpressionEvaluator")]
[assembly: AssemblyDescription("Expression Evaluation Library")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("VAR")]
[assembly: AssemblyProduct("VAR.ExpressionEvaluator")]
[assembly: AssemblyCopyright("Copyright © VAR 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("74635f68-55b1-4819-84a3-9ea818d396d9")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]

View File

@@ -144,6 +144,11 @@ namespace VAR.ExpressionEvaluator
NextChar();
_currentToken = Token.LessOrEqualThan;
}
if (_currentChar == '>')
{
NextChar();
_currentToken = Token.NotEquals;
}
return;
case '&':
@@ -171,16 +176,51 @@ namespace VAR.ExpressionEvaluator
}
// Identifier
if (char.IsLetter(_currentChar))
if (IsIdentifierStartLetter(_currentChar))
{
var sb = new StringBuilder();
while (char.IsLetterOrDigit(_currentChar) || _currentChar == '_')
while (IsIdentifierLetter(_currentChar))
{
sb.Append(_currentChar);
NextChar();
if (_currentChar == '\0') { break; }
}
_text = sb.ToString();
_currentToken = Token.Identifier;
}
else if (_currentChar == '[')
{
char stringEndsWith = ']';
NextChar();
StringBuilder sbString = new StringBuilder();
while (_currentChar != stringEndsWith && _currentChar != '\0')
{
if (_currentChar != '\\')
{
sbString.Append(_currentChar);
}
else
{
NextChar();
if (_currentChar == stringEndsWith)
{
sbString.Append(stringEndsWith);
}
else
{
// FIXME: Other escaped characters
sbString.Append(_currentChar);
}
}
NextChar();
}
NextChar();
_text = sbString.ToString();
_currentToken = Token.Identifier;
}
if (_currentToken == Token.Identifier)
{
string textLowercase = _text.ToLower();
if (textLowercase == "and")
{
@@ -216,7 +256,11 @@ namespace VAR.ExpressionEvaluator
else
{
NextChar();
if (_currentChar == '\\')
if (_currentChar == stringEndsWith)
{
sbString.Append(stringEndsWith);
}
else if (_currentChar == '\\')
{
sbString.Append('\\');
}
@@ -260,5 +304,15 @@ namespace VAR.ExpressionEvaluator
throw new InvalidDataException(string.Format("Unexpected character: {0} at {1}", _currentChar, _currentPosition));
}
private static bool IsIdentifierLetter(char c)
{
return char.IsLetterOrDigit(c) || c == '_' || c == '$' || c == '#' || c == '@';
}
private static bool IsIdentifierStartLetter(char c)
{
return char.IsLetter(c) || c == '_' || c == '$' || c == '#' || c == '@';
}
}
}

View File

@@ -41,6 +41,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="EvaluationContext.cs" />
<Compile Include="ExpressionNodes\ExpressionBooleanAndNode.cs" />
<Compile Include="ExpressionNodes\ExpressionBooleanNode.cs" />
@@ -55,6 +58,7 @@
<Compile Include="ExpressionNodes\ExpressionLessThanNode.cs" />
<Compile Include="ExpressionNodes\ExpressionMultiplyNode.cs" />
<Compile Include="ExpressionNodes\ExpressionNotEqualsNode.cs" />
<Compile Include="ExpressionNodes\ExpressionNullNode.cs" />
<Compile Include="ExpressionNodes\ExpressionUnaryNode.cs" />
<Compile Include="ExpressionNodes\ExpressionBinaryNode.cs" />
<Compile Include="ExpressionNodes\ExpressionMinusNode.cs" />