Re: Lua syntax ambiguity

"'Martin Eden' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
On 2026-08-18 22:47, Sean Conner wrote:
>    I mean, how does your code determine which quoting method to use?  In mine
> [1], I just use double quotes, and will escape control codes or byte values
> larger than 126.  For example:
>
>> dump("x",x)
> x =
> {
>    bar = C_FUNCTION,
>    file = file (0xcbc720),
>    [true] = false,
>    ["one\ntwo"] = 12.000000,
>    foo = "1\n2\t3\v4\a5\000\001\002b\226\141\133",
>    ["[[a]]"] = 2.000000,
>    x = x,
> }
>
>    I sidestepped the issue of using [[...]] and '...' by not using them [2].
>
>    -spc
>
> [1]	https://github.com/spc476/lua-conmanorg/blob/fa5bcdbdcc0ceeeadd238a470c063f8b843c11cd/lua/table.lua#L78
>
> [2]	Yes, some values are not valid Lua (like "bar = C_FUNCTION") but
> 	some Lua values are not easy to deal with (userdata, functions and
> 	threads come to mind).  I was able to solve this somewhat with my
> 	CBOR [3] implemetation, but never published it.  Also, this means
> 	that some tables can't be properly round-tripped with my code; that
> 	doesn't bother me too much and hasn't been an issue.
>
> [3]	Concise Binary Object Representation:
>
> 		defined:<https://cbor.io/>
> 		my module:https://github.com/spc476/CBOR


Mine implementation values diversity. So all three quotes can be used.


Long quotes are nice for multi-line strings without ASCII control chars.
(Newline is not considered control char for this case.)

Short quotes can start with ' or ", whichever occurs less.

There are many ways to decide which (and how) characters should be
escaped with \. If string length is 1, 2, 4 or 8 and contains high ASCII
or control chars this is likely binary value. We quote all it's chars.

Else we quote control chars using \123. (Before there was fancy quoting
for \b \f \v etc but I disliked it.)

And mine serialization is to stream. Which can be whatever you can write
function Write(str): file, pipe, string. That means that it's not
limited by RAM amount (well, _less_ limited).

functions, metatables, uservalues and threads are not serialized.
I don't know how and never had practical need to do this.

Selling point is that my implementation serializes graphs:
table can contain self-references. And produced string contains
loadable Lua code.

-- Martin

-- 
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/b60cfd97-b6c3-42f5-8e2c-85d8bc0c9d10%40disroot.org.
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.