• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Lua 'end' syntax (1 Viewer)

225559

Newcomer
Joined
Nov 17, 2020
Messages
15
Reaction score
4
Is there any way to make the Lua end syntax more similar to Ada's end syntax? e.g.: end if, end loop, end Function_Name

I'm currently using comments to emulate the Ada syntax, e.g.:
Lua:
function Get_Max (A, B)
   if (A > B) then
      return A;
   else
      return B;
   end -- if
end -- Get_Max

print (Get_Max (3, 2))

The Ada equivalent is:
Ada:
with Ada.Text_IO; use Ada.Text_IO;

procedure Main
is
    function Get_Max (A, B : Integer) return Integer
    is
    begin
        if A > B then
            return A;
        else
            return B;
        end if;
    end Get_Max;
begin
    Put_Line (Integer'Image (Get_Max (3, 2)));
end Main;

It looks like the Lua syntax was very much inspired by Ada. Hence, I don't understand why they didn't copy the end syntax as well? It makes the code much more readable.
 

dinsdale247

Moderator
Staff member
Community Patron
Creator of WinLua
Joined
Nov 17, 2020
Messages
93
Reaction score
32
Location
Victoria BC
Website
winlua.net
That's definitely a question for the Lua-L mailing list. I'd like to know what the Lua team says.
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
75
Reaction score
46
Location
Italy
Website
github.com
Lua syntax was more inspired by Modula, according to this paper by the Lua triumvirate: The Evolution of Lua (pdf).

This answers half the question, I think. As for how one could emulate Ada's syntax, I honestly don't see how, but of course this doesn't mean much.
 

dinsdale247

Moderator
Staff member
Community Patron
Creator of WinLua
Joined
Nov 17, 2020
Messages
93
Reaction score
32
Location
Victoria BC
Website
winlua.net
Lua syntax was more inspired by Modula, according to this paper by the Lua triumvirate: The Evolution of Lua (pdf).

This answers half the question, I think. As for how one could emulate Ada's syntax, I honestly don't see how, but of course this doesn't mean much.
Thanks for the link. I had seen that document once before and lost track of it.
 

coal

Newcomer
Joined
Mar 6, 2021
Messages
1
Reaction score
0
Age
16
Website
coals.live
Lua syntax was more inspired by Modula, according to this paper by the Lua triumvirate: The Evolution of Lua (pdf).

This answers half the question, I think. As for how one could emulate Ada's syntax, I honestly don't see how, but of course this doesn't mean much.
You could write a grammar using the actual Lua EBNF specification as reference, parse the syntax and transpile into a vanilla Lua equivalent.

The Lua grammar is very (very) simple; it extends to just 56 lines of code, compared to other languages where the grammar can be thousands of lines long. There's an ECMAScript grammar for ANTLR which is 1,500+ lines available here.

For comparison, the Lua EBNF specification for 5.1 is also available in the Lua reference manual.
 

GavinW

Newcomer
Creator of RiscLua
Joined
Oct 21, 2020
Messages
43
Reaction score
17
Age
82
Location
UK
Website
www.wra1th.plus.com
comment
For the sake of two hyphens you can have your cake and eat it
end -- comment
 
Top