11/******************************************************************************************************
22 Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3- Version : 1.2.1.3
3+ Version : 1.2.1.4
44 (if last digit not zero version is an intermediate version and can be unstable)
55
66 Author : Coding Seb
@@ -26,23 +26,25 @@ public class ExpressionEvaluator
2626 {
2727 #region Regex declarations
2828
29- private static readonly Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ_][a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ0-9_]*)\s*((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![a-zA-Z0-9_]))|((?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
29+ private static readonly string diactiticsKeywordsRegexPattern = "a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ_" ;
30+
31+ private static readonly Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9]*)\s*((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![" + diactiticsKeywordsRegexPattern + @"0-9]))|((?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
3032 private static readonly Regex numberRegex = new Regex ( @"^(?<sign>[+-])?\d+(?<hasdecimal>\.?\d+(e[+-]?\d+)?)?(?<type>ul|[fdulm])?" , RegexOptions . IgnoreCase ) ;
3133 private static readonly Regex stringBeginningRegex = new Regex ( "^(?<interpolated>[$])?(?<escaped>[@])?[\" ]" ) ;
3234 private static readonly Regex internalCharRegex = new Regex ( @"^['](\\[']|[^'])*[']" ) ;
33- private static readonly Regex castRegex = new Regex ( @"^\(\s*(?<typeName>[a-zA-Z_][a-zA-Z0-9_ \.\[\]<>]*[?]?)\s*\)" ) ;
35+ private static readonly Regex castRegex = new Regex ( @"^\(\s*(?<typeName>[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 \.\[\]<>]*[?]?)\s*\)") ;
3436 private static readonly Regex indexingBeginningRegex = new Regex ( @"^[?]?\[" ) ;
35- private static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^\s*((?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![a-zA-Z0-9_ ])))" ) ;
37+ private static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^\s*((?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![" + diactiticsKeywordsRegexPattern + @"0-9 ])))") ;
3638 private static readonly Regex endOfStringWithDollar = new Regex ( "^[^\" {]*[\" {]" ) ;
3739 private static readonly Regex endOfStringWithoutDollar = new Regex ( "^[^\" ]*[\" ]" ) ;
3840 private static readonly Regex endOfStringInterpolationRegex = new Regex ( "^[^}\" ]*[}\" ]" ) ;
3941 private static readonly Regex stringBeginningForEndBlockRegex = new Regex ( "[$]?[@]?[\" ]$" ) ;
40- private static readonly Regex lambdaExpressionRegex = new Regex ( @"^\s*(?<args>(\s*[(]\s*([a-zA-Z_][a-zA-Z0-9_ ]*\s*([,]\s*[a-zA-Z_][a-zA-Z0-9_ ]*\s*)*)?[)])|[a-zA-Z_][a-zA-Z0-9_ ]*)\s*=>(?<expression>.*)$" , RegexOptions . Singleline ) ;
41- private static readonly Regex lambdaArgRegex = new Regex ( @"[a-zA-Z_][a-zA-Z0-9_ ]*" ) ;
42+ private static readonly Regex lambdaExpressionRegex = new Regex ( @"^\s*(?<args>(\s*[(]\s*([" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 ]*\s*([,]\s*[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 ]*\s*)*)?[)])|[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 ]*)\s*=>(?<expression>.*)$", RegexOptions . Singleline ) ;
43+ private static readonly Regex lambdaArgRegex = new Regex ( @"[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 ]*") ;
4244
43- private static readonly string instanceCreationWithNewKeywordRegexPattern = @"^new\s+(?<name>[a-zA-Z_][a-zA-Z0-9_ .]*)\s*(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?" ;
45+ private static readonly string instanceCreationWithNewKeywordRegexPattern = @"^new\s+(?<name>[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 .]*)\s*(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?";
4446 private Regex instanceCreationWithNewKeywordRegex = new Regex ( instanceCreationWithNewKeywordRegexPattern ) ;
45- private static readonly string primaryTypesRegexPattern = @"(?<=^|[^a-zA-Z_ ])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|void)(?=[^a-zA-Z_]|$)" ;
47+ private static readonly string primaryTypesRegexPattern = @"(?<=^|[^" + diactiticsKeywordsRegexPattern + @" ])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|void)(?=[^a-zA-Z_]|$)";
4648 private Regex primaryTypesRegex = new Regex ( primaryTypesRegexPattern ) ;
4749
4850 // To remove comments in scripts based on https://stackoverflow.com/questions/3524317/regex-to-strip-line-comments-from-c-sharp/3524689#3524689
@@ -55,8 +57,8 @@ public class ExpressionEvaluator
5557
5658 // For script only
5759 private static readonly Regex blockKeywordsBeginningRegex = new Regex ( @"^\s*(?<keyword>while|for|foreach|if|else\s+if|catch)\s*[(]" , RegexOptions . IgnoreCase ) ;
58- private static readonly Regex foreachParenthisEvaluationRegex = new Regex ( @"^\s*(?<variableName>[a-zA-Z_][a-zA-Z0-9_ ]*)\s+(?<in>in)\s+(?<collection>.*)" , RegexOptions . IgnoreCase ) ;
59- private static readonly Regex blockKeywordsWithoutParenthesesBeginningRegex = new Regex ( @"^\s*(?<keyword>else|do|try|finally)(?![a-zA-Z0-9_ ])" , RegexOptions . IgnoreCase ) ;
60+ private static readonly Regex foreachParenthisEvaluationRegex = new Regex ( @"^\s*(?<variableName>[" + diactiticsKeywordsRegexPattern + @"][" + diactiticsKeywordsRegexPattern + @"0-9 ]*)\s+(?<in>in)\s+(?<collection>.*)", RegexOptions . IgnoreCase ) ;
61+ private static readonly Regex blockKeywordsWithoutParenthesesBeginningRegex = new Regex ( @"^\s*(?<keyword>else|do|try|finally)(?![" + diactiticsKeywordsRegexPattern + @"0-9 ])", RegexOptions . IgnoreCase ) ;
6062 private static readonly Regex blockBeginningRegex = new Regex ( @"^\s*[{]" ) ;
6163 private static readonly Regex returnKeywordRegex = new Regex ( @"^return(\s+|\()" , RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
6264 private static readonly Regex nextIsEndOfExpressionRegex = new Regex ( @"^\s*[;]" ) ;
0 commit comments