lua-users home
lua-l archive

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


String literals used anywhere as comment ?

Forger that idea. Lua already has currification, and the ambiguïté caused by optional semicolons between statements.

We should be able to place comment anywhere (including in the middle of any lexical token, and in the middle of long literals with a proper syntaxe of these literals allowing them to be segmented and automatically concatenated by the parser if they are splitted into multiple tokens (to break too long lines, or insert comments or o
processing directives, we should allow thèse delimted tokens to be separaetd by any whitespaces or even none, without needing any additional operator tokens).

Note that long literals are NOT just for strings. These literals may be preprocessed for other types or could as well have some preprocessing directives or indicators, allowing several syntaxes, like those used in XML/HTML, or MIME, or hexadecimal, base64, or other bases, giving freedom for developpers to wrote thdor constants thd way they wish.

Then comments are just a other type of literals, excdot that it uses a directive or indicator, instructing the lexer to discarc the token and not pass it to the parser.


Le ven. 24 nov. 2023, 20:43, Claudio Grondi <claudio.grondi@freenet.de> a écrit :

On 11/24/23 20:22, bil til wrote:
> Am Fr., 24. Nov. 2023 um 20:17 Uhr schrieb Claudio Grondi
> <claudio.grondi@freenet.de>:
>> ''' multiline string
>>                                   first level '''
> This looks somehow funny, this really works well in Python?
In Python there are two options for multiline strings: """ some
multiline string literal """   and   ''' some multiline string literal ''' .

As I am coming to Lua after more than 30 years of Python I appreciate
the infinite depth of nesting Lua comes with.

This allows me even better styling with more options for different kinds
of strings as the four Python comes with (1.'x' 2."x" 3.'''x''' 4."""x""").

I found in Lua also the equivalent of the "(magic switch)" I was using
in Python to switch between two blocks of code by inserting/deleting
only one character in source code text to make one or the  other block a
comment.


>
> ... just wondering how they distinguish empty strings "" from this
> start sign of a multiline string ...
This is easy ... they allow occurrences of unnamed string literals in
code ... something Lua could probably also do with ease if decided to go
this way. This would not brake anything adding a nice way of using
string literals as comments.

This works because the first part of the triple quote is considered to
be an empty string and because it is not necessary to give it a name
it's OK for the parser which bumps into a single quotation starting a
string literal scan.