lua-users home
lua-l archive

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


Tom Spilman wrote:
>
> > > Lua 5.1 will bring a more general long comment:
> > > --[****[ ... ]****]
> > > The comment closes when the same number of stars match.
> > > You're free to choose how many stars to use.
> >
> It's a minor issue, but Lua is always striving for simplicity and this
> doesn't seem like it.

I tend to agree.  It solves the common problem (a[b[c]]) but,
dispite its complexity, it's still hard to embed arbitrary
strings.

Why not simply ignore *any* unbalanced brackets inside long
strings/comments instead of only unbalanced *double* brackets.
Isn't that the Lua way?  An easy rule, makes the lexer simpler,
fixes the common nuisance and the "arbitrary string" problem is
ignored for the moment ;-)

diff -u src/llex-orig.c src/llex.c
--- src/llex-orig.c     Fri Jun 18 20:56:52 2004
+++ src/llex.c  Fri Jun 18 20:57:27 2004
@@ -226,18 +226,13 @@
         break;  /* to avoid warnings */
       case '[':
         save_and_next(LS, l);
-        if (LS->current == '[') {
-          cont++;
-          save_and_next(LS, l);
-        }
+        cont++;
         continue;
       case ']':
         save_and_next(LS, l);
-        if (LS->current == ']') {
-          if (cont == 0) goto endloop;
-          cont--;
-          save_and_next(LS, l);
-        }
+        if (LS->current == ']' && cont == 0)
+          goto endloop;
+        cont--;
         continue;
       case '\n':
         save(LS, '\n', l);

Ciao, ET.