Skip to content

Commit a4da0aa

Browse files
authored
Support for parsing Binary Integer (#554)
1 parent 2eeb663 commit a4da0aa

12 files changed

+311
-207
lines changed

System.Linq.Dynamic.Core.sln

-19
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore2.0_EF2.1
5454
EndProject
5555
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore2.1_EF2.1.1", "src-console\ConsoleAppEF2.1.1\ConsoleApp_netcore2.1_EF2.1.1.csproj", "{F1880F07-238F-4A3A-9E58-141350665E1F}"
5656
EndProject
57-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppPerformanceTest236", "src-console\ConsoleAppPerformanceTest236\ConsoleAppPerformanceTest236.csproj", "{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}"
58-
EndProject
5957
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp_net452_EF6_Effort", "src-console\ConsoleApp_net452_EF6_Effort\ConsoleApp_net452_EF6_Effort.csproj", "{36B101B1-720B-4770-B222-C6ADD464F9EC}"
6058
EndProject
6159
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Z.EntityFramework.Classic.DynamicLinq", "src\Z.EntityFramework.Classic.DynamicLinq\Z.EntityFramework.Classic.DynamicLinq.csproj", "{D3804228-91F4-4502-9595-39584EA20000}"
@@ -337,22 +335,6 @@ Global
337335
{F1880F07-238F-4A3A-9E58-141350665E1F}.Release|x64.Build.0 = Release|Any CPU
338336
{F1880F07-238F-4A3A-9E58-141350665E1F}.Release|x86.ActiveCfg = Release|Any CPU
339337
{F1880F07-238F-4A3A-9E58-141350665E1F}.Release|x86.Build.0 = Release|Any CPU
340-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
341-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|Any CPU.Build.0 = Debug|Any CPU
342-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|ARM.ActiveCfg = Debug|Any CPU
343-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|ARM.Build.0 = Debug|Any CPU
344-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|x64.ActiveCfg = Debug|Any CPU
345-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|x64.Build.0 = Debug|Any CPU
346-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|x86.ActiveCfg = Debug|Any CPU
347-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Debug|x86.Build.0 = Debug|Any CPU
348-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|Any CPU.ActiveCfg = Release|Any CPU
349-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|Any CPU.Build.0 = Release|Any CPU
350-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|ARM.ActiveCfg = Release|Any CPU
351-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|ARM.Build.0 = Release|Any CPU
352-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|x64.ActiveCfg = Release|Any CPU
353-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|x64.Build.0 = Release|Any CPU
354-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|x86.ActiveCfg = Release|Any CPU
355-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84}.Release|x86.Build.0 = Release|Any CPU
356338
{36B101B1-720B-4770-B222-C6ADD464F9EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
357339
{36B101B1-720B-4770-B222-C6ADD464F9EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
358340
{36B101B1-720B-4770-B222-C6ADD464F9EC}.Debug|ARM.ActiveCfg = Debug|Any CPU
@@ -743,7 +725,6 @@ Global
743725
{437473EE-7FBB-4C28-96EC-41E1AEE161F3} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
744726
{EDF434F6-70C0-4005-B63E-0C365B3DA42A} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
745727
{F1880F07-238F-4A3A-9E58-141350665E1F} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
746-
{E9C52E5E-28DC-4D45-B9AB-1B2CF2924A84} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
747728
{36B101B1-720B-4770-B222-C6ADD464F9EC} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
748729
{D3804228-91F4-4502-9595-39584EA20000} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
749730
{0077F262-D69B-44D2-8A7C-87D8D19022A6} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}

src/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore5/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore5.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Description>Dynamic Linq extensions for Microsoft.EntityFrameworkCore which adds Async support</Description>
77
<AssemblyTitle>Microsoft.EntityFrameworkCore.DynamicLinq</AssemblyTitle>
88
<Authors>ZZZ Projects;Stef Heyenrath</Authors>
9-
<TargetFrameworks>netstandard2.1</TargetFrameworks>
9+
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
1010
<DefineConstants>$(DefineConstants);EFCORE;EFCORE_3X;EFDYNAMICFUNCTIONS</DefineConstants>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1212
<AssemblyName>Microsoft.EntityFrameworkCore.DynamicLinq</AssemblyName>
@@ -58,7 +58,6 @@
5858

5959
<ItemGroup>
6060
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" PrivateAssets="All" />
61-
6261
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
6362
</ItemGroup>
6463
</Project>

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

+5-120
Original file line numberDiff line numberDiff line change
@@ -809,94 +809,12 @@ Expression ParseIntegerLiteral()
809809
_textParser.ValidateToken(TokenId.IntegerLiteral);
810810

811811
string text = _textParser.CurrentToken.Text;
812-
string qualifier = null;
813-
char last = text[text.Length - 1];
814-
bool isHexadecimal = text.StartsWith(text[0] == '-' ? "-0x" : "0x", StringComparison.OrdinalIgnoreCase);
815-
char[] qualifierLetters = isHexadecimal
816-
? new[] { 'U', 'u', 'L', 'l' }
817-
: new[] { 'U', 'u', 'L', 'l', 'F', 'f', 'D', 'd', 'M', 'm' };
818812

819-
if (qualifierLetters.Contains(last))
820-
{
821-
int pos = text.Length - 1, count = 0;
822-
while (qualifierLetters.Contains(text[pos]))
823-
{
824-
++count;
825-
--pos;
826-
}
827-
qualifier = text.Substring(text.Length - count, count);
828-
text = text.Substring(0, text.Length - count);
829-
}
830-
831-
if (text[0] != '-')
832-
{
833-
if (isHexadecimal)
834-
{
835-
text = text.Substring(2);
836-
}
837-
838-
if (!ulong.TryParse(text, isHexadecimal ? NumberStyles.HexNumber : NumberStyles.Integer, _parsingConfig.NumberParseCulture, out ulong value))
839-
{
840-
throw ParseError(Res.InvalidIntegerLiteral, text);
841-
}
842-
843-
_textParser.NextToken();
844-
if (!string.IsNullOrEmpty(qualifier))
845-
{
846-
if (qualifier == "U" || qualifier == "u") return ConstantExpressionHelper.CreateLiteral((uint)value, text);
847-
if (qualifier == "L" || qualifier == "l") return ConstantExpressionHelper.CreateLiteral((long)value, text);
848-
849-
// in case of UL, just return
850-
return ConstantExpressionHelper.CreateLiteral(value, text);
851-
}
813+
var tokenPosition = _textParser.CurrentToken.Pos;
852814

853-
// if (value <= (int)short.MaxValue) return ConstantExpressionHelper.CreateLiteral((short)value, text);
854-
if (value <= int.MaxValue) return ConstantExpressionHelper.CreateLiteral((int)value, text);
855-
if (value <= uint.MaxValue) return ConstantExpressionHelper.CreateLiteral((uint)value, text);
856-
if (value <= long.MaxValue) return ConstantExpressionHelper.CreateLiteral((long)value, text);
857-
858-
return ConstantExpressionHelper.CreateLiteral(value, text);
859-
}
860-
else
861-
{
862-
if (isHexadecimal)
863-
{
864-
text = text.Substring(3);
865-
}
866-
867-
if (!long.TryParse(text, isHexadecimal ? NumberStyles.HexNumber : NumberStyles.Integer, _parsingConfig.NumberParseCulture, out long value))
868-
{
869-
throw ParseError(Res.InvalidIntegerLiteral, text);
870-
}
871-
872-
if (isHexadecimal)
873-
{
874-
value = -value;
875-
}
876-
877-
_textParser.NextToken();
878-
if (!string.IsNullOrEmpty(qualifier))
879-
{
880-
if (qualifier == "L" || qualifier == "l")
881-
{
882-
return ConstantExpressionHelper.CreateLiteral(value, text);
883-
}
884-
885-
if (qualifier == "F" || qualifier == "f" || qualifier == "D" || qualifier == "d" || qualifier == "M" || qualifier == "m")
886-
{
887-
return ParseRealLiteral(text, qualifier[0], false);
888-
}
889-
890-
throw ParseError(Res.MinusCannotBeAppliedToUnsignedInteger);
891-
}
892-
893-
if (value <= int.MaxValue)
894-
{
895-
return ConstantExpressionHelper.CreateLiteral((int)value, text);
896-
}
897-
898-
return ConstantExpressionHelper.CreateLiteral(value, text);
899-
}
815+
var constantExpression = _numberParser.ParseIntegerLiteral(tokenPosition, text);
816+
_textParser.NextToken();
817+
return constantExpression;
900818
}
901819

902820
Expression ParseRealLiteral()
@@ -907,40 +825,7 @@ Expression ParseRealLiteral()
907825

908826
_textParser.NextToken();
909827

910-
return ParseRealLiteral(text, text[text.Length - 1], true);
911-
}
912-
913-
Expression ParseRealLiteral(string text, char qualifier, bool stripQualifier)
914-
{
915-
object o;
916-
switch (qualifier)
917-
{
918-
case 'f':
919-
case 'F':
920-
o = _numberParser.ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(float));
921-
break;
922-
923-
case 'm':
924-
case 'M':
925-
o = _numberParser.ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(decimal));
926-
break;
927-
928-
case 'd':
929-
case 'D':
930-
o = _numberParser.ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(double));
931-
break;
932-
933-
default:
934-
o = _numberParser.ParseNumber(text, typeof(double));
935-
break;
936-
}
937-
938-
if (o != null)
939-
{
940-
return ConstantExpressionHelper.CreateLiteral(o, text);
941-
}
942-
943-
throw ParseError(Res.InvalidRealLiteral, text);
828+
return _numberParser.ParseRealLiteral(text, text[text.Length - 1], true);
944829
}
945830

946831
Expression ParseParenExpression()

0 commit comments

Comments
 (0)