mIRC Home    About    Download    Register    News    Help

Print Thread
Comment parsing bug/prob #167312 22/12/06 09:18 AM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
Code:
alias bugtest { 
  if (1 == 1) { 
    if (2 == 1) { ;echo -a one | ;echo -a two }
    else { echo -a False }
  }
}


Those comments are obstructing the if statement becuase it is stripping out the commands but not the relative |, better parsing would solve.

I found the problem when i was trying to do this:
Code:
if ($readini($scriptdirconfig.ini,bot-config,authserv)) { ;.timer 1 1 %sw mode %me +x | ;.timer 1 1 %sw as AUTH $v1 }

Last edited by HellRaz0r; 22/12/06 09:24 AM.
Re: Comment parsing bug/prob [Re: HellRaz0r] #167313 22/12/06 09:44 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
The reason it wont echo is because mIRC sees it as this:
Php Code:

alias bugtest { 
  if (1 == 1) { 
	if (2 == 1) { ;echo -a one | ;echo -a two }
	  else { echo -a False }
	}
  }
 

So the else is never evaluated as its become part of the if.
However the Remote's {} will see it differently

the "problem" is that while using IF ; doesnt make | lose its special meaning
Php Code:
alias bugtest { 
  if (1) { ;echo a hello | echo -a this triggers! }
  ;echo a hello | echo -a this doesn't trigger!
}
 

and it shouldnt really as well.
since it didnt encounter ; before if so it evals if and see an opening bracket. It sees that there are characters after { so it tries tokenizing | to get the commands it then finds out they are comments ";echo -a one" and ";echo -a two }" so therefor doesnt do anything and move to the next line which is else { echo -a False } it didnt find a conditionial before in the if statement clausal so else is ignored.

This is of course my own reasoning though smile


$maybe
Re: Comment parsing bug/prob [Re: Mpdreamz] #167317 22/12/06 11:53 AM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
that didnt make much sense Mpdreamz, found a workaround solution for this problem, maybe khaled will fix in the next release.

Code:
;works, i shouldnt have to put | at the end tho.
alias bugtest { 
  if (1) { 
    if (2 == 1) { ;echo -a one | ;echo -a two | }
    else { echo -a False }
  }
} 

Last edited by HellRaz0r; 22/12/06 11:58 AM.
Re: Comment parsing bug/prob [Re: HellRaz0r] #167318 22/12/06 11:57 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Of course, it wont comment the } anymore like that. Like i explained earlier on | takes higher precedence than ; inside the IF statement not elsewhere smile

Last edited by Mpdreamz; 22/12/06 12:00 PM.

$maybe
Re: Comment parsing bug/prob [Re: Mpdreamz] #167319 22/12/06 12:01 PM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
:|

Last edited by HellRaz0r; 22/12/06 12:22 PM.
Re: Comment parsing bug/prob [Re: HellRaz0r] #167320 22/12/06 12:18 PM
Joined: Jul 2003
Posts: 655
Om3n Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
I understood just fine...

alias bugtest {
if (1 == 1) {
if (2 == 1) { ;echo -a one | ;echo -a two }
else { echo -a False }
}
}

As they explained, the pipe takes higher precedance than the semicolon. The semicolon is a SINGLE line comment, everything is ignored until the END of the line. Because the pipe has higher precedance, the first commented command ends at the pipe, however the comment has higher procedance than the }, therefor the second comments command ignores EVERYTHING until the end of the line, INCLUDING the }. As a result that second if statement is never closed, again as already explained.

The problem is not with mircs comment handling (it is right to include the brace in the ignored/commented text), the problem was with the way you wrote the code. (or more acurately, your method of commenting in that style of code layout)

If there is any issues here at all, then it is the inconsistancy between the parser and the bracket matching feature of the script editor. (again as already mentioned)

Last edited by Om3n; 22/12/06 12:20 PM.

"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Re: Comment parsing bug/prob [Re: Om3n] #167321 22/12/06 12:32 PM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
Om3n i understood your explanation properly, thanks

