lua-users home
lua-l archive

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



-------- Forwarded Message --------
Subject: Heritage of Lua syntax for multi-line strings and comments
Date: Thu, 23 Nov 2023 23:52:17 +0100
From: Claudio Grondi <claudio.grondi@freenet.de>
To: Lua mailing list <lua-l@lists.lua.org>


coloredCode
In order to colorize my life while writing code I am using the Lua feature of providing different kind of strings and use the code highlighting in the text editor to show them in different text colors and styles.

I am putting this "styling info", a kind of markdown, after the line length limit column in order to separate the main text and the styling information.

What I am wondering about is if there is a good eason I am not aware of for using:

`--[===[        third level styled text comment    ]===]`
instead of:
`--[[[[[        third level styled text comment    ]]]]]`
or
`--['''[        third level styled text comment    ]''']`
or
`--[...[        third level styled text comment    ]...]`

Why does it matter for me? It does matter because I decided to leave the path of in my eyes ugly and overlong monospaced texts with spaces to embrace variable width fonts and tabs which allow me to put more textual information within same space on the display:

`--[===[    third level styled text comment    ]===]`
`--[[[[[    third level styled text comment    ]]]]]`
`--[...[    third level styled text comment    ]...]`
`--['''[    third level styled text comment    ]''']` (in my eMail client the shortest one)

The shortest and probably most appropriate and least obtrusive text pattern in this context seems to be given using single quotes. And while I am in the process of writing a kind of transpiler to be able to experiment with another patterns for marking starts and ends of strings/comments I would like to know what could be the reason for the choice of such and not other pattern in Lua.

What I am currently considering as most concise way of defining strings and comments is usage of a double quote as begin and a single quote as end of a string, increasing the amount of single quotes for higher levels:

"''' multiline string 3rd level

" string '      -" comment '
"' multiline first level
                    string '     -"' multiline
                                                       first level comment'
''' -"''' multiline
                        3rd level
                                        comment'''

Please don't consider this posting as a feature request or critics ... I am just only curious about the heritage of the Lua syntax choices. Maybe I am not aware of something thinking a transpiler to Lua from the targeted syntax would be a matter of very simple regular expressions based text replacements.

Another approach with easier parsing and no need for any escaping would be to move the entire actual script code, except comments and content of strings fully outside of the ASCII range ... this would make the transpiler even easier to write by just replacing patterns of higher range Unicode with the related ASCII pattern without the need for regular expressions.

Claudio