C# Evaluator, Terse syntax fix.
authorMiguel de Icaza <miguel@gnome.org>
Sat, 9 Feb 2013 20:30:23 +0000 (15:30 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Sat, 9 Feb 2013 20:30:55 +0000 (15:30 -0500)
The terse syntax added a semicolon automatically, but that also meant
that things lik:

csharp> for (int i = 0; i < 10; i++)

Would never get a continuation for partial input, since the semicolon
woudl make that a valid block.

Fix that by first trying to add a block at the end, if that works, then
we know we want to continue, otherwise we insert the semicolon.

mcs/mcs/eval.cs

index 6810507d063fb0ca79c5124042fa3943cce1d767..457bff4986b8df63dca767465f3de4899f132521 100644 (file)
@@ -226,9 +226,16 @@ namespace Mono.CSharp
 
                                bool partial_input;
                                CSharpParser parser = ParseString (ParseMode.Silent, input, out partial_input);
+
+                               // Terse mode, try to provide the trailing semicolon automatically.
                                if (parser == null && Terse && partial_input){
                                        bool ignore;
-                                       parser = ParseString (ParseMode.Silent, input + ";", out ignore);
+
+                                       // check if the source would compile with a block, if so, we should not
+                                       // add the semicolon.
+                                       var needs_block = ParseString (ParseMode.Silent, input + "{}", out ignore) != null;
+                                       if (!needs_block)
+                                               parser = ParseString (ParseMode.Silent, input + ";", out ignore);
                                }
                                if (parser == null){
                                        compiled = null;