Lua 5.x parser, Looking beyond luaX_lookahead()

74 views
Skip to first unread message

Alexander Walz

unread,
Oct 13, 2025, 2:50:17 PM (5 days ago) Oct 13
to Lua

 

Hello,

 

is there a save way to check for tokens beyond that luaX_lookahead() will offer ?

 

Especially, I would like to implement Maple-style `(...) -> expr` anonymous/lambda functions in Lua.

 

After dozens and dozens of hours, I am too dumb obviously to succeed, unfortunately.

 

Thank you. Alex
agena.sourceforge.net

 



Sainan

unread,
Oct 13, 2025, 2:57:22 PM (5 days ago) Oct 13
to lu...@googlegroups.com
It is relatively easy to modify the lexer to parse all tokens up-front and then have the parser be able to look anywhere. You can take a look at Pluto[1] which makes such a modification.

And yet, Pluto's lambda syntax is `|...| -> expr`, partially because it predates the "look anywhere" patch iirc, but also less ambiguity is always nice. :^)

[1] https://github.com/PlutoLang/Pluto/

-- Sainan

Luiz Henrique de Figueiredo

unread,
Oct 13, 2025, 3:15:27 PM (5 days ago) Oct 13
to lu...@googlegroups.com
You may use my Lua token processor for experimenting by writing Lua code:

Alexander Walz

unread,
Oct 14, 2025, 2:33:53 AM (5 days ago) Oct 14
to lu...@googlegroups.com
With all due respect: "It is relatively easy to modify the lexer to parse " Nope. It is not "easy" if you check all this with Valgrind. And yep, Pluto's x < y < z chaining is marvelloeus. It may work in 5.x, but in 5.1 it ... it will do, with some changes. Long live Lua.


-----Original-Nachricht-----
Betreff: Re: Lua 5.x parser, Looking beyond luaX_lookahead()
Datum: 2025-10-13T20:57:23+0200
Von: "'Sainan' via lua-l" <lu...@googlegroups.com>
An: "lu...@googlegroups.com" <lu...@googlegroups.com>
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/QoiDiB8RrkHKymXsRSDDHMvoJJt9beLtlkg6QzWLMD9JBhX7eB8lQ19Yd88Sm9RZDa-B-GGrC-1EbBAQAQRJaRU4erRo-umtpymuvdZXf4k%3D%40calamity.inc.


Sainan

unread,
Oct 14, 2025, 2:54:41 AM (5 days ago) Oct 14
to lu...@googlegroups.com
I'm not sure what you mean. I think this was one of the easier patches; I assumed it would need a lot of messing with the internals, but it basically just worked. And Pluto's entire test suite (which includes most of Lua's) goes through Valgrind without a hitch.

Also, Lua 5.1 is not something I would recommend, e.g. see the recent Redis 10.0 CVE which was entirely avoidable by just not using unmaintained versions of Lua that are older than Lua was when it was released.

-- Sainan
Reply all
Reply to author
Forward
0 new messages