On the subject of Lua's grammar... --[[ ]]

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: On the subject of Lua's grammar... --[[ ]]

Philippe Lhoste
> While we're talking about Lua's grammar, and someone had
> mentioned Lua's short-comment specifier (which I don't really mind)
> there's one thing I'd really rather like to see in a future
> version of the language: nestable or otherwise non-accidentally-
> terminated long-comments.
> 
> I often use --[[ ... ]] for commenting out chunks of code, but
> am also often foiled in this because the long-comment terminator,
> ']]', is something that fairly often occurs naturally in the
> code I'm commenting out.  It would be nice if the parser could
> either count the [[ and ]] balance and only terminate the
> comment when the balance returns to zero, or allowed a different
> block-comment format whose terminator sequence wasn't valid
> Lua grammar.
> 
> Regards,
> --Adam

I don't understand. They are nestable, I just did a quick test, and it seems
to work. I worked hard to have 
the Scintilla lexer for Lua to handle these nesting, I hope I did right :-)

Regards.

-- 
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--

NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService

Jetzt kostenlos anmelden unter http://www.gmx.net

+++ GMX - die erste Adresse für Mail, Message, More! +++


Reply | Threaded
Open this post in threaded view
|

Re: On the subject of Lua's grammar... --[[ ]]

Roberto Ierusalimschy
In reply to this post by Nick Trout
> Woo I didn't think I'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...

You cannot put strings that do not end with '\n'.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: On the subject of Lua's grammar... --[[ ]]

Leandro Candido
In reply to this post by Philipp Janda
Hello all,

    Thank you Philipp for the code, you only forgot the userdata type
 metamethods, etc.. ). In my opinion, it's best to have in the language
itself, as this speed up the code and can use the parser to check types,
etc...

                                                                    The
God's Peace,


Leandro.

----- Original Message -----
From: "Philipp Janda" <[hidden email]>
To: <[hidden email]>
Sent: Friday, November 28, 2003 6:50 AM
Subject: Re: On the subject of Lua's grammar... --[[ ]]


> Leandro Candido schrieb:
> > Hello all,
> >
> >
> >     As we are in suggestion time, i will make my one. Can you guys add
range
> > operator? To use like:
> >
> >     for x in 0..10 do print(x) end or
> >     for x in 'A'..'Z' do print(x) end
> >
> >     Of course the .. need be other letters/signs or we need to change
the
> > concat operator, because it is "..".
> >     Perhaps the best is the word "to":
> >
> >     for x in 0 to 10 do print(x) end, y = 0 to 10 or y = { 0 to 10 } --
> > equal y = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
>
> What about this:
>
> local function num_range_iterator( state, var1 )
>    -- state is the end of the iteration
>    var1 = var1 + 1
>    if var1 > state then
>      return nil
>    end
>    return var1
> end
>
> local function char_range_iterator( state, var1 )
>    -- state is the end of the iteration
>    local ret = num_range_iterator( state, string.byte( var1 ) )
>    return ret and string.char( ret )
> end
>
>
> function range( start, ending )
>    local stype, etype = type( start ), type( ending )
>    if stype == "string" and etype == "string" then
>      return char_range_iterator, string.byte( ending ),
>             string.char( string.byte( start )-1 )
>    elseif stype == "number" and etype == "number" then
>      return num_range_iterator, ending, start-1
>    else
>      error( "type error in function `range' (strings or numbers
expected)" )
>    end
> end
>
>
> function from_to( start, ending )
>    local tab = {}
>    for x in range( start, ending ) do
>      table.insert( tab, x )
>    end
>    return unpack( tab )
> end
>
> --------- test -------------------------------------------------------
>
>
> for x in range( 1, 10 ) do
>    print( x )
> end
>
> for x in range( 'A', 'Z' ) do
>    print( x )
> end
>
> local y = { from_to( 1, 10 ) }
> for i,j in ipairs( y ) do
>    print( i, j )
> end
>
>
>
>
> Philipp
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: On the subject of Lua's grammar... --[[ ]]

Leandro Candido
Hello,

    Oops, where you see the word PARSER, close the eyes and imagine the word
INTERPRETER ;-), in the past mail.

                                                                    God
bless you,


Leandro.

----- Original Message -----
From: "Leandro Candido" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Saturday, November 29, 2003 10:32 PM
Subject: Re: On the subject of Lua's grammar... --[[ ]]


> Hello all,
>
>     Thank you Philipp for the code, you only forgot the userdata type
>  metamethods, etc.. ). In my opinion, it's best to have in the language
> itself, as this speed up the code and can use the parser to check types,
> etc...
>
>                                                                     The
> God's Peace,
>
>
> Leandro.
>
> ----- Original Message -----
> From: "Philipp Janda" <[hidden email]>
> To: <[hidden email]>
> Sent: Friday, November 28, 2003 6:50 AM
> Subject: Re: On the subject of Lua's grammar... --[[ ]]
>
>
> > Leandro Candido schrieb:
> > > Hello all,
> > >
> > >
> > >     As we are in suggestion time, i will make my one. Can you guys add
> range
> > > operator? To use like:
> > >
> > >     for x in 0..10 do print(x) end or
> > >     for x in 'A'..'Z' do print(x) end
> > >
> > >     Of course the .. need be other letters/signs or we need to change
> the
> > > concat operator, because it is "..".
> > >     Perhaps the best is the word "to":
> > >
> > >     for x in 0 to 10 do print(x) end, y = 0 to 10 or y = { 0 to
10 } --
> > > equal y = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
> >
> > What about this:
> >
> > local function num_range_iterator( state, var1 )
> >    -- state is the end of the iteration
> >    var1 = var1 + 1
> >    if var1 > state then
> >      return nil
> >    end
> >    return var1
> > end
> >
> > local function char_range_iterator( state, var1 )
> >    -- state is the end of the iteration
> >    local ret = num_range_iterator( state, string.byte( var1 ) )
> >    return ret and string.char( ret )
> > end
> >
> >
> > function range( start, ending )
> >    local stype, etype = type( start ), type( ending )
> >    if stype == "string" and etype == "string" then
> >      return char_range_iterator, string.byte( ending ),
> >             string.char( string.byte( start )-1 )
> >    elseif stype == "number" and etype == "number" then
> >      return num_range_iterator, ending, start-1
> >    else
> >      error( "type error in function `range' (strings or numbers
> expected)" )
> >    end
> > end
> >
> >
> > function from_to( start, ending )
> >    local tab = {}
> >    for x in range( start, ending ) do
> >      table.insert( tab, x )
> >    end
> >    return unpack( tab )
> > end
> >
> > --------- test -------------------------------------------------------
> >
> >
> > for x in range( 1, 10 ) do
> >    print( x )
> > end
> >
> > for x in range( 'A', 'Z' ) do
> >    print( x )
> > end
> >
> > local y = { from_to( 1, 10 ) }
> > for i,j in ipairs( y ) do
> >    print( i, j )
> > end
> >
> >
> >
> >
> > Philipp
> >
> >
> >
>
>


12