lua-users home
lua-l archive

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

From: <>
To: "Lua list" <>
Sent: Thursday, November 27, 2003 1:20 PM
Subject: RE: On the subject of Lua's grammar... --[[ ]]

> Nick Trout didn't think he'd be saying this, but:
> > what about the way it works in Perl?
> > e.g. <<END;
> > I can put anything I want here until my own delimiter is met...
> > END
> Actually, I think this comes from the Unix shell, even before Perl. It
> is also more or less the strategy used by MIME. However, it can also lead
> to obscure errors, and it is difficult to implement reliably in a code
> generator.
> I would actually suggest something much simpler: leave --[[, [[ and ]] as 
> they are, except
> that they are only recognized if they are the first characters of a line, 
> or perhaps
> the first non-whitespace characters. 
> That does not allow an "arbitrary" string, but it would certainly solve 
> all of my
> problems with accidental closing by a[b[j]]; I can probably remember not 
> to
> write that as:
> a[b[
> ]]
> :)
> This would probably mean changing the semantics of long strings [[ ]] yet 
> again,
> so that both the first and the last line end are deleted. Oh, well.

I second that, simpler is better!

I have written a text editor with syntax coloring for Lua. For each line of the text it stores a state at the end of the line to be used in the next line. For example if the current line starts a string and ends on '\' then the string continues on the next line.

The nested comments and strings are a big pain as it is because I have to include the nesting level in my state. Adding variable nested comment delimiters would greatly complicate the end state. (Right now it fits nicely in the range 0..30 and I use it instead of EOL character) I have to include the number of ***s and/or any additional arbitrary identifiers.

I have checked out several other syntax colorers and they use similar approach. Adding variable delimiters will most likely complicate those too.