Re: Lua syntax ambiguity

"'Martin Eden' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
On 2026-08-16 19:58, Andrey Dobrovolsky wrote:
 > Hi Martin,

Hi Andrew,

 > Simple modification of the rule
 >
 >  field ::= "[ " exp " ]" ‘=’ exp
 >
 > probably is the minimal change, however I don't know whether string
 > literals of the length greater than 1 are allowed in EBNF.

Yeah string literals are allowed in BNF but this modification will
make code strings like "t={[a]=true}" invalid. And using space
in literal considered bad manners there.

 > I think it wouldn't be complicated for code generator to insert extra
 > space before and after an index value:
 >
 > t={[ [[a]] ]=true}
 >
 > and it would be enough, for correct parsing.

Actually lexer needs any separator (one or more of any of (space, 
newline, comment))
between "[" from index opening and "[" from string opening.

But it can't be inserted nicely in code generation. Because proper code just
writes to output stream and can't (and shouldn't) read existing output 
stream.


So we have something like

   // serialize key and value
   // ...
   emit_opening_index()
   serialize(KeyNode)
   // ...

And that flag ("bro if you gonna open with "[" then plz insert any
whitespace you like before it") is ugly thing to embed in code.

I've handled it by temporarily monkey-patching output stream method.
Just another similar-ugliness solution

https://github.com/martin-eden/lua_table_serializer/blob/06e5bedb6a248a950158b7fb4062a8d6f61957d6/src/workshop/concepts/codec_lua_graph/compile/Initializer.lua#L138-L143


In theory if we aim to comply with "our language is described by formal 
grammar"
we can state that any long quote MUST have at least one "=".

So "[[abc]]" becomes invalid, minimal valid will be "[=[abc]=]".
This will resolve this syntax clash.

 > Thanks for an interesting corner case,
 > -- Andrew

I'm glad you liked it.

-- 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/eea51f32-acbe-49e2-b072-496c3cfb42e4%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.