Why remove [[ ... [[ ... ]] ... ]]

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

Why remove [[ ... [[ ... ]] ... ]]

mos-4
Hi!
    From 5.02 to 5.1, it can not surpport the string like [[abc[[def]]ghl]], I indeed have the requirement because I use Lua as the RPC's parser.
    I like [[ ]], it have begin and end so can use it freely.
    for example: I send a cmd to server like 
    "DoCmd([[ShutDown([[the server will shut down!]])]])"; 
    and more 
    SendCmdRemote("topserver", [[DoCmd([[ShutDown([[the server will shut down!]])]]]]) 
    and I feel very sad when use [=[ ]=] etc. How can I know how many '=' I should append?

yujiang 


Reply | Threaded
Open this post in threaded view
|

Re: Why remove [[ ... [[ ... ]] ... ]]

Mildred Ki'Lya
On Fri, 17 Mar 2006 12:05:02 +0800 "mos" <[hidden email]> wrote:
> Hi!
>     From 5.02 to 5.1, it can not surpport the string like
> [[abc[[def]]ghl]], I indeed have the requirement because I use Lua as
> the RPC's parser. I like [[ ]], it have begin and end so can use it
> freely. for example: I send a cmd to server like
> "DoCmd([[ShutDown([[the server will shut down!]])]])"; and more 
>     SendCmdRemote("topserver", [[DoCmd([[ShutDown([[the server will
> shut down!]])]]]]) and I feel very sad when use [=[ ]=] etc. How can
> I know how many '=' I should append?

I agree completely ... I don't understand that decision at all ...
Why can't just keep compatibilità and :
- allow nested [[ ... ]]
- forbid nested [=[ ... ]=]

I like nested [[ ... ]] because it gives great flexibility ...
For example you can just add a comment --[[ ... ]] even if there is
[[ ... ]] strings inside !

???

-- 
Mildred       <xmpp:[hidden email]> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]

Reply | Threaded
Open this post in threaded view
|

Re: Why remove [[ ... [[ ... ]] ... ]]

Roberto Ierusalimschy
In reply to this post by mos-4
On Fri, Mar 17, 2006 at 12:05:02PM +0800, mos wrote:
> Hi!
>     From 5.02 to 5.1, it can not surpport the string like [[abc[[def]]ghl]], I indeed have the requirement because I use Lua as the RPC's parser.
>     I like [[ ]], it have begin and end so can use it freely.
>     for example: I send a cmd to server like 
>     "DoCmd([[ShutDown([[the server will shut down!]])]])"; 
>     and more 
>     SendCmdRemote("topserver", [[DoCmd([[ShutDown([[the server will shut down!]])]]]]) 
>     and I feel very sad when use [=[ ]=] etc. How can I know how many '=' I should append?
> 

One more than the previous one?

  [==[DoCmd([=[ShutDown([[the server will shut down!]])]=]]==]

The reason for the change was to simplify the language. For instance,
now it is easy to write a Lua pattern to match such comments. Also, it
should be easier to write syntax highlight and other tools for Lua. I
also think it is easier to read your example with the new syntax (but
this is my personal taste, of course).

(I know; the new format is not a regular expression, too. It cannot
be. But if you assume the tool should work only up to 10 equals, then
you can define it as a regular expression.)

The next function builds the "correct" brackets for a given string:

function quote (s)
  -- find maximum length of sequences of equal signs
  local n = -1
  for w in string.gmatch(s, "]=*") do
    n = math.max(n, #w - 1)
  end

  -- produce a string with 'n' plus one equal signs
  local eq = string.rep("=", n + 1)

  -- build quoted string
  return string.format(" [%s[\n%s]%s] ", eq, s, eq)
end

(Example taken from the 2nd edition of the Lua book :)
 
-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Why remove [[ ... [[ ... ]] ... ]]

Aaron Brown
In reply to this post by Mildred Ki'Lya
Mildred wrote:

I like nested [[ ... ]] because it gives great flexibility
...  For example you can just add a comment --[[ ... ]]
even if there is [[ ... ]] strings inside !

But not if there's code like foo[bar[baz]] inside.

--
Aaron

Reply | Threaded
Open this post in threaded view
|

Re: Why remove [[ ... [[ ... ]] ... ]]

mos-4
In reply to this post by Roberto Ierusalimschy
Hi
    
>    One more than the previous one? 
No!
    I create the cmd like!
    void SendCmd(int cmd, const char* cmd)
    {
        stringstream s;
        s << "SendCmd(" << cmd << ",[[" << cmd << "]])"
       SendCmd(s);
    }
      Thanks for you given function quete(s), there may be 
      s << "SendCmd(" << cmd << "," << quete(cmd) << ")";
 > now it is easy to write a Lua pattern to match such comments
    you already did it on 5.02 !    
 > it should be easier to write syntax highlight and other tools for Lua
    but I still suggest you caring more about the user than tools