File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
csharp/ToolGood.Algorithm Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff 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>
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments