Skip to content

Commit 32c8468

Browse files
author
linzhijun
committed
fix
1 parent b5d2f67 commit 32c8468

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

csharp/ToolGood.Algorithm/AlgorithmEngineHelper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,29 @@ public static FunctionBase ParseFormula(string exp)
394394
return visitor.Visit(context);
395395
}
396396

397+
/// <summary>
398+
/// 检查公式是否正确
399+
/// </summary>
400+
/// <param name="exp"></param>
401+
/// <returns></returns>
402+
public static bool CheckFormula(string exp)
403+
{
404+
if (string.IsNullOrWhiteSpace(exp)) { return false; }
405+
var stream = new AntlrCharStream(new AntlrInputStream(exp));
406+
var lexer = new mathLexer(stream);
407+
var tokens = new CommonTokenStream(lexer);
408+
var parser = new mathParser(tokens);
409+
var antlrErrorListener = new AntlrErrorListener();
410+
parser.RemoveErrorListeners();
411+
parser.AddErrorListener(antlrErrorListener);
412+
413+
var context = parser.prog();
414+
if (antlrErrorListener.IsError) {
415+
return false;
416+
}
417+
return true;
418+
}
419+
397420
/// <summary>
398421
/// 解析条件
399422
/// </summary>

csharp/ToolGood.Algorithm/ToolGood.Algorithm.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Product>ToolGood.Algorithm</Product>
2020
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2121
<SignAssembly>true</SignAssembly>
22-
<Version>5.0.0.9</Version>
22+
<Version>5.0.0.10</Version>
2323
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
2424
<DelaySign>false</DelaySign>
2525
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>

0 commit comments

Comments
 (0)