@@ -30,8 +30,10 @@ public partial class ExpressionEvaluator
3030
3131 protected const string diactitics = "áàâãåǎăāąæéèêëěēĕėęěìíîïīĭįijóôõöōŏőøðœùúûüǔũūŭůűųýþÿŷıćĉċčçďđĝğġģĥħĵķĺļľŀłńņňŋñŕŗřśŝşšţťŧŵźżžÁÀÂÃÅǍĂĀĄÆÉÈÊËĚĒĔĖĘĚÌÍÎÏĪĬĮIJÓÔÕÖŌŎŐØÐŒÙÚÛÜǓŨŪŬŮŰŲÝÞŸŶIĆĈĊČÇĎĐĜĞĠĢĤĦĴĶĹĻĽĿŁŃŅŇŊÑŔŖŘŚŜŞŠŢŤŦŴŹŻŽß" ;
3232 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_]|$)" ;
3335
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 ) ;
3537
3638 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])?" ;
3739 protected string numberRegexPattern = null ;
@@ -58,8 +60,6 @@ public partial class ExpressionEvaluator
5860 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>[{{]))?))"; } }
5961 protected string CastRegexPattern { get { return $@ "^\((?>\s*)(?<typeName>[{ diactiticsKeywordsRegexPattern } ][{ diactiticsKeywordsRegexPattern } 0-9{ ( OptionInlineNamespacesEvaluationActive ? @"\." : string . Empty ) } \[\]<>]*[?]?)(?>\s*)\)"; } }
6062
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-
6363 // To remove comments in scripts based on https://stackoverflow.com/questions/3524317/regex-to-strip-line-comments-from-c-sharp/3524689#3524689
6464 protected const string blockComments = @"/\*(.*?)\*/" ;
6565 protected const string lineComments = @"//[^\r\n]*" ;
@@ -950,6 +950,8 @@ protected virtual object ScriptEvaluate(string script, ref bool valueReturned, r
950950 List < List < string > > ifElseStatementsList = new List < List < string > > ( ) ;
951951 List < List < string > > tryStatementsList = new List < List < string > > ( ) ;
952952
953+ script = script . TrimEnd ( ) ;
954+
953955 object ManageJumpStatementsOrExpressionEval ( string expression )
954956 {
955957 expression = expression . Trim ( ) ;
@@ -1343,16 +1345,20 @@ void forAction(int index)
13431345 {
13441346 ExecuteBlocksStacks ( ) ;
13451347
1346- if ( TryParseStringAndParenthisAndCurlyBrackets ( ref i ) ) { }
1348+ bool executed = false ;
1349+
1350+ if ( TryParseStringAndParenthisAndCurlyBrackets ( ref i ) ) { }
13471351 else if ( script . Length - i > 2 && script . Substring ( i , 3 ) . Equals ( "';'" ) )
13481352 {
13491353 i += 2 ;
13501354 }
13511355 else if ( script [ i ] == ';' )
13521356 {
13531357 lastResult = ScriptExpressionEvaluate ( ref i ) ;
1358+ executed = true ;
13541359 }
1355- else if ( ! OptionScriptNeedSemicolonAtTheEndOfLastExpression && i == script . Length - 1 )
1360+
1361+ if ( ! OptionScriptNeedSemicolonAtTheEndOfLastExpression && i == script . Length - 1 && ! executed )
13561362 {
13571363 i ++ ;
13581364 lastResult = ScriptExpressionEvaluate ( ref i ) ;
@@ -1362,12 +1368,12 @@ void forAction(int index)
13621368 ifBlockEvaluatedState = IfBlockEvaluatedState . NoBlockEvaluated ;
13631369 tryBlockEvaluatedState = TryBlockEvaluatedState . NoBlockEvaluated ;
13641370
1365- if ( OptionScriptNeedSemicolonAtTheEndOfLastExpression || i < script . Length - 1 )
1371+ if ( OptionScriptNeedSemicolonAtTheEndOfLastExpression || i < script . Length )
13661372 i ++ ;
13671373 }
13681374 }
13691375
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 )
13711377 throw new ExpressionEvaluatorSyntaxErrorException ( "A [;] character is missing." ) ;
13721378
13731379 ExecuteBlocksStacks ( ) ;
@@ -1718,7 +1724,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
17181724 if ( varFuncMatch . Groups [ "varKeyword" ] . Success
17191725 && ! varFuncMatch . Groups [ "assignationOperator" ] . Success )
17201726 {
1721- throw new ExpressionEvaluatorSyntaxErrorException ( "Implicit variables must be initialized" ) ;
1727+ throw new ExpressionEvaluatorSyntaxErrorException ( "Implicit variables must be initialized. [var " + varFuncMatch . Groups [ "name" ] . Value + "] ") ;
17221728 }
17231729
17241730 if ( varFuncMatch . Success
0 commit comments