[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ada mode parser error for 'declare expression' in Ada 2022

From: Cameron Howie
Subject: Ada mode parser error for 'declare expression' in Ada 2022
Date: Mon, 27 Jun 2022 16:36:18 +0000 (UTC)

I've posted these particulars to Emacs bugs list and have also sent this message to the mailing list address, as the Ada mode homepage requests:

ISSUE: see subject line above. I've not yet used "declare expressions" in subprogram bodies, just their contracts, and noticed parser errors. So it may be that the issue is specific to things like preconditions and postconditions.

EXAMPLE CODE DEMONSTRATING ISSUE: a Postcondition uses a declare _expression_ which, if not commented out, surfaces parser errors:

---------------  PASTE THIS FOLLOWING CODE INTO A FILE "main.adb" THEN OPEN IN Emacs with Ada Mode --------------

--  Build with e.g., "gnatmake main.adb -gnat2020"
--  EMACS ADA MODE ISSUE: remove the 'commented out' Postcondition for 
--                        Absolute_Difference and the Ada Mode parser signals 
--                        all sorts of errors.

with Ada.Text_IO; use Ada.Text_IO;

procedure Main
   procedure Absolute_Difference
     (x, y : Integer;
      diff : out Integer)
      --  with Post => (declare
      --     min : constant Integer := Integer'Min(x, y);
      --     max : constant Integer := Integer'Max(x, y);
      --     begin diff = max - min)
      diff := abs x - y;
   end Absolute_Difference;

   u : constant Integer := 95;
   v : constant Integer := 5;
   d : Integer;
   Absolute_Difference (u, v, diff => d);
   Put_Line ("Absolute difference =" & d'Img);  --  prints "90"
end Main;

--------- END OF EXAMPLE FILE main.adb

reply via email to

[Prev in Thread] Current Thread [Next in Thread]