public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Syntactic error recovery for case expressions
@ 2017-04-25  8:13 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2017-04-25  8:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

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 ",".


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 770 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-25  8:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  8:13 [Ada] Syntactic error recovery for case expressions Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).