tkurtbond / old-ada-mode

This is a fork of the old version of ada-mode.el that was distributed with Emacs.
GNU General Public License v3.0
27 stars 4 forks source link

Broken handling of conditional expressions #3

Open paralogismos opened 5 months ago

paralogismos commented 5 months ago

It seems that old-ada-mode is broken when handling case expressions and if expressions. Consider the two code examples below:

with Ada.Text_IO; use Ada.Text_IO;

procedure Case_Expr is
   type Pet is (Dog, Cat, Goldfish);
   My_Pet : Pet := Dog;
begin
   Put_Line(
     (case My_Pet is
        when Dog => "Doggie",
        when Cat => "Kitty",
        when Goldfish => "Fishy"));
end Case_Expr;
with Ada.Text_IO; use Ada.Text_IO;

procedure If_Expr is
   type Pet is (Dog, Cat, Goldfish);
   My_Pet : Pet := Dog;
begin
   Put_Line(
     (if My_Pet = Dog then "Doggie"
     elsif My_Pet = Cat then "Kitty"
     else "Goldfish"));
end If_Expr;

These are legal Ada programs which compile and run, but old-ada-mode complains about "No matching proc/func/task/declare/package/protected." When the conditional expression occurs in a loop old-ada-mode complains of the end loop that "Matching start is not 'loop'."

Note that old-ada-mode can be satisfied by the inclusion of a "matching" end case or end if, but then the code is no longer legal Ada code and will not compile.

This issue does not prevent one from writing correct code, but it does cause much unpleasantness and havoc with formatting and ada-mode warnings below any occurrences of conditional expressions in source code.

Conditional expressions were an addition to Ada 2012, so I suspect that old-ada-mode just predates these newer language features; still, this is an annoying gap.

mgrojo commented 1 week ago

Yes, the old ada-mode did not support Ada 2012, that should be stated in the README.

We have three possible Ada modes for Emacs, and none of them entirely satisfactory, in my opinion. I've checked that ada-light-mode indents your snippets (although rigidly and after finishing the current statement) once you've activated eglot and the ada_language_server.

I wonder if this one would work with eglot and company-mode but working with its own indentation engine. It would be mildly satisfactory if you don't mind the lack of Ada 2012 support.