* [Ada] Improve error recovery for bad comma/semicolon in expression
@ 2014-10-20 14:27 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2014-10-20 14:27 UTC (permalink / raw)
To: gcc-patches; +Cc: Robert Dewar
[-- Attachment #1: Type: text/plain, Size: 664 bytes --]
This patch improves the error recovery for an errant comma or semicolon
after one condition in an expression when more conditions follow, as
shown in this example:
1. procedure BadANDTHEN (X : Integer) is
2. begin
3. if X > 10
4. and then X mod 4 = 2;
|
>>> extra ";" ignored
5. and then X mod 12 = 8
6. then
7. null;
8. end if;
9. end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2014-10-20 Robert Dewar <dewar@adacore.com>
* par-ch4.adb (P_Expression): Handle extraneous comma/semicolon
in middle of expression with logical operators.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 2044 bytes --]
Index: par-ch4.adb
===================================================================
--- par-ch4.adb (revision 216469)
+++ par-ch4.adb (working copy)
@@ -1708,6 +1708,48 @@
Node1 := New_Op_Node (Logical_Op, Op_Location);
Set_Left_Opnd (Node1, Node2);
Set_Right_Opnd (Node1, P_Relation);
+
+ -- Check for case of errant comma or semicolon
+
+ if Token = Tok_Comma or else Token = Tok_Semicolon then
+ declare
+ Com : constant Boolean := Token = Tok_Comma;
+ Scan_State : Saved_Scan_State;
+ Logop : Node_Kind;
+
+ begin
+ Save_Scan_State (Scan_State); -- at comma/semicolon
+ Scan; -- past comma/semicolon
+
+ -- Check for AND THEN or OR ELSE after comma/semicolon. We
+ -- do not deal with AND/OR because those cases get mixed up
+ -- with the select alternatives case.
+
+ if Token = Tok_And or else Token = Tok_Or then
+ Logop := P_Logical_Operator;
+ Restore_Scan_State (Scan_State); -- to comma/semicolon
+
+ if Nkind_In (Logop, N_And_Then, N_Or_Else) then
+ Scan; -- past comma/semicolon
+
+ if Com then
+ Error_Msg_SP -- CODEFIX
+ ("|extra "","" ignored");
+ else
+ Error_Msg_SP -- CODEFIX
+ ("|extra "";"" ignored");
+ end if;
+
+ else
+ Restore_Scan_State (Scan_State); -- to comma/semicolon
+ end if;
+
+ else
+ Restore_Scan_State (Scan_State); -- to comma/semicolon
+ end if;
+ end;
+ end if;
+
exit when Token not in Token_Class_Logop;
end loop;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-10-20 14:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20 14:27 [Ada] Improve error recovery for bad comma/semicolon in expression 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).