Re: Comment parsing bug/prob [Re: Om3n] #167337 22/12/06 04:01 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
I would consider that behaviour a bug. To have pipes and braces with different precedence in the syntax relative to comments is IMO a mistake.

Pipes and braces are very similar in that they are both delimiting syntax so I think comments should ignore both since the only thing defining single-line comments is that they run to the end of the line. It'd be far easier to scan code if you knew that a comment at the start of the line meant everything on that line is definitely a comment without exception.

Since comments are made for people reading the code and have no relevance to code execution it makes sense that they are tailored to helping people, well, read the code. This is how single-line comments work in all other languages I'm aware of.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Comment parsing bug/prob [Re: starbucks_mafia] #167358 22/12/06 09:58 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Yeah, I understand why | isn't commented out, but I agree that it should be. It shouldn't ignore the fact that it is commented. Just think what would happen to someone who puts a LOT of commands on each line with tons of pipes -- if he/she commented out the line (or thinks he/she did), the pipes would make the rest of the commands uncommented and would just cause problems.


Invision Support
#Invision on irc.irchighway.net
Re: Comment parsing bug/prob [Re: Riamus2] #167359 22/12/06 10:13 PM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
i dont believe | should be commented because the pipes define when a comment or command ends/begins, it would be nice if the comment stops before } tho instead of making it stop at the end of the line, then for statements which dont have { } the comment can stop at the end of the line, that would seem the logical way.

Last edited by HellRaz0r; 22/12/06 10:20 PM.
Re: Comment parsing bug/prob [Re: HellRaz0r] #167363 22/12/06 10:43 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
I do agree | should have higher precedence.
Using comments like this
if () { command | ;comment | ;comment }
does not improve reading to begin with, and i honestly dont see why anyone would want to do it.

| signals a "new line"

| is ignored in
; this doesnt echo | echo -a yay
where its easily traceable

In a condensed if it would be hard to spot a literal | and a "new line" |. in fact once commented you'd have to put an actual new line to start a new command.

It shouldnt ignore } in those cases just to accommodate a scripting way that is pretty awful to begin with.


$maybe
Re: Comment parsing bug/prob [Re: Mpdreamz] #167364 22/12/06 11:00 PM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
Comments are not just for reading, they are also useful to disable command usage.
Its not very nice having to take small 1 line conditionals then spread them across multiple lines just to stop the comment from eating }
Its also not nice having to end a comment with | to make it stop before it eats }


Last edited by HellRaz0r; 22/12/06 11:11 PM.
Re: Comment parsing bug/prob [Re: HellRaz0r] #167365 22/12/06 11:11 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
If it was really a one-line conditional it wouldn't be using pipes would it?

Obviously commenting out code is used when testing or fixing bugs, but you'd never leave commented out commands in the code for any long period of time, so even if you were hell bent on cramming every command on a single line you'd only need to press enter once to get the desired effect while you tested/bugfixed/whatever. ie.
Code:
if { ; commented out commands | more commented commands
_not_ commented commands | yet more commands _not_ commented out
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Comment parsing bug/prob [Re: starbucks_mafia] #167366 22/12/06 11:19 PM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
yes and thats retarded, you dont have to do that in any other language ive seen and it is something that could easily be avoided by applying some simple logic to the parser.

i doubt im the first person to find this problem annoying and i probably wont be the last.


Re: Comment parsing bug/prob [Re: HellRaz0r] #167368 22/12/06 11:30 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Here's an example of what I was trying to say...
Code:
on *:input:#: {
  if ($1 == !stats) { echo -a Displaying stats... | msg $chan Here are the stats (line 1) | msg $chan Here are the stats (line 2) }
  elseif ($1 == !help) { echo -a Displaying help... | msg $chan This is the help (line 1) | msg $chan This is the help (line 2) }
}


Granted, I would never code that way, but many people do for some really strange (imo) reason.

