lua-users home
lua-l archive

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


What do you think about the following suggestion?

Let's introduce special "ignore me" symbol in Lua syntax.
(The description below assumes this symbol is the backtick)

Single occurrence of "ignore me" symbol means that this symbol
must be ignored (excepting inside literal strings)
without splitting the current lexem:

   local million = 1`000`000
   local INT64_MIN = 0x8000`0000`0000`0000
   assert(#("1`000`000") == 9)

A sequence of two (or more) "ignore me" symbols means
part of line (block) must be ignored.
The block is terminated by either end-of-line
or the same amount ("the depth") of backticks.
Syntactically it should be treated as lexem separator.

   local x``integer`` = 42
   local arr``array[65`536] of double``, sz```integer``` = {}, 0
   ``This is single-line comment
   ```This is single-line comment
   ````This is single-line comment
   return`42         -- identifier "return42"
   return``xxxx``42  -- not "return42", but "return 42"

Q: Why this suggestion might be useful?
A: It solves a bunch of problems described as
"I want to extend Lua syntax without breaking compatibility":

Everyone would be glad to have optional digits-group separator
in literal numbers.
Some Lua users would appreciate ability to make long Lua identifiers
more readable by splitting them with ignorable separator.
Lua extensions such as Ravi could be made compatible with Lua.
Return type annotations in Ravi may be located after closing parenthesis:
function (x``integer``)``integer,integer`` return x-1,x+1 end
Global-by-default-haters could use their own Lua dialect which requires
every global variable to be preceded by single backtick.
Global-by-default-lovers could use (and modify) the code written
by global-by-default-haters without a problem.
Your "religion" (hater/lover) could be specified in "luaconf.h"
Different Lua extensions could coexist simultaneously by processing
blocks only having specific depth.

Q: Do you actually suggest new additional syntax for comments in Lua?
A: No.
Comments are for comments (text written in human language).
Extension-blocks ``....`` are for extended syntax.
Structured data in comments looks awkward (although widely used).
Short comment in long brackets --[[integer]] looks not nice.

More notes:
a) Blocks are concatenate-able preserving their depths:
``depth 2`````depth 3`````depth 2``
should be parsed as
``depth 2``+```depth 3```+``depth 2``
b) Nesting of blocks should be avoided.
c) Should blocks of depth 3+ be considered multi-line?
d) This suggestion doesn't break any existing Lua code.

-- Egor