diff mbox

[Ada] Syntactic error recovery for case expressions

Message ID 20170425080451.GA145058@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 25, 2017, 8:04 a.m. UTC
This patch improves the synactic error recovery in the case where a ";"
is used instead of "," in a case expression. The following test should
get these errors:

case_exp_semi.ads:5:28: ";" should be ","

package Case_Exp_Semi is

   X : Integer := 1;
   Y : Integer :=
     (case X is when 1 => 1; when 2 => 2, when others => 3);

end Case_Exp_Semi;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-04-25  Bob Duff  <duff@adacore.com>

	* par-ch4.adb (P_Case_Expression): If a semicolon
	is followed by "when", assume that ";" was meant to be ",".
diff mbox

Patch

Index: par-ch4.adb
===================================================================
--- par-ch4.adb	(revision 247135)
+++ par-ch4.adb	(working copy)
@@ -3199,6 +3199,20 @@ 
          if Token = Tok_When then
             T_Comma;
 
+         --  A semicolon followed by "when" is probably meant to be a comma
+
+         elsif Token = Tok_Semicolon then
+            Save_Scan_State (Save_State);
+            Scan; -- past the semicolon
+
+            if Token /= Tok_When then
+               Restore_Scan_State (Save_State);
+               exit;
+            end if;
+
+            Error_Msg_SP -- CODEFIX
+              ("|"";"" should be "",""");
+
          --  If comma/WHEN, skip comma and we have another alternative
 
          elsif Token = Tok_Comma then