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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Dec 29, 2005 6:19 pm   

Parsing Bug
 
I've come across the following bug when parsing regular expressions.

The following commands should all match
Code:
#SHOW %match("5 to 9 (average 7)", "(%d) to (%d) ~(average (%d)~)")
#SHOW %match("5 to 9 (average 7)", "(%d) to (%d) \(average (%d)\)")
#SHOW %regex("5 to 9 (average 7)", "(\d+) to (\d+) \(average (\d+)\)")


but only the third one does.
Code:
0
0
1


Has anyone else seen this?

Here's one for you to tackle in CMUD Zugg.
_________________
Asati di tempari!
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Thu Dec 29, 2005 6:31 pm   
 
#2 won't work cause \ is the regex escape char

as for #1 Iit is using the tildes to treat the next char as a literal and then consuming the tilde :p

ie it is trying to perform a match against
#SHOW %match("5 to 9 (average 7)", "(5) to (9) (average (7))")
which wont match cause it is using the parenthesis around average to capture to a var
%1=5
%2=9
%3=average 7
%4=7


Workaround keep the tilde by using two

#SHOW %match("5 to 9 (average 7)", "(%d) to (%d) ~~(average (%d)~~)")
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Dec 29, 2005 8:38 pm   
 
Hey Nexela,

I think I should explained more. I did the one with '\' just to dispel what i thought would get about trying that instead of the tilde. So #2 was really just to stop folks from looking at #1 and saying try '\' instead of the '~'..

As for #1 the pattern I want to match is "5 to 9 (average 7)" and you should notice that the tilde's are only where highlighted... i.e. "(%d) to (%d) ~(average (%d)~)".

So while I'm expecting

%1=5
%2=9
%3=7

which I do get with #3 that's not what I get with #1 because it doesn't show as matching at all.

To be clear the pattern I want to match is 'X to Y (average Z)' where X, Y, and Z are numbers. #1 should match but it doesn't and I'm convinced that it's the parantheses that are throwing off the parsing. I also tried
Code:
#SHOW %match("5 to 9 average 7", "(%d) to (%d) average (%d)")

and that worked as expected.
_________________
Asati di tempari!
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Thu Dec 29, 2005 9:00 pm   
 
The workaround explaned it, use 2 tildes instead of 1

#SHOW %match("5 to 9 (average 7)", "(%d) to (%d) ~~(average (%d)~~)")
Becomes

#SHOW %match("5 to 9 (average 7)", "(5) to (9) ~(average (7)~)")
1

%1=5
%2=9
%3=7
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Dec 30, 2005 12:04 am   
 
Ok... I think I get it now. Not quite sure I agree with the parsing.. but if it keeps all my cool parsing tricks I'll deal with it. :)

That's for the explanation. I totally missed (and I've actually written several parsers and simple compilers.)
_________________
Asati di tempari!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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