mparlak / Flee

Fast Lightweight Expression Evaluator
607 stars 119 forks source link

Exception thrown: 'Flee.Parsing.grammatica_1._5.alpha2.PerCederberg.Grammatica.Runtime.RE.RegExpException' in Flee.NetStandard20.dll #46

Open ademgashi opened 5 years ago

ademgashi commented 5 years ago

I have a .net core 2.1 project doing the following

ExpressionContext context = new ExpressionContext();
                context.Imports.AddType(typeof(DateTime), "DateTime");
                VariableCollection variables = context.Variables;
                variables.Add(varName, varVal);

                IGenericExpression<object> e = context.CompileGeneric<object>(_expression);
                object result = e.Evaluate();
                LogHelper.Trace("Evaluating: object: " + varName + ", expression: " + _expression + ", result: " + result);
                return result;

ExpressionContext context = new ExpressionContext(); allways throws this exception

Flee.Parsing.grammatica_1._5.alpha2.PerCederberg.Grammatica.Runtime.RE.RegExpException

Any ideas?

ibbgomes commented 5 years ago

I have the same issue. Did you found any solution?

ademgashi commented 5 years ago

Not really I had the usage of it.

On Fri, Jun 7, 2019 at 16:36 Ivo Gomes notifications@github.com wrote:

I have the same issue. Did you found any solution?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mparlak/Flee/issues/46?email_source=notifications&email_token=ABVNF2A4ULM26Q7LAIACB7TPZJW7TA5CNFSM4F2SVEUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXGAJIQ#issuecomment-499909794, or mute the thread https://github.com/notifications/unsubscribe-auth/ABVNF2CYUGDDCUJ3PW73NJDPZJW7TANCNFSM4F2SVEUA .

--

Adem Gashi T: +383 44 937 300

[image: LinkedIn] http://www.linkedin.com/in/ademg

jballin82 commented 5 years ago

I think this problem is related to a flaw in NFA matcher's use of TokenRegExpParser.ParseAtomModifier when interpreting repeat specifiers. Specifically it generates an exception for these patterns (below) added by Flee.Parsing.ExpressionTokenizer.CreatePatterns (the repeat specifiers being the parts in curly braces). When min or max are not 0 or 1, as in the cases below, the exception is thrown.

The regexp matcher handles the patterns successfully - see Tokenizer.AddPattern()

I came to this problem because I saw this exception being logged in the Output console, and a severe degradation in performance in my application using Flee. It has affected a colleague too. It can disappear as quickly as it appears (which is absolutely bizarre of course).

It affects Net45 and NetStandard20, and problems for Debug and Release configurations.

customPattern = new RealPattern(Convert.ToInt32(ExpressionConstants.REAL), "REAL", TokenPattern.PatternType.REGEXP, "\\d{0}\\{1}\\d+([e][+-]\\d{{1,3}})?(d|f|m)?");
pattern = new TokenPattern(Convert.ToInt32(ExpressionConstants.STRING_LITERAL), "STRING_LITERAL", TokenPattern.PatternType.REGEXP, "\"([^\"\\r\\n\\\\]|\\\\u[0-9a-f]{4}|\\\\[\\\\\"'trn])*\"");
pattern = new TokenPattern(Convert.ToInt32(ExpressionConstants.CHAR_LITERAL), "CHAR_LITERAL", TokenPattern.PatternType.REGEXP, "'([^'\\r\\n\\\\]|\\\\u[0-9a-f]{4}|\\\\[\\\\\"'trn])'");
pattern = new TokenPattern(Convert.ToInt32(ExpressionConstants.TIMESPAN), "TIMESPAN", TokenPattern.PatternType.REGEXP, "##(\\d+\\.)?\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,7})?)?#");
ibbgomes commented 5 years ago

Thanks for the detailed explanation @jballin82.