1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.4.14.0
3
+ Version : 1.4.14.1
4
4
(if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
5
5
6
6
Author : Coding Seb
@@ -28,11 +28,9 @@ public partial class ExpressionEvaluator
28
28
{
29
29
#region Regex declarations
30
30
31
- protected const string diactiticsKeywordsRegexPattern = @"\p{L}_" ;
32
- protected const string primaryTypesGroupPattern = "(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)" ;
33
- protected const string primaryTypesRegexPattern = "(?<=^|[^" + diactiticsKeywordsRegexPattern + "])" + primaryTypesGroupPattern + "(?=[^a-zA-Z_]|$)" ;
31
+ protected const string primaryTypesRegexPattern = @"(?<=^|[^\p{L}_])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)(?=[^a-zA-Z_]|$)" ;
34
32
35
- protected static readonly Regex varOrFunctionRegEx = new Regex ( $ @ "^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern } ](?>[{ diactiticsKeywordsRegexPattern } 0 -9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern } 0 -9]))|((?<isgeneric>[<](?>([{ diactiticsKeywordsRegexPattern } ](?>[{ diactiticsKeywordsRegexPattern } 0 -9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
33
+ protected static readonly Regex varOrFunctionRegEx = new Regex ( @"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[\p{L}_ ](?>[\p{L}_0 -9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![\p{L}_0 -9]))|((?<isgeneric>[<](?>([\p{L}_ ](?>[\p{L}_0 -9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
36
34
37
35
protected const string numberRegexOrigPattern = @"^(?<sign>[+-])?([0-9][0-9_{1}]*[0-9]|\d)(?<hasdecimal>{0}?([0-9][0-9_]*[0-9]|\d)(e[+-]?([0-9][0-9_]*[0-9]|\d))?)?(?<type>ul|[fdulm])?" ;
38
36
protected string numberRegexPattern ;
@@ -41,7 +39,7 @@ public partial class ExpressionEvaluator
41
39
protected static readonly Regex stringBeginningRegex = new Regex ( "^(?<interpolated>[$])?(?<escaped>[@])?[\" ]" , RegexOptions . Compiled ) ;
42
40
protected static readonly Regex internalCharRegex = new Regex ( @"^['](\\[\\'0abfnrtv]|[^'])[']" , RegexOptions . Compiled ) ;
43
41
protected static readonly Regex indexingBeginningRegex = new Regex ( @"^[?]?\[" , RegexOptions . Compiled ) ;
44
- protected static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^(?>\s*)((?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![" + diactiticsKeywordsRegexPattern + "0 -9])))") ;
42
+ protected static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^(?>\s*)((?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![\p{L}_0 -9])))" ) ;
45
43
protected static readonly Regex genericsDecodeRegex = new Regex ( "(?<name>[^,<>]+)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?" , RegexOptions . Compiled ) ;
46
44
protected static readonly Regex genericsEndOnlyOneTrim = new Regex ( @"(?>\s*)[>](?>\s*)$" , RegexOptions . Compiled ) ;
47
45
@@ -51,13 +49,13 @@ public partial class ExpressionEvaluator
51
49
protected static readonly Regex endOfStringWithoutDollarWithAt = new Regex ( "^[^\" ]*[\" ]" , RegexOptions . Compiled ) ;
52
50
protected static readonly Regex endOfStringInterpolationRegex = new Regex ( "^('\" '|[^}\" ])*[}\" ]" , RegexOptions . Compiled ) ;
53
51
protected static readonly Regex stringBeginningForEndBlockRegex = new Regex ( "[$]?[@]?[\" ]$" , RegexOptions . Compiled ) ;
54
- protected 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 | RegexOptions . Compiled ) ;
55
- protected static readonly Regex lambdaArgRegex = new Regex ( $ "[ { diactiticsKeywordsRegexPattern } ](?>[{ diactiticsKeywordsRegexPattern } 0 -9]*)", RegexOptions . Compiled ) ;
52
+ protected static readonly Regex lambdaExpressionRegex = new Regex ( @"^(?>\s*)(?<args>((?>\s*)[(](?>\s*)([\p{L}_ ](?>[\p{L}_0 -9]*)(?>\s*)([,](?>\s*)[\p{L}_][\p{L}_0 -9]*(?>\s*))*)?[)])|[\p{L}_ ](?>[\p{L}_0 -9]*))(?>\s*)=>(?<expression>.*)$" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
53
+ protected static readonly Regex lambdaArgRegex = new Regex ( @"[\p{L}_ ](?>[\p{L}_0 -9]*)", RegexOptions . Compiled ) ;
56
54
protected static readonly Regex initInNewBeginningRegex = new Regex ( @"^(?>\s*){" , RegexOptions . Compiled ) ;
57
55
58
56
// Depending on OptionInlineNamespacesEvaluationActive. Initialized in constructor
59
- protected string InstanceCreationWithNewKeywordRegexPattern { get { return $ @ "^new(?>\s*)((?<isAnonymous>[{{])|((?<name>[{ diactiticsKeywordsRegexPattern } ][ { diactiticsKeywordsRegexPattern } 0-9 { ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) } ]*)(?>\s*)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?>\s*)((?<isfunction>[(])|(?<isArray>\[)|(?<isInit>[{{]))?))"; } }
60
- protected string CastRegexPattern { get { return $ @ "^\((?>\s*)(?<typeName>[{ diactiticsKeywordsRegexPattern } ][ { diactiticsKeywordsRegexPattern } 0-9 { ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) } \[\]<>]*[?]?)(?>\s*)\)"; } }
57
+ protected string InstanceCreationWithNewKeywordRegexPattern { get { return @"^new(?>\s*)((?<isAnonymous>[{{])|((?<name>[\p{L}_][\p{L}_0-9" + ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) + @" ]*)(?>\s*)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?>\s*)((?<isfunction>[(])|(?<isArray>\[)|(?<isInit>[{{]))?))"; } }
58
+ protected string CastRegexPattern { get { return @"^\((?>\s*)(?<typeName>[\p{L}_][\p{L}_0-9" + ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) + @" \[\]<>]*[?]?)(?>\s*)\)"; } }
61
59
62
60
// To remove comments in scripts based on https://stackoverflow.com/questions/3524317/regex-to-strip-line-comments-from-c-sharp/3524689#3524689
63
61
protected const string blockComments = @"/\*(.*?)\*/" ;
@@ -69,8 +67,8 @@ public partial class ExpressionEvaluator
69
67
70
68
// For script only
71
69
protected static readonly Regex blockKeywordsBeginningRegex = new Regex ( @"^(?>\s*)(?<keyword>while|for|foreach|if|else(?>\s*)if|catch)(?>\s*)[(]" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
72
- protected static readonly Regex foreachParenthisEvaluationRegex = new Regex ( @"^(?>\s*)(?<variableName>[" + diactiticsKeywordsRegexPattern + " ](?>[" + diactiticsKeywordsRegexPattern + @"0 -9]*))(?>\s*)(?<in>in)(?>\s*)(?<collection>.*)", RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
73
- protected static readonly Regex blockKeywordsWithoutParenthesesBeginningRegex = new Regex ( @"^(?>\s*)(?<keyword>else|do|try|finally)(?![" + diactiticsKeywordsRegexPattern + "0 -9])", RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
70
+ protected static readonly Regex foreachParenthisEvaluationRegex = new Regex ( @"^(?>\s*)(?<variableName>[\p{L}_ ](?>[\p{L}_0 -9]*))(?>\s*)(?<in>in)(?>\s*)(?<collection>.*)" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
71
+ protected static readonly Regex blockKeywordsWithoutParenthesesBeginningRegex = new Regex ( @"^(?>\s*)(?<keyword>else|do|try|finally)(?![\p{L}_0 -9])" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
74
72
protected static readonly Regex blockBeginningRegex = new Regex ( @"^(?>\s*)[{]" , RegexOptions . Compiled ) ;
75
73
protected static readonly Regex returnKeywordRegex = new Regex ( @"^return((?>\s*)|\()" , RegexOptions . IgnoreCase | RegexOptions . Singleline | RegexOptions . Compiled ) ;
76
74
protected static readonly Regex nextIsEndOfExpressionRegex = new Regex ( @"^(?>\s*)[;]" , RegexOptions . Compiled ) ;
0 commit comments