@@ -25,7 +25,7 @@ public class ExpressionEvaluator
2525 private static Regex endOfStringWithoutDollar = new Regex ( "^[^\" ]*[\" ]" ) ;
2626 private static Regex endOfStringInterpolationRegex = new Regex ( "^[^}\" ]*[}\" ]" ) ;
2727 private static Regex stringBeginningForEndBlockRegex = new Regex ( "[$]?[@]?[\" ]$" ) ;
28- private static Regex lambdaExpressionRegex = new Regex ( @"^\s*(?<args>(\s*[(]\s*([a-zA-Z_][a-zA-Z0-9_]*\s*([,]\s*[a-zA-Z_][a-zA-Z0-9_]*\s*)*)?[)])|[a-zA-Z_][a-zA-Z0-9_]*)\s*=>(?<expression>.*)$" ) ;
28+ private static Regex lambdaExpressionRegex = new Regex ( @"^\s*(?<args>(\s*[(]\s*([a-zA-Z_][a-zA-Z0-9_]*\s*([,]\s*[a-zA-Z_][a-zA-Z0-9_]*\s*)*)?[)])|[a-zA-Z_][a-zA-Z0-9_]*)\s*=>(?<expression>.*)$" , RegexOptions . Singleline ) ;
2929 private static Regex lambdaArgRegex = new Regex ( @"[a-zA-Z_][a-zA-Z0-9_]*" ) ;
3030
3131 private static readonly string instanceCreationWithNewKeywordRegexPattern = @"^new\s+(?<name>[a-zA-Z_][a-zA-Z0-9_.]*)\s*(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?" ;
@@ -707,53 +707,6 @@ bool TryParseStringAndParenthis(ref int index)
707707 return parsed ;
708708 }
709709
710- string GetScriptBetweenCurlyBrackets ( string parentScript , ref int index )
711- {
712- string s ;
713- string currentScript = string . Empty ;
714- int bracketCount = 1 ;
715- for ( ; index < parentScript . Length ; index ++ )
716- {
717- Match internalStringMatch = stringBeginningRegex . Match ( parentScript . Substring ( index ) ) ;
718- Match internalCharMatch = internalCharRegex . Match ( parentScript . Substring ( index ) ) ;
719-
720- if ( internalStringMatch . Success )
721- {
722- string innerString = internalStringMatch . Value + GetCodeUntilEndOfString ( parentScript . Substring ( index + internalStringMatch . Length ) , internalStringMatch ) ;
723- currentScript += innerString ;
724- index += innerString . Length - 1 ;
725- }
726- else if ( internalCharMatch . Success )
727- {
728- currentScript += internalCharMatch . Value ;
729- index += internalCharMatch . Length - 1 ;
730- }
731- else
732- {
733- s = parentScript . Substring ( index , 1 ) ;
734-
735- if ( s . Equals ( "{" ) ) bracketCount ++ ;
736-
737- if ( s . Equals ( "}" ) )
738- {
739- bracketCount -- ;
740- if ( bracketCount == 0 )
741- break ;
742- }
743-
744- currentScript += s ;
745- }
746- }
747-
748- if ( bracketCount > 0 )
749- {
750- string beVerb = bracketCount == 1 ? "is" : "are" ;
751- throw new Exception ( $ "{ bracketCount } '"+ "}" + $ "' character { beVerb } missing in script at : [{ index } ]") ;
752- }
753-
754- return currentScript ;
755- }
756-
757710 void ExecuteIfList ( )
758711 {
759712 if ( ifElseStatementsList . Count > 0 )
@@ -1758,7 +1711,12 @@ private bool GetLambdaExpression(string expr, Stack<object> stack)
17581711
17591712 ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator ( vars ) ;
17601713
1761- return expressionEvaluator . Evaluate ( lambdaExpressionMatch . Groups [ "expression" ] . Value ) ;
1714+ string lambdaBody = lambdaExpressionMatch . Groups [ "expression" ] . Value . Trim ( ) ;
1715+
1716+ if ( lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
1717+ return expressionEvaluator . ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
1718+ else
1719+ return expressionEvaluator . Evaluate ( lambdaExpressionMatch . Groups [ "expression" ] . Value ) ;
17621720 } ) ) ;
17631721
17641722 return true ;
@@ -1904,6 +1862,53 @@ private BindingFlags DetermineInstanceOrStatic(ref Type objType, ref object obj)
19041862 }
19051863 }
19061864
1865+ string GetScriptBetweenCurlyBrackets ( string parentScript , ref int index )
1866+ {
1867+ string s ;
1868+ string currentScript = string . Empty ;
1869+ int bracketCount = 1 ;
1870+ for ( ; index < parentScript . Length ; index ++ )
1871+ {
1872+ Match internalStringMatch = stringBeginningRegex . Match ( parentScript . Substring ( index ) ) ;
1873+ Match internalCharMatch = internalCharRegex . Match ( parentScript . Substring ( index ) ) ;
1874+
1875+ if ( internalStringMatch . Success )
1876+ {
1877+ string innerString = internalStringMatch . Value + GetCodeUntilEndOfString ( parentScript . Substring ( index + internalStringMatch . Length ) , internalStringMatch ) ;
1878+ currentScript += innerString ;
1879+ index += innerString . Length - 1 ;
1880+ }
1881+ else if ( internalCharMatch . Success )
1882+ {
1883+ currentScript += internalCharMatch . Value ;
1884+ index += internalCharMatch . Length - 1 ;
1885+ }
1886+ else
1887+ {
1888+ s = parentScript . Substring ( index , 1 ) ;
1889+
1890+ if ( s . Equals ( "{" ) ) bracketCount ++ ;
1891+
1892+ if ( s . Equals ( "}" ) )
1893+ {
1894+ bracketCount -- ;
1895+ if ( bracketCount == 0 )
1896+ break ;
1897+ }
1898+
1899+ currentScript += s ;
1900+ }
1901+ }
1902+
1903+ if ( bracketCount > 0 )
1904+ {
1905+ string beVerb = bracketCount == 1 ? "is" : "are" ;
1906+ throw new Exception ( $ "{ bracketCount } '" + "}" + $ "' character { beVerb } missing in script at : [{ index } ]") ;
1907+ }
1908+
1909+ return currentScript ;
1910+ }
1911+
19071912 private List < string > GetExpressionsBetweenParenthis ( string expr , ref int i , bool checkSeparator , string separator = "," )
19081913 {
19091914 List < string > expressionsList = new List < string > ( ) ;
0 commit comments