Re: Lua syntax ambiguity

Francisco Olarte <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <CA+bJJbxf6F_OBBWWVN_M_nULFsN9vAjiL-j6tbjBNfW42-n=yg@mail.gmail.com>
Hi Martin.

I have been tracking this thread, and IMO, you are complicating things a lot.

I would personally just insert a space in places which could need it,
there are not that many, but if youMUST absolutely avoid extra
spaces...

On Wed, 19 Aug 2026 at 16:47, 'Martin Eden' via lua-l
<[email protected]> wrote:
> I think I found acceptable solution for handling this.
...
> Problem is that when serializing index in table ("[" serialize(key) "]"),
> serialize() can write something starting with "[" which will spoil
> index bracket.
> So we must know from what that next token will begin.
> So we need stream that has method to peek at output.
> And generally, when key node type is that problematic "string" --
> we call serialize() for that peekable sub-stream, peeking
> and it's first char, writing separator to main stream if needed,
> writing sub-stream data to main stream:

Have you considered changing serialize(key,stream) to
serialize(key,stream,context)? Extra parameter is IMO justified, and
can default to nil for the current behaviour, but in this case you can
pass, i.e., '[' as context when you are serializing a key and the
serialize function can then insert a space if it is going to emit a
'[[' string.

In fact, all my serialization functions are of the form
local function _serialize(data, context) ... lots of code probably
with some helper calls... end
local function serialize(data)
   local r = _serialize(data, INITIAL_CONTEXT)
   return some_function_probably_identity(r)
end

contexts, in my case, are rather complex, they include streams, a
state object to detect loops and duplicates, key path tracking info (
so I can patch recursive tables when I write things like lua source ),
indentation settings and states, what type of thing I am writing,
whatever is needed. And normally I have several published entry points
which use different contexts. But the pattern has served me well for a
long time in several languages.

Francisco Olarte.

-- 
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 [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CA%2BbJJbxf6F_OBBWWVN_M_nULFsN9vAjiL-j6tbjBNfW42-n%3Dyg%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.