Anyhow, let's say that I want to comment out the elseif line to test or for some other reason. If pipes stop the comment, then I can't just put a semicolon in front of that entire line. It will prevent the if and echo parts, but the msg lines will still occur and they wouldn't even be in an ELSEIF statement anymore... they'd appear no matter what was typed. I really think that is a BAD thing. I shouldn't have to put a semicolon at the beginning of the line AND after every pipe just to make the entire line commented.

As a side note, if people stopped putting many commands all on one line instead of spreading them out across multiple lines to make the code easier to read and so you don't have to scroll horizontally just to see what is happening, none of this would matter. I admit that I use pipes occasionally, but I usually only use them for error checking lines... if (this is true) { echo -a error | return }. That sort of thing.

Anyhow, everyone can script however they want to since there isn't an official standard to follow.


Invision Support
#Invision on irc.irchighway.net
Re: Comment parsing bug/prob [Re: HellRaz0r] #167369 22/12/06 11:46 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Which languages? In most languages I'm aware of you couldn't even get away with breaking comments using pipes.

Code:
Python:		# print "hello"; print "there"
Javascript:	// alert("hello"); alert("there");
C/C++:		// fputs("hello", stdout); fputs("there", stdout);
PHP:		// echo("hello"); echo("there");
Delphi:		// SomeCommand("hello"); SomeCommand("there");

All of those would ignore the second command after the semi-colon (their equivalent to a pipe).

While the fact that other languages do it doesn't necessarily mean mIRC should too, the fact is that it's not a case where the designers of those languages flipped a coin and ended up doing it that way - it's a purposeful design characteristic which benefits anyone who has to read or maintain code.

On the other hand, if for whatever reason Khaled decides that the current handling of pipes in comments should stay it would make sense for comments to respect braces aswell.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Comment parsing bug/prob [Re: starbucks_mafia] #167371 23/12/06 12:39 AM
Joined: Dec 2006
Posts: 12
H
HellRaz0r Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Dec 2006
Posts: 12
Originally Posted By: starbucks_mafia
Which languages? In most languages I'm aware of you couldn't even get away with breaking comments using pipes.


Most other languages dont use pipes because they parse the statement/syntax then they parse the commands and ignores the comments without leaving/eating anything that obstructs the statement/syntax its self.

example: <?php if (1 == 2) { echo 'one'; /* soming */ echo 'two'; } else { echo 'false'; } ?>

Originally Posted By: starbucks_mafia

the fact is that it's not a case where the designers of those languages flipped a coin and ended up doing it that way - it's a purposeful design characteristic which benefits anyone who has to read or maintain code.


thats true altho doesnt mean there isnt room for improvement.

Re: Comment parsing bug/prob [Re: HellRaz0r] #167373 23/12/06 03:18 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Hm... I was able to test this out and I have to withdraw what I said. If you comment the beginning of the line, it comments the entire line regardless of pipes. I thought that was true before I saw this thread, but the thread made me think I was wrong and I couldn't test it.

So pipes only stop a comment (;) if done somewhere in the line itself. That makes sense to me.

Unfortunately, you can't use /* */ inline like you can with php. /* can only be used at the start of the line and you can't put a */ inline, either. Maybe that should be changed and leave pipes as they are?


Invision Support
#Invision on irc.irchighway.net
Re: Comment parsing bug/prob [Re: Riamus2] #167381 23/12/06 04:17 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
Unfortunately, you can't use /* */ inline like you can with php. /* can only be used at the start of the line and you can't put a */ inline, either. Maybe that should be changed and leave pipes as they are?


Not a good plan:

Quote:
/* Comment starts here

echo -a code commented out
echo -a $regex($1, /hello .*/)

Comment ends here */

"damn why is my code creating errors?"

Quoteless strings + abitrary syntax rules = bugs


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Comment parsing bug/prob [Re: starbucks_mafia] #167391 23/12/06 05:03 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I'd say that it would only work inline if both were on the same line. I'm not sure if php does it that way, or not. Anyhow, it was just a random thought. I'd never put a comment in the middle of a line, anyhow.


Invision Support
#Invision on irc.irchighway.net