mIRC Homepage
Posted By: Charlie incorrect parse tokenize - 23/06/03 04:01 PM
anybody can help me?

i have following problems, mirc won't parse following token correctly

Code:
 
 set %token a,b,c,,e
 echo -a --> $gettok(%token,4,44)

as result i get --> e <-- instead, an empty value

is there a mirc bug, or just a script error from my side?
any idea, guys?
Posted By: starbucks_mafia Re: incorrect parse tokenize - 23/06/03 05:11 PM
It's a shortcoming of the scripting langauge.
Posted By: KingTomato Re: incorrect parse tokenize - 23/06/03 08:22 PM
Thats the same reason why mirc doesn't allow double spaces. Any consecutive delimiters (such as spaces in a sentance) are reduced to one.
Posted By: Raccoon Re: incorrect parse tokenize - 23/06/03 11:19 PM
If it is really important to handle an empty value, you could do one of two things. Store an actual space between the commas instead of nothing, or store $null if that is more suitable.

Or if you have no control over the data, you can use a regular expression which is very static about its back-references.

Code:
var %token = a,b,c,,e
var %re = /^(.*?),(.*?),(.*?),(.*?),(.*?)$/
var %nul = $regex(%token,%re)
echo -a $regml(1) / $regml(2) / $regml(3) / $regml(4) / $regml(5)
The only problem is you're limited to a static number of delimited items in my above example. I'm sure there's a way to make it more dynamic, but I can't think of one right now. Yet, $regml(4) indeed returns nothing.

- Raccoon
Posted By: codemastr Re: incorrect parse tokenize - 23/06/03 11:54 PM
Maybe what should be done is a property for $*tok called "all" where if you do like $gettok(.....).all it will include $null entries. That way it's still backwards compatible, but people who want this feature can use it.
Posted By: Charlie Re: incorrect parse tokenize - 24/06/03 08:17 AM
thanks guys for your reply all

i have solved the problem with insert 0 (zero) when the value is empty.

Code:

 var %token = $iif(%a,a,0) $+ , $+ $iif(%b,b,0) $+ , $+ $iif(%c,c,0) $+ , $+ $iif(%d,d,0) $+ , $+ $iif(%e,e,0)
 echo -a --&gt; $gettok(%token,4,44)

i know, the code is not clean, but with this one i can fix the problems inside my script :tongue:
Posted By: qwerty Re: incorrect parse tokenize - 24/06/03 10:06 AM
You mean something like this?
Code:
alias gettokn {
  if $2 !isnum || $3 !isnum 1-255 { return }
  var %c = \x $+ $base($3,10,16,2)
  !.echo -q $regex(gettokn,$1,/(?&lt;=^| $+ %c $+ )([^ $+ %c $+ ]*)(?=$| $+ %c $+ )/g)
  return $regml(gettokn,$iif($2 &lt; 0,$calc($regml(gettokn,0) + 1 + $2),$2))
}


Works like $gettok(), same parameters etc. There's no support for token ranges but it does support negative indexes (e.g. $gettokn(a.b..c.d,-2,46)).
Posted By: Charlie Re: incorrect parse tokenize - 24/06/03 11:06 AM
super qwerty,

this code help me so much, thanks you
Posted By: Raccoon Re: incorrect parse tokenize - 24/06/03 07:57 PM
Qwerty... You're gonna have to share some of your mad regex skillz.

/(?<=^| ...
* Raccoon blinks, "Didn't know mIRC could do those..."
And here I was trying to figure out how to get \G to work. crazy

Would using the /x flag save you from having to use $+ in the expression?

- Raccoon
Posted By: codemastr Re: incorrect parse tokenize - 24/06/03 08:50 PM
mIRC doesn't support any regex, PCRE does. And PCRE supports whatever Perl supports, and perl is the one that invented look behind afaik.
Posted By: Raccoon Re: incorrect parse tokenize - 24/06/03 08:59 PM
It's a matter of inherence. When I say 'mIRC could do', I'm naturally referring to mIRC and anything that it is composed of... including PCRE, C++, and x86 machine language. I never suggested Khaled was at all responsible for or supports it, or that other applications using PCRE were any less capable.

picky picky poo.
Posted By: codemastr Re: incorrect parse tokenize - 24/06/03 10:24 PM
My point was that, 99.9% PCRE = Perl regex. And since Perl regex has lookbehind, so does PCRE, and since mIRC uses PCRE, so does mIRC.
Posted By: qwerty Re: incorrect parse tokenize - 25/06/03 12:30 AM
Would using the /x flag save you from having to use $+ in the expression?

Damn right it would... smart usage of /x, I should keep it in mind smile
© mIRC Discussion Forums