@@ -48,6 +48,8 @@ public class ExpressionEvaluator
4848 private static readonly Regex blockBeginningRegex = new Regex ( @"^\s*[{]" ) ;
4949 private static readonly Regex returnKeywordRegex = new Regex ( @"^return(\s+|\()" , RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
5050
51+ private static readonly string tryToMatchSetPropertyRegexPattern = @"^(?<toEvaluate>([a-zA-Z_][a-zA-Z0-9_]*\s*(?<isgeneric>[(](?>[^()""]+|(?<parenthis>[(])|(?<-parenthis>[)]))*(?(parenthis) (?!))[)])*\.)+)(?<propertyToSet>[a-zA-Z_] [a-zA-Z0-9_]*)" ;
52+
5153 #endregion
5254
5355 #region enums (Operators, if else blocks states)
@@ -632,6 +634,8 @@ public ExpressionEvaluator(Dictionary<string, object> variables) : this()
632634
633635 #region Main evaluate methods (Expressions and scripts ==> public)
634636
637+ private bool inScript = false ;
638+
635639 /// <summary>
636640 /// Evaluate a script (multiple expressions separated by semicolon)
637641 /// Support Assignation with [=] (for simple variable write in the Variables dictionary)
@@ -654,18 +658,26 @@ public T ScriptEvaluate<T>(string script)
654658 /// <returns>The result of the last evaluated expression</returns>
655659 public object ScriptEvaluate ( string script )
656660 {
657- bool isReturn = false ;
658- bool isBreak = false ;
659- bool isContinue = false ;
661+ inScript = true ;
662+ try
663+ {
664+ bool isReturn = false ;
665+ bool isBreak = false ;
666+ bool isContinue = false ;
660667
661- object result = ScriptEvaluate ( script , ref isReturn , ref isBreak , ref isContinue ) ;
668+ object result = ScriptEvaluate ( script , ref isReturn , ref isBreak , ref isContinue ) ;
662669
663- if ( isBreak )
664- throw new ExpressionEvaluatorSyntaxErrorException ( "[break] keyword executed outside a loop" ) ;
665- else if ( isContinue )
666- throw new ExpressionEvaluatorSyntaxErrorException ( "[continue] keyword executed outside a loop" ) ;
667- else
668- return result ;
670+ if ( isBreak )
671+ throw new ExpressionEvaluatorSyntaxErrorException ( "[break] keyword executed outside a loop" ) ;
672+ else if ( isContinue )
673+ throw new ExpressionEvaluatorSyntaxErrorException ( "[continue] keyword executed outside a loop" ) ;
674+ else
675+ return result ;
676+ }
677+ finally
678+ {
679+ inScript = false ;
680+ }
669681 }
670682
671683 private object ScriptEvaluate ( string script , ref bool valueReturned , ref bool breakCalled , ref bool continueCalled )
@@ -948,6 +960,8 @@ void forAction(int index)
948960 breakCalled = isBreak ;
949961 continueCalled = isContinue ;
950962
963+ inScript = false ;
964+
951965 if ( isReturn || OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnAutomaticallyLastEvaluatedExpression )
952966 return lastResult ;
953967 else if ( OptionOnNoReturnKeywordFoundInScriptAction == OptionOnNoReturnKeywordFoundInScriptAction . ReturnNull )
@@ -1813,7 +1827,7 @@ private bool GetLambdaExpression(string expr, Stack<object> stack)
18131827
18141828 string lambdaBody = lambdaExpressionMatch . Groups [ "expression" ] . Value . Trim ( ) ;
18151829
1816- if ( lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
1830+ if ( inScript && lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
18171831 return expressionEvaluator . ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
18181832 else
18191833 return expressionEvaluator . Evaluate ( lambdaExpressionMatch . Groups [ "expression" ] . Value ) ;
0 commit comments