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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue May 04, 2010 8:32 pm   

Need some help with an ANSI pattern
 
Here's the pattern:
Code:

(<(used as|worn on|worn around|floating)?\s?(light|finger|neck|torso|head|legs|feet|hands|arms|shield|body|waist|waist|wrist|wielded|held|nearby|sheathed)>\s+(?:%e[0S\(%e[1;34mBlue Aura%e[0S\)%e[0m\s)?)((?:%e[0S\(%e[36mGlowing%e[0S\)%e[0m\s)?(?:%e[0S\(%e[53mHumming%e[0S\)%e[0m\s)?(.*))


Yeah, it's a mess. It also doesn't work, I get an error in the trigger pattern that I don't understand. What is it supposed to match?

Code:

<used as light>     (Blue Aura) (Glowing) a small glowing blue ball
<worn on finger>    (Blue Aura) (Glowing) (Humming) a ring of wizardry
<worn around neck>  (Glowing) a crystal necklace
<worn on torso>     (Glowing) (Humming) a deep blue cloth shirt with intricate designs
<worn on head>      (Glowing) a deep blue cloth bandana, thinly wrapped and knotted tightly
<worn on legs>      (Glowing) (Humming) a pair of deep blue cloth pants, embroidered carefully
<worn on feet>      (Glowing) a pair of deep blue cloth shoes, plated with mithril
<worn on hands>     (Glowing) a pair of deep blue cloth gloves with finger holes
<worn on arms>      (Glowing) a pair of deep blue cloth sleeves, layered with folds
<worn as shield>    (nothing)
<worn about body>   (Glowing) a deep blue cloth robe,bearing intricate designs
<worn about waist>  (Glowing) a deep blue cloth rope, knotted and wound tightly
<worn around wrist> (Glowing) a fine thin mithril bracer with deep blue designs
<worn around wrist> (Glowing) a fine thin mithril bracer with deep blue designs
<wielded>           (Glowing) a quartz staff
<held>              (Glowing) a wand of elm wood
<floating nearby>   (Blue Aura) a golden acorn


Essentially, the string is built up in 3 parts:
<eq slot> (flags) short_desc

The possible slots are:
used as light, worn on finger, worn on finger, worn around neck, worn around neck, worn on torso, worn on head, worn on legs, worn on feet, worn on hands, worn on arms, worn as shield, worn about body, worn about waist, worn around wrist, worn around wrist, wielded, held, floating nearby, sheathed

There's a variable number of spaces between the slots and the flags

The three possible flags are:
Blue Aura, Glowing, Humming, all in () and in that priority aura in the string. They all have 1 space between them if they exist (they don't always all exist, it can be just a Blue Aura, or just a Glowing, or just a Humming, or a Blue Aura and a Glowing, or a Blue Aura and a Humming, or a Blue Aura and a Glowing and a Humming, etc...)

There's one space between the flags and the short description
The short description can be just about anything. Hence the .*

The pattern uses ANSI and Regex.

The pattern below is just Regex and matched all possibilities perfectly, but didn't preserve color:
Code:

(<(used as|worn on|worn around|floating)?\s?(light|finger|neck|torso|head|legs|feet|hands|arms|shield|body|waist|waist|wrist|wielded|held|nearby|sheathed)>\s+(?:\(Blue Aura\)\s)?)((?:\(Glowing\)\s)?(?:\(Humming\)\s)?(.*))


For the following: <worn on hands> (Blue Aura) (Glowing) some silksteel cloth gloves
We'd get:
%1=<worn on hands> (Blue Aura)
%2=worn on
%3=hands
%4=(Glowing) some silksteel cloth gloves
%5=some silksteel cloth gloves

Now, this is fine, except, I use a #SUB in the script which ends up using strings without the ANSI color:
Code:

$_short=%trim( %5)
$_echo=%null
$_sub=0
$_end=%4
$_end=%replace( $_end, "(Glowing)", "("%ansi( 3)"Glowing"%ansi( reset)")")
$_end=%replace( $_end, "(Humming)", "("%ansi( 14)"Humming"%ansi( reset)")")
$_beg=%1
$_beg=%replace( $_beg, "(Blue Aura) ", "")
#IF (%iskey( @_bless_eq, $_short)) {
  $_bless=%format( & 2 s, %string( %db( @_bless_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 9)$_bless%ansi( reset)") ")
  $_sub=1
  }
#IF (%iskey( @_fp_eq, $_short)) {
  $_fp=%format( & 2 s, %string( %db( @_fp_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 12)$_fp%ansi( reset)") ")
  $_sub=1
  }
#IF ($_sub) {#SUB %concat( $_beg, $_echo, $_end)}


The colors for the flags are:
Blue Aura=Bright Blue (9)
Glowing=Dark Cyan (3)
Humming=Bright Yellow (14)

So, for those, I could simply put the color back in if I wanted to. The problem comes in with the short description. The short descriptions in DSL are widely varied, and the color in them is extremely varied as well. I can't possibly predict the color differences in the short descriptions and my only alternative is to have a massive database of short descriptions with their appropriate color-coding, or, to use a wildcard (.*) and an ANSI trigger.

Help would be appreciated. Essentially, I need my pattern to not error out, and it needs to match everything that I've tried to get it to match. It doesn't need to be regex, but I can't afford to lose any of the power that I have in regex to use zscript. So, I can get the exact same matching without the regrex, great. If there's even a minor difference it could cause problems. I used regex because it's what I'm more comfortable with. But I'm beginning to wonder if Regex and ANSI trigger don't mix? Help is appreciated.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue May 04, 2010 10:14 pm   
 
Odd followup issue. I went back to the old pattern while I'm waiting to figure this out.

The pattern is:
Code:

(<(used as|worn on|worn around|floating)?\s?(light|finger|neck|torso|head|legs|feet|hands|arms|shield|body|waist|waist|wrist|wielded|held|nearby|sheathed)>\s+(?:\(Blue Aura\)\s)?)((?:\(Glowing\)\s)?(?:\(Humming\)\s)?(.*))


When I use this: <used as light> (Blue Aura) a ray of hope
I get:
%1=<used as light> (Blue Aura)
%2=Used as
%3=light
%4=a ray of hope
%5=a ray of hope

That all makes sense, but the trigger wasn't properly subbing in. So I wanted to see if it was seeing the short correctly. So I put in a #show $_short command.

Code without the #show $_short
Code:

$_short=%trim( %5)
$_echo=%null
$_sub=0
$_end=%4
$_end=%replace( $_end, "(Glowing)", "("%ansi( 3)"Glowing"%ansi( reset)")")
$_end=%replace( $_end, "(Humming)", "("%ansi( 14)"Humming"%ansi( reset)")")
$_beg=%1
$_beg=%replace( $_beg, "(Blue Aura) ", "")
#IF (%iskey( @_bless_eq, $_short)) {
  $_bless=%format( & 2 s, %string( %db( @_bless_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 9)$_bless%ansi( reset)") ")
  $_sub=1
  }
#IF (%iskey( @_fp_eq, $_short)) {
  $_fp=%format( & 2 s, %string( %db( @_fp_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 12)$_fp%ansi( reset)") ")
  $_sub=1
  }
#IF ($_sub) {#SUB %concat( $_beg, $_echo, $_end)}


Code with the $_show_short
Code:

$_short=%trim( %5)
$_echo=%null
$_sub=0
$_end=%4
$_end=%replace( $_end, "(Glowing)", "("%ansi( 3)"Glowing"%ansi( reset)")")
$_end=%replace( $_end, "(Humming)", "("%ansi( 14)"Humming"%ansi( reset)")")
$_beg=%1
$_beg=%replace( $_beg, "(Blue Aura) ", "")
#show $_short
#IF (%iskey( @_bless_eq, $_short)) {
  $_bless=%format( & 2 s, %string( %db( @_bless_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 9)$_bless%ansi( reset)") ")
  $_sub=1
  }
#IF (%iskey( @_fp_eq, $_short)) {
  $_fp=%format( & 2 s, %string( %db( @_fp_eq, $_short)))
  $_echo=%concat( $_echo, "("%ansi( 12)$_fp%ansi( reset)") ")
  $_sub=1
  }
#IF ($_sub) {#SUB %concat( $_beg, $_echo, $_end)}


And this is what it displayed:
(Blue Aura) a ray of hope


Why is the %5 from the test different from what it's actually grabbing?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 05, 2010 1:38 am   
 
Regarding your second posting: I just tested it here, and it works fine, displaying "a ray of hope". When you tested this, were you just typing the text on the command line? If you do, remember that you have to escape the parentheses with tildes: "<used as light> ~(Blue Aura~) a ray of hope "
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 05, 2010 2:11 am   
 
For the first posting: in regular expressions, use \e instead of %e, and escape square brackets just like you do parentheses: [ and ].
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed May 05, 2010 2:57 am   
 
I wasn't testing it with my own commands, I was actually looking at output from the MUD and it wasn't working. Not sure what was up, but I'll try again. Thanks for the comments on REGEX and ANSI.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed May 05, 2010 3:27 am   
 
It absolutely refuses to work for me, maybe you could put up the pattern you're using? I have no idea why it fails
<used as light> (Blue Aura) a ray of hope

Gives:
(Blue Aura) a ray of

and

<used as light> a ray of hope

gives

a ray of

I have no idea... *sighs*

It looks to me like it's trying to match one of the ones before the .* because they're optional, so it's being lazy. Any way I can make it greedy?


Edit:
Breaking down into simpler chunks to solve this:

Code:

(^<({@_slots})>\s+\(Blue Aura\))\s?(.*)$


Works perfectly with:
Code:

<used as light>     (Blue Aura) a ray of hope


%1=<used as light> (Blue Aura)
%2=used as light
%3=a ray of hope

I then made it optional
Code:

(^<({@_slots})>\s+(?:\(Blue Aura\))?)\s?(.*)$


But got the same results

Alright. So, I need to add in the other flags. However, I wanted to get ANSI working. So, I ticked off the ANSI box and copied and pasted some sample text from CMUD into the pattern box:
Code:

%e[0S(%e[1;34mBlue Aura%e[0S)%e[0m


Is what I got, however, holding to what Rahab suggested, I converted all of the %s to \ and escaped all of the [s
So, I get

Code:

\e\[0S\(\e\[1;34mBlue Aura\e\[0S\)\e\[0m


Code:

(^<({@_slots})>\s+(?:\e\[0S\(\e\[1;34mBlue Aura\e\[0S\)\e\[0m)?)\s?(.*)$


Now, suddenly, the pattern doesn't match. So, I tried getting to to fire in the game, I changed the script text to #say Fire!

And then I put this through the command line:

Code:

#show <used as light>       ~(%ansi(9)Blue Aura%ansi(reset)~) a ray of hope


Didn't work, so I tried:
Code:

#show "<used as light>       ("%ansi(9)"Blue Aura"%ansi(reset)") a ray of hope"


Still didn't work. I'm at a loss right now. I have nothing left in me to know what I can do.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 05, 2010 1:52 pm   
 
Can you show the ansi pattern that you last used? Here is what I did:

I created a blank trigger, and marked it ANSI Trigger and Regular Expression
I wrote on the command line:
Quote:
#show test ~(%ansi(blue)Blue Aura%ansi(reset)~) test

I cut and pasted the resulting output into the trigger pattern:
Code:
test (%e[34mBlue Aura%e[0m) test

I put "#show success" into the trigger script
I edited the pattern like so:
Code:
test \(\e\[34mBlue Aura\e\[0m\) test$

I sent the text from the command line again, and it worked.

Maybe you need to get rid of the %e[0S at the beginning and %e[0m at the end when you start out, unless those codes are actually coming in from your mud. They aren't there in my tests, but I'm only inputting from the commandline.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed May 05, 2010 2:44 pm   
 
Yeah, I've done all that. And it generally seems to work there, but not in the implementation of my script. I really have nothing else left in me to try, to be honest. Here's the pattern I used:
Code:

(<({@_slots})>\s+(?:\(\e\[54mBlue Aura\e\[0m\))?)\s?((?:\(\e\[36mGlowing\e\[0m\))?\s?(?:\(\e\[53mHumming\e\[0m\))?)?(.*)


I got the regex pattern working again:
Code:

(<({@_slots})>\s+(?:\(Blue Aura\))?)\s?((?:\(Glowing\))?\s?(?:\(Humming\))?)?(.*)


Though, for some reason, it doesn't seem to like one line in particular which I will post when I get a chance.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed May 05, 2010 11:44 pm   
 
I've worked with DraxDrax and he created a nifty way of capturing everything neatly in a multi-state trigger. I've simply applied my script on adding in the new information and voila. It works. With one odd and notable problem:

Code:

<trigger name="equip_trigger" priority="4210" id="1358">
  <pattern>^You are using:$</pattern>
  <trigger type="Manual" ansi="true" trigontrig="false">
    <pattern>^(*)$</pattern>
    <value><![CDATA[#SWITCH %null( %trigger) {#STATE equip_trigger 0}
  (%match( %trigger, "^%e[0S<(*)>(%s)(*)$", $location, $spaces, $item)) {
  $_short = %trim( %stripansi( %word( $item, %numwords( $item, ")"), ")")))
  #DEBUG %concat( %ansi( bright, cyan), "$location = "$location, " | $short = ", $_short, " | $item = ", %ansi( default), $item)
  #LOCAL $_echo $_sub
  #IF (%iskey( @_bless_eq, $_short)) {
    $_bless=%format( & 2 s, %string( %db( @_bless_eq, $_short)))
    $_echo=%concat( $_echo, %ansi( reset)"("%ansi( 9)$_bless%ansi( reset)")")
    $_sub=1
    }
  #IF (%iskey( @_fp_eq, $_short)) {
    $_fp=%format( & 2 s, %string( %db( @_fp_eq, $_short)))
    $_echo=%concat( $_echo, %ansi( reset)"("%ansi( 12)$_fp%ansi( reset)")")
    $_sub=1
    }
  $_echo=%concat( $_echo, " ")
  #IF ($_sub) {#SUB %concat( "< ", $location, " >", $spaces, $_echo, $item, %cr)}
  }]]></value>
  </trigger>
</trigger>


Putting the < > back in creates this problem
Code:


You are using:
< used as light >     (34)(47) (Blue Aura) a ray of hope
< worn on finger >    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
< worn on finger >    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
< worn around neck >  (48)(48) (Blue Aura) (Glowing) the sandshark skin
< worn around neck >  (48)(48) (Blue Aura) (Glowing) the sandshark skin
<worn on torso>     (Glowing) a silksteel cloth shirt
<worn on head>      (Glowing) a silksteel cloth helmet
<worn on legs>      (Glowing) some silksteel cloth leggings
<worn on feet>      (Glowing) some silksteel cloth boots
<worn on hands>     (Glowing) some silksteel cloth gloves
<worn on arms>      (Glowing) some silksteel cloth sleeves
<worn as shield>    (Glowing) a crystal shield
<worn about body>   (Glowing) a long robe
<worn about waist>  (Glowing) a leather loin-cloth
<worn around wrist> (Glowing) a finely crafted mithril bracer
<worn around wrist> (Glowing) a finely crafted mithril bracer
<wielded>           (Glowing) (Humming) a slender staff of rose quartz
<held>              (Glowing) a holy symbol
<floating nearby>   a petrified sand wyrm egg
<sheathed>          a shining sword glowing purple
<worn as quiver>    (Glowing) (Humming) a leather quiver covered in ancient runes


As you can tell, some of them are not quite like the others. Notable the subbed lines! No idea what's causing it, but neither of us know what's going on. DraxDrax wonders if perhaps it's a carry over from zMud where they apparently forced the expansion of variables? If so, is it possible to be fixed? Is there a work around. I'm quite excited that it's finally working, so this is but a small worry. But hey, I'd love to make it perfect.

To be clear. If you take the spaces out of the "< " " >" in the concat, they will not show up when the line is presented in the MUD window.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Thu May 06, 2010 12:16 am   
 
To put that another way...

The line:
Code:
#SUB %concat( "< ", $location, " >", $spaces, $_echo, $item, %cr)

From within the trigger chemanas posted works more or less as intended, but adds spaces inside of the <> characters, around the $location variable, which chamenas doesn't want.
It gives output like this:
Code:
< used as light >     (34)(47) (Blue Aura) a ray of hope
< worn on finger >    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
< worn on finger >    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King


If you remove the spaces from the code and instead have the line:
Code:
#SUB %concat( "<", $location, ">", $spaces, $_echo, $item, %cr)

It doesn't display $location at all and instead gives output like this:
Code:
     (34)(47) (Blue Aura) a ray of hope
    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King

Which seems to be a bug.

Ideally what is desired is output that looks like this:
Code:
<used as light>     (34)(47) (Blue Aura) a ray of hope
<worn on finger>    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
<worn on finger>    (35) (Blue Aura) (Glowing) (Humming) a ring of the Gypsy King
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu May 06, 2010 5:40 pm   
 
Yes, that is extremely weird, but I confirm that behavior. It does look like a bug to me. If you put any non-alphabetic character inside the quotes after the left-angle, e.g. "<1", "<~", "<*", the #sub works correctly. If the content between angle-brackets starts with an alphabetic character, it misbehaves like this. I also tried putting the %concat into a variable, $line, and doing "#sub $line", and it still misbehaved. However, if I simply do "#sub "<foobar> blah blah", it works fine. It looks to me like #sub is translating <something> as MXP under some circumstances, when it has to interpret the substitution line.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu May 06, 2010 5:52 pm   
 
I believe it is to do with MXP and if you enable the "Show unknown tags" option then the $location items will display fine on screen when only "<" and ">" are used instead of "< " and " >".
_________________
Taz :)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu May 06, 2010 7:08 pm   
 
That seems to be it, Taz. Thanks :)
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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