mIRC Home    About    Download    Register    News    Help

Print Thread
incorrect parse tokenize #31681 23/06/03 04:01 PM
Joined: Dec 2002
Posts: 29
C
Charlie Offline OP
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 29
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?


Charlie
Re: incorrect parse tokenize #31682 23/06/03 05:11 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
It's a shortcoming of the scripting langauge.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: incorrect parse tokenize #31683 23/06/03 08:22 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Thats the same reason why mirc doesn't allow double spaces. Any consecutive delimiters (such as spaces in a sentance) are reduced to one.


-KingTomato
Re: incorrect parse tokenize #31684 23/06/03 11:19 PM
Joined: Feb 2003
Posts: 2,659
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,659
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: incorrect parse tokenize #31685 23/06/03 11:54 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Re: incorrect parse tokenize #31686 24/06/03 08:17 AM
Joined: Dec 2002
Posts: 29
C
Charlie Offline OP
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 29
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:


Charlie
Re: incorrect parse tokenize #31687 24/06/03 10:06 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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)).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: incorrect parse tokenize #31688 24/06/03 11:06 AM
Joined: Dec 2002
Posts: 29
C
Charlie Offline OP
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 29
super qwerty,

this code help me so much, thanks you


Charlie
Re: incorrect parse tokenize #31689 24/06/03 07:57 PM
Joined: Feb 2003
Posts: 2,659
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,659
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: incorrect parse tokenize #31690 24/06/03 08:50 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
mIRC doesn't support any regex, PCRE does. And PCRE supports whatever Perl supports, and perl is the one that invented look behind afaik.

Re: incorrect parse tokenize #31691 24/06/03 08:59 PM
Joined: Feb 2003
Posts: 2,659
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,659
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.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: incorrect parse tokenize #31692 24/06/03 10:24 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Re: incorrect parse tokenize #31693 25/06/03 12:30 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com