@@ -54,9 +54,9 @@ public class ExpressionEvaluator
5454 private static readonly Regex newLineCharsRegex = new Regex ( @"\r\n|\r|\n" ) ;
5555
5656 // For script only
57- private static readonly Regex blockKeywordsBeginningRegex = new Regex ( @"^\s*(?<keyword>while|for|foreach|if|else\s+if)\s*[(]" , RegexOptions . IgnoreCase ) ;
57+ private static readonly Regex blockKeywordsBeginningRegex = new Regex ( @"^\s*(?<keyword>while|for|foreach|if|else\s+if|catch )\s*[(]" , RegexOptions . IgnoreCase ) ;
5858 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)(?![a-zA-Z0-9_])" , RegexOptions . IgnoreCase ) ;
59+ private static readonly Regex blockKeywordsWithoutParenthesesBeginningRegex = new Regex ( @"^\s*(?<keyword>else|do|try|finally )(?![a-zA-Z0-9_])" , RegexOptions . IgnoreCase ) ;
6060 private static readonly Regex blockBeginningRegex = new Regex ( @"^\s*[{]" ) ;
6161 private static readonly Regex returnKeywordRegex = new Regex ( @"^return(\s+|\()" , RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
6262 private static readonly Regex nextIsEndOfExpressionRegex = new Regex ( @"^\s*[;]" ) ;
@@ -102,6 +102,13 @@ private enum IfBlockEvaluatedState
102102 ElseIf
103103 }
104104
105+ private enum TryBlockEvaluatedState
106+ {
107+ NoBlockEvaluated ,
108+ Try ,
109+ Catch
110+ }
111+
105112 #endregion
106113
107114 #region Dictionaries declarations (Primary types, number suffix, escaped chars, operators management, default vars and functions)
@@ -718,6 +725,7 @@ private object ScriptEvaluate(string script, ref bool valueReturned, ref bool br
718725 bool isContinue = continueCalled ;
719726 int startOfExpression = 0 ;
720727 IfBlockEvaluatedState ifBlockEvaluatedState = IfBlockEvaluatedState . NoBlockEvaluated ;
728+ TryBlockEvaluatedState tryBlockEvaluatedState = TryBlockEvaluatedState . NoBlockEvaluated ;
721729 List < List < string > > ifElseStatementsList = new List < List < string > > ( ) ;
722730
723731 object ManageJumpStatementsOrExpressionEval ( string expression )
@@ -808,14 +816,14 @@ void ExecuteIfList()
808816 while ( ! isReturn && ! isBreak && ! isContinue && i < script . Length )
809817 {
810818 Match blockKeywordsBeginingMatch = null ;
811- Match elseBlockKeywordsBeginingMatch = null ;
819+ Match blockKeywordsWithoutParenthesesBeginningMatch = null ;
812820
813821 if ( script . Substring ( startOfExpression , i - startOfExpression ) . Trim ( ) . Equals ( string . Empty )
814822 && ( ( blockKeywordsBeginingMatch = blockKeywordsBeginningRegex . Match ( script . Substring ( i ) ) ) . Success
815- || ( elseBlockKeywordsBeginingMatch = blockKeywordsWithoutParenthesesBeginningRegex . Match ( script . Substring ( i ) ) ) . Success ) )
823+ || ( blockKeywordsWithoutParenthesesBeginningMatch = blockKeywordsWithoutParenthesesBeginningRegex . Match ( script . Substring ( i ) ) ) . Success ) )
816824 {
817- i += blockKeywordsBeginingMatch . Success ? blockKeywordsBeginingMatch . Length : elseBlockKeywordsBeginingMatch . Length ;
818- string keyword = blockKeywordsBeginingMatch . Success ? blockKeywordsBeginingMatch . Groups [ "keyword" ] . Value . Replace ( " " , "" ) : ( elseBlockKeywordsBeginingMatch ? . Groups [ "keyword" ] . Value ?? string . Empty ) ;
825+ i += blockKeywordsBeginingMatch . Success ? blockKeywordsBeginingMatch . Length : blockKeywordsWithoutParenthesesBeginningMatch . Length ;
826+ string keyword = blockKeywordsBeginingMatch . Success ? blockKeywordsBeginingMatch . Groups [ "keyword" ] . Value . Replace ( " " , "" ) : ( blockKeywordsWithoutParenthesesBeginningMatch ? . Groups [ "keyword" ] . Value ?? string . Empty ) ;
819827 List < string > keywordAttributes = blockKeywordsBeginingMatch . Success ? GetExpressionsBetweenParenthis ( script , ref i , true , ";" ) : null ;
820828
821829 if ( blockKeywordsBeginingMatch . Success )
0 commit comments