Making custom DSLs starting with "!" and "@"

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Making custom DSLs starting with "!" and "@"

Abhijit Nandy
Hi,

I want to support some custom syntax like the following in a Lua console I have implemented:

!ls -lrt
or 
@name{....}  

The exclamation mark and "@" are not valid Lua syntax so currently I detect them in the typed string and replace with valid Lua code - macro pre-processing.

But is there a way to make it valid given the flexibility of Lua to make DSLs.

Thanks
Abhijit


Reply | Threaded
Open this post in threaded view
|

Re: Making custom DSLs starting with "!" and "@"

Luiz Henrique de Figueiredo
> I want to support some custom syntax like the following in a Lua console I have implemented:
>
> !ls -lrt
> or
> @name{....}
>
> The exclamation mark and "@" are not valid Lua syntax so currently I detect them in the typed string and replace with valid Lua code - macro pre-processing.
>
> But is there a way to make it valid given the flexibility of Lua to make DSLs.

Experiment with ltokenp. See
http://lua-users.org/lists/lua-l/2018-07/msg00683.html.

Reply | Threaded
Open this post in threaded view
|

Re: Making custom DSLs starting with "!" and "@"

Abhijit Nandy
Thanks Luiz. That should do it!!

ltokenp uses a separate Lua interpretor. How different is it from the usual Lua 5.3.x code and can it be merged?

Thanks,
Abhijit

On Thu, Nov 8, 2018 at 4:24 PM Luiz Henrique de Figueiredo <[hidden email]> wrote:
> I want to support some custom syntax like the following in a Lua console I have implemented:
>
> !ls -lrt
> or
> @name{....}
>
> The exclamation mark and "@" are not valid Lua syntax so currently I detect them in the typed string and replace with valid Lua code - macro pre-processing.
>
> But is there a way to make it valid given the flexibility of Lua to make DSLs.

Experiment with ltokenp. See
http://lua-users.org/lists/lua-l/2018-07/msg00683.html.

Reply | Threaded
Open this post in threaded view
|

Re: Making custom DSLs starting with "!" and "@"

Luiz Henrique de Figueiredo
> ltokenp uses a separate Lua interpretor. How different is it from the usual Lua 5.3.x code and can it be merged?

ltokenp is a preprocessor. You need to save its output and run it separately.

If your DSL contains Lua as a subset, then you can embed a token
processor by using the modified llex.c (one line) and a suitable
proxy.c. I have posted several examples here in lua-l. Search the
archives for proxy.c. However, writing a custom proxy.c is not fun for
anything complicated and requires some understanding of the internals
of Lua (mainly the lexer). This was the motivation for ltokenp, where
you can write token filters in Lua.