lua-users home
lua-l archive

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


On 25/03/2019 02.21, Soni "They/Them" L. wrote:
> Hello!
> 
> I need a simple and quick way to process valid Lua files. Namely, I need to look
> at the space between freeform text (strings, comments, etc), and potentially
> modify it. However, one must note that such freeform text may appear in tables,
> or in indexing operations, or in function calls, and so on, and I need to be
> able to handle that as well.
> 
> Is there an easy way to scan "Lua" files for lexical tokens and being able to
> rearrange them without going with a full parser?
> 
> [...]
>
> Sorry, I think I forgot to specify that I wanna do this from Lua, not with an
> external tool. .-.

I don't know such.

Snow-like information injection is not too common task in this lands.

You may use full Lua parser from my "lcf" rock. It's command "lua.get_ast"
returns full syntax tree for given Lua file. With comments and whitespaces
folded hierarchically. After modification you need to compile tree back
to string. Which is easy, just DFS and concat all string items.

-- Martin