@@ -30,8 +30,10 @@ public partial class ExpressionEvaluator
30
30
31
31
protected const string diactitics = "áàâãåǎăāąæéèêëěēĕėęěìíîïīĭįijóôõöōŏőøðœùúûüǔũūŭůűųýþÿŷıćĉċčçďđĝğġģĥħĵķĺļľŀłńņňŋñŕŗřśŝşšţťŧŵźżžÁÀÂÃÅǍĂĀĄÆÉÈÊËĚĒĔĖĘĚÌÍÎÏĪĬĮIJÓÔÕÖŌŎŐØÐŒÙÚÛÜǓŨŪŬŮŰŲÝÞŸŶIĆĈĊČÇĎĐĜĞĠĢĤĦĴĶĹĻĽĿŁŃŅŇŊÑŔŖŘŚŜŞŠŢŤŦŴŹŻŽß" ;
32
32
protected const string diactiticsKeywordsRegexPattern = "a-zA-Z_" + diactitics ;
33
+ protected const string primaryTypesGroupPattern = "(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)" ;
34
+ protected const string primaryTypesRegexPattern = "(?<=^|[^" + diactiticsKeywordsRegexPattern + "])" + primaryTypesGroupPattern + "(?=[^a-zA-Z_]|$)" ;
33
35
34
- protected static readonly Regex varOrFunctionRegEx = new Regex ( $@ "^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var\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 ) ;
36
+ protected static readonly Regex varOrFunctionRegEx = new Regex ( $@ "^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var) \s+|(?<dynamicKeyword>dynamic)\s+| { primaryTypesGroupPattern } \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 ) ;
35
37
36
38
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])?" ;
37
39
protected string numberRegexPattern = null ;
@@ -58,8 +60,6 @@ public partial class ExpressionEvaluator
58
60
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>[{{]))?))"; } }
59
61
protected string CastRegexPattern { get { return $@ "^\((?>\s*)(?<typeName>[{ diactiticsKeywordsRegexPattern } ][{ diactiticsKeywordsRegexPattern } 0-9{ ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) } \[\]<>]*[?]?)(?>\s*)\)"; } }
60
62
61
- protected const string primaryTypesRegexPattern = "(?<=^|[^" + diactiticsKeywordsRegexPattern + "])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)(?=[^a-zA-Z_]|$)" ;
62
-
63
63
// To remove comments in scripts based on https://stackoverflow.com/questions/3524317/regex-to-strip-line-comments-from-c-sharp/3524689#3524689
64
64
protected const string blockComments = @"/\*(.*?)\*/" ;
65
65
protected const string lineComments = @"//[^\r\n]*" ;
@@ -950,6 +950,8 @@ protected virtual object ScriptEvaluate(string script, ref bool valueReturned, r
950
950
List < List < string > > ifElseStatementsList = new List < List < string > > ( ) ;
951
951
List < List < string > > tryStatementsList = new List < List < string > > ( ) ;
952
952
953
+ script = script . TrimEnd ( ) ;
954
+
953
955
object ManageJumpStatementsOrExpressionEval ( string expression )
954
956
{
955
957
expression = expression . Trim ( ) ;
@@ -1343,16 +1345,20 @@ void forAction(int index)
1343
1345
{
1344
1346
ExecuteBlocksStacks ( ) ;
1345
1347
1346
- if ( TryParseStringAndParenthisAndCurlyBrackets ( ref i ) ) { }
1348
+ bool executed = false ;
1349
+
1350
+ if ( TryParseStringAndParenthisAndCurlyBrackets ( ref i ) ) { }
1347
1351
else if ( script . Length - i > 2 && script . Substring ( i , 3 ) . Equals ( "';'" ) )
1348
1352
{
1349
1353
i += 2 ;
1350
1354
}
1351
1355
else if ( script [ i ] == ';' )
1352
1356
{
1353
1357
lastResult = ScriptExpressionEvaluate ( ref i ) ;
1358
+ executed = true ;
1354
1359
}
1355
- else if ( ! OptionScriptNeedSemicolonAtTheEndOfLastExpression && i == script . Length - 1 )
1360
+
1361
+ if ( ! OptionScriptNeedSemicolonAtTheEndOfLastExpression && i == script . Length - 1 && ! executed )
1356
1362
{
1357
1363
i ++ ;
1358
1364
lastResult = ScriptExpressionEvaluate ( ref i ) ;
@@ -1362,12 +1368,12 @@ void forAction(int index)
1362
1368
ifBlockEvaluatedState = IfBlockEvaluatedState . NoBlockEvaluated ;
1363
1369
tryBlockEvaluatedState = TryBlockEvaluatedState . NoBlockEvaluated ;
1364
1370
1365
- if ( OptionScriptNeedSemicolonAtTheEndOfLastExpression || i < script . Length - 1 )
1371
+ if ( OptionScriptNeedSemicolonAtTheEndOfLastExpression || i < script . Length )
1366
1372
i ++ ;
1367
1373
}
1368
1374
}
1369
1375
1370
- if ( ! script . Substring ( startOfExpression ) . Trim ( ) . Equals ( string . Empty ) && ! isReturn && ! isBreak && ! isContinue )
1376
+ if ( ! script . Substring ( startOfExpression ) . Trim ( ) . Equals ( string . Empty ) && ! isReturn && ! isBreak && ! isContinue && OptionScriptNeedSemicolonAtTheEndOfLastExpression )
1371
1377
throw new ExpressionEvaluatorSyntaxErrorException ( "A [;] character is missing." ) ;
1372
1378
1373
1379
ExecuteBlocksStacks ( ) ;
@@ -1718,7 +1724,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1718
1724
if ( varFuncMatch . Groups [ "varKeyword" ] . Success
1719
1725
&& ! varFuncMatch . Groups [ "assignationOperator" ] . Success )
1720
1726
{
1721
- throw new ExpressionEvaluatorSyntaxErrorException ( "Implicit variables must be initialized" ) ;
1727
+ throw new ExpressionEvaluatorSyntaxErrorException ( "Implicit variables must be initialized. [var " + varFuncMatch . Groups [ "name" ] . Value + "] ") ;
1722
1728
}
1723
1729
1724
1730
if ( varFuncMatch . Success
0 commit comments