Skip to content

Commit f8eefa2

Browse files
author
Sébastien Geiser
committed
Add OptionScriptNeedSemicolonAtTheEndOfLastExpression
+ Tests
1 parent 7ef014e commit f8eefa2

File tree

8 files changed

+321
-235
lines changed

8 files changed

+321
-235
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 190 additions & 158 deletions
Large diffs are not rendered by default.

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

Lines changed: 94 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingSeb.ExpressionEvaluator.Tests/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,10 @@
298298
<data name="Script0060" type="System.Resources.ResXFileRef, System.Windows.Forms">
299299
<value>resources\script0060.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
300300
</data>
301+
<data name="Script0061" type="System.Resources.ResXFileRef, System.Windows.Forms">
302+
<value>resources\script0061.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
303+
</data>
304+
<data name="Script0062" type="System.Resources.ResXFileRef, System.Windows.Forms">
305+
<value>resources\script0062.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
306+
</data>
301307
</root>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0061 */
2+
var x = new List<int> {1,2,3,4};
3+
x.Json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Script0062 */
2+
var x = new List<int> {1,2,3,4}

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************************************
22
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3-
Version : 1.4.2.0
3+
Version : 1.4.2.1
44
(if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
55
66
Author : Coding Seb
@@ -775,6 +775,13 @@ public bool OptionNewFunctionEvaluationActive
775775
/// </summary>
776776
public OptionOnNoReturnKeywordFoundInScriptAction OptionOnNoReturnKeywordFoundInScriptAction { get; set; } = OptionOnNoReturnKeywordFoundInScriptAction.ReturnAutomaticallyLastEvaluatedExpression;
777777

778+
/// <summary>
779+
/// If <c>true</c> ScriptEvaluate need to have a semicolon [;] after each expression.
780+
/// If <c>false</c> Allow to omit the semicolon for the last expression of the script.
781+
/// Default : true
782+
/// </summary>
783+
public bool OptionScriptNeedSemicolonAtTheEndOfLastExpression { get; set; } = true;
784+
778785
#endregion
779786

780787
#region Reflection flags
@@ -1345,11 +1352,18 @@ void forAction(int index)
13451352
{
13461353
lastResult = ScriptExpressionEvaluate(ref i);
13471354
}
1355+
else if (!OptionScriptNeedSemicolonAtTheEndOfLastExpression && i == script.Length - 1)
1356+
{
1357+
i++;
1358+
lastResult = ScriptExpressionEvaluate(ref i);
1359+
startOfExpression--;
1360+
}
13481361

13491362
ifBlockEvaluatedState = IfBlockEvaluatedState.NoBlockEvaluated;
13501363
tryBlockEvaluatedState = TryBlockEvaluatedState.NoBlockEvaluated;
13511364

1352-
i++;
1365+
if (OptionScriptNeedSemicolonAtTheEndOfLastExpression || i < script.Length - 1)
1366+
i++;
13531367
}
13541368
}
13551369

TryWindow/MainWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit"
88
Closing="Window_Closing"
99
mc:Ignorable="d"
10-
Title="Expression Evaluate" Width="400" Height="300">
10+
Title="Expression Evaluate" Width="400" Height="320">
1111
<DockPanel>
1212

1313
<StackPanel DockPanel.Dock="Bottom">
@@ -24,6 +24,11 @@
2424
Text="1" />
2525

2626
</DockPanel>
27+
28+
<WrapPanel>
29+
<CheckBox x:Name="NeedSemicolonAtTheEndCheckBox"
30+
Content="Need semicolon [;] At the end" />
31+
</WrapPanel>
2732

2833
<Button x:Name="CalculateButton" Content="_Execute" IsDefault="True" Click="CalculateButton_Click" />
2934
<Button x:Name="CancelButton"

TryWindow/MainWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
3636
CalculateButton.IsEnabled = false;
3737
CancelButton.IsEnabled = true;
3838

39-
ExpressionEvaluator evaluator = new ExpressionEvaluator();
39+
ExpressionEvaluator evaluator = new ExpressionEvaluator()
40+
{
41+
OptionScriptNeedSemicolonAtTheEndOfLastExpression = NeedSemicolonAtTheEndCheckBox.IsChecked.GetValueOrDefault(),
42+
};
4043

4144
if (UseCachesCheckbox.IsChecked ?? false)
4245
evaluator.CacheTypesResolutions = true;

0 commit comments

Comments
 (0)