Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Oct 13, 2006 7:53 pm   

New multiline syntax supported in v1.10
 
Taking an idea from Python, I've implemented a more flexible multiline script syntax in CMUD v1.10.

In v1.10, whenever you could use a space character, you can now use a newline instead, as long as the indentation of the continuation line is greater than the original indentation for the start of the command.

Here is an example:
Code:
#ALIAS test {
  #IF (@a>1)
    {true}
    {false}
}

Notice that the {true} and {false} lines are indented more than the original #IF statement?

This should allow improved readability for multiline scripts, especially when using the new #SWITCH command.
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Fri Oct 13, 2006 8:45 pm   
 
Nice, always wondered why it was on one line before. this looks nicer.
_________________
http://www.Aardwolf.com
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Oct 13, 2006 10:55 pm   
 
Quote:
always wondered why it was on one line before

Because zMUD really only handles single-line scripts and is kludged to handle multiline. CMUD, on the other hand, has a proper parser/compiler that can be improved to handle stuff like this correctly. It was basically impossible to support a syntax like this in zMUD. One of the many reasons the CMUD design is better.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Oct 14, 2006 4:10 am   
 
Nice I've wanted something like this for a long time. I found some odities though.

Code:

#if (@a>1)
  {
 #if (@test) {do this} {Do that}
 #if (@test) {do this} {Do that}
  }


Compiles fine and works as does.

Code:

#if (@a>1)
  {
       #if (@test) {do this} {Do that}
 #if (@test) {do this} {Do that}
  }


But this doesn't.

Code:

#if (@a>1)
  {
       #if (@test) {do this} {Do that}
       #if (@test) {do this} {Do that}
  }


Or this

Code:

#if (@a>1)
  {
           #if (@test) {do this} {Do that}
       #if (@test) {do this} {Do that}
  }


Or this

Code:

#if (@a>1)
  {
       #if (@test) {do this} {Do that}
           #if (@test) {do this} {Do that}
  }
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Rugbystyle
Wanderer


Joined: 07 Oct 2001
Posts: 71

PostPosted: Sat Oct 14, 2006 6:10 am   
 
Arminas wrote:
Nice I've wanted something like this for a long time. I found some odities though.

Code:

#if (@a>1)
  {
 #if (@test) {do this} {Do that}
 #if (@test) {do this} {Do that}
  }


Compiles fine and works...


I have troubles with a set up like that, when using functions.

For example, this compiles
Code:

#IF (@allow)
   {
   say go
   say no
   }


This will not compile
Code:

#IF (@allow)
   {
   #ECHO go
   #ECHO no
   }

It gives me an "argument expected" when compiling. Any combination of functions I tried, did the same thing.

However, this will compile
Code:

#IF (@allow)
   {
   #ECHO go;#ECHO no
   }
_________________
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sat Oct 14, 2006 6:19 am   
 
Looks like there are some quirks in the implementation. Not sure why, but my guess is that the it's overwriting the value of the current indent variable somewhere. Not unexpected for the first version with a new syntax like this.
Reply with quote
Riesz
Novice


Joined: 16 May 2006
Posts: 35
Location: Plymouth, England

PostPosted: Sat Oct 14, 2006 10:39 am   
 
I'm really glad to see this, I've always despised the single { on the end of the first command line, I want it on the next line usually by itself so that the closing bracket is on the same indent. I find it greatly enhances code readability. Shame the former syntax is surprisingly common, but that's just a gripe for me :P Good work on this!
_________________
Elaria, Lusternia.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Oct 14, 2006 1:34 pm   
 
Ment to edit this post and posted twice..
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram

Last edited by Arminas on Sat Oct 14, 2006 1:54 pm; edited 1 time in total
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Oct 14, 2006 1:45 pm   
 
When you go to the next line when cmud MUST have a space, you have to add an extra space for ONLY that line. On the next line you MUST have only one space. I guess I should have said that in my previous post.

Rugbystyle your example isn't working because you added extra spaces. here are our two examples side by side.

Code:

#if (@a>1)
  {
 #if (@test) {do this} {Do that}
 #if (@test) {do this} {Do that}
  }

#IF (@allow)
   {
   say go
   say no
   }


Please note that Rugbystyle's code has added spaces.
And that the added spaces are what is wrong with my failed examples.
I was trying to point out with the added examples that further indentations when a space is NOT needed break the syntax, except in the first line of the multi line value.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Rugbystyle
Wanderer


Joined: 07 Oct 2001
Posts: 71

PostPosted: Sat Oct 14, 2006 5:30 pm   
 
Actually the part of the code that you quoted for me is code that DOES work. The only time it did not work is when I had the two functions.
_________________
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Oct 14, 2006 7:08 pm   
 
Ah, my bad. I qouted the wrong line then. Try it with the spaces like in my example and it should work.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Oct 17, 2006 12:05 am   
 
OK, I have found some of the problems with the new multiline syntax. Turned out to be a bit more complicated than I expected. I think I've got it working for 1.11. The examples shown in this topic work properly.

One comment about one of the examples from Arminas:
Code:
#if (@a>1)
  {
       #if (@test) {do this} {Do that}
           #if (@test) {do this} {Do that}
  }

That example should NOT compiled. The third #if statement is indented more than the previous line, which is treated as a continuation of the previous line. But an #IF command is not allowed as the 4th argument of the previous #IF command, so the syntax error is correct. This still produces a correct syntax error in 1.11.

Anyway, sorry this screwed up so many existing multiline scripts Sad
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Oct 17, 2006 1:07 am   
 
Heh, I didn't think it should, was just trying to be thurough.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net