You are not logged in.

#1 23 Mar 2016 22:57

dplafoll
Member
Registered: 23 Mar 2016
Posts: 4

Issue with Closing Parentheses [Notepad++ bug]

So I've been building some pretty elaborate batch scripts to do various things for me, and I keep running into a strange problem. In some code blocks, like this one, the opening and closing parentheses for the IF match up just like that, with the closing one on a separate line, just like all the code examples on the internet. (Aside: these are mostly unrelated examples from various scripts; I keep having the same problem in all of them. I've cleaned up some non-essential lines that I think aren't relevant.
Block 1

if !debug0!==d ( 
    @ECHO DEBUG IS ON: BEGIN DEBUG
    call:debugFunction
) 

However, in the following block, the closing parentheses only work right if I move them up to the end of the previous line, both at the end of the IF and the ELSE.
Block 2, inside a function called siteFunction

IF DEFINED SSID[%site%] (
     @ECHO DO STUFF
) ELSE (
     @ECHO DO STUFF
)

I even have a code block with BOTH situations; the IF parentheses work like that, but the ELSE closer does not unless I move it up.
Block 3

if !debug0!==d (
     @ECHO DO STUFF
) ELSE (
     @ECHO DO STUFF
)

Now, obviously I can just put the ) on the working line and go on, but it really disrupts the way I see the code. I'm using Notepad++ which is telling me which ones match up and which ones don't, and I've verified that it's telling me the right thing on these i.e. that second block Notepad++ says they're all unmatched, the IF doesn't run even though the variable is defined, and the ELSE is completely ignored. If I move them to the previous lines, the script works perfectly without any other changes.

Now, here's something else: There's a line above all that in block 2:

if !site!==corp ( call :corpFunction ) ELSE ( call :siteFunction )

With this line, the IF's closing ) is faulty, and Notepad++ says the closing ) for it is the closing ) in the IF in block 2. If I move the ") ELSE..." to the next line:

if !site!==corp ( call :corpFunction 
) ELSE ( call :siteFunction )

It all matches up there, but now ALL of the parentheses stop matching up in block 2, unless moved up. I don't know if it matters, but corpFunction has no parentheses at all.

Sorry for the wall of text, but I wanted to make sure the situation is clear. I may just be a total noob at something here that's super obvious, but I'm stumped. And this is a great problem to have if you want bugs in the code, which I do not. I've searched and searched here and elsewhere but I just can't figure it out. Any help would be appreciated, and I can post or PM more of the code if it helps.

Thanks!

Offline

#2 23 Mar 2016 23:19

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Issue with Closing Parentheses [Notepad++ bug]

You've not explained very well what you mean by "not working".

I've not run them, but all of your posted examples all look like valid code to my eye.  This is based on two assumptions:
1. The various variables you have specified, but not shown the value of, have sane contents -- IE no spaces, no reserved characters.
2. The code you've replaced with "@ECHO DO STUFF" doesn't do anything funky.

It would be of great assistance if you provided two things:
1. Unadulterated samples of a code block that is not working and the same code block in a "working" state, including the values of all variables used therein (it's usually beneficial to provide the entire script so that we can see the context)
2. The verbatim output produced when the problematic section of code is run.


cmd | *sh | ruby | chef

Offline

#3 24 Mar 2016 20:41

DigitalSnow
Member
From: United States
Registered: 27 Dec 2012
Posts: 24

Re: Issue with Closing Parentheses [Notepad++ bug]

Notepad++'s syntax highlighting for CMD/BAT files parenthases is faulty.  So ignore it.

u8I5Aes.png

Offline

#4 24 Mar 2016 20:43

dplafoll
Member
Registered: 23 Mar 2016
Posts: 4

Re: Issue with Closing Parentheses [Notepad++ bug]

DigitalSnow wrote:

Notepad++'s syntax highlighting for CMD/BAT files parenthases is faulty.  So ignore it.

Ha! Well that's dumb, and that explains it. Thanks!

Offline

#5 25 Mar 2016 01:11

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: Issue with Closing Parentheses [Notepad++ bug]

I am afraid I don't understand what happened. Did you said that you though the Batch file have an error because the Notepad++ highlight? Didn't you run such Batch file? sad

Offline

#6 25 Mar 2016 03:40

dplafoll
Member
Registered: 23 Mar 2016
Posts: 4

Re: Issue with Closing Parentheses [Notepad++ bug]

Aacini wrote:

I am afraid I don't understand what happened. Did you said that you though the Batch file have an error because the Notepad++ highlight? Didn't you run such Batch file? sad

Well sure I did. I've got several hundred lines of code here and I didn't just type it all up and hope it all worked the first time. I was getting anomalous results from parts of it, in multiple blocks of code in multiple batch files. It seems what happened was that the Notepad++ problem was causing me to misplace various parentheses, which caused problems like an ELSE block running when it shouldn't, for example. Honestly, I made a faulty assumption which was that the problem was in Windows and not Notepad++, which I'd argue isn't the craziest assumption to make. Thanks for making your own assumptions about me, though. wink

Offline

#7 25 Mar 2016 03:50

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Issue with Closing Parentheses [Notepad++ bug]

I'm confused. So your only problem was that you thought there was a problem when there actually wasn't?

Offline

#8 25 Mar 2016 04:00

dplafoll
Member
Registered: 23 Mar 2016
Posts: 4

Re: Issue with Closing Parentheses [Notepad++ bug]

Shadow Thief wrote:

I'm confused. So your only problem was that you thought there was a problem when there actually wasn't?

Yep, pretty much. Had weird results, was seeing the Notepad++ thing, thought it was Windows not treating parentheses correctly. Pretty dumb problem, but some times that leads you to the right answers. In this case, DigitalSnow helped me out with the right answer, for which I am very grateful. I'm no batch file expert so it's good to know some folks are still willing to help out others on the internet.

BTW if a moderator sees this and wants to close it or delete it I'm cool with that. The question has been answered and I think I'm done explaining my own mistake repeatedly. Cheers.

Offline

#9 25 Mar 2016 05:18

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Issue with Closing Parentheses [Notepad++ bug]

I can see your confusion - PSpad has the same problems with bracket highlighting. 

The guys here are really saying that a short test with a few lines of code often shows the reason for code failing, and is a very good diagnostic step.  If you'd put the few lines of code examples that you have shown above inside a test batch file, then you will have seen if they work or they don't work.

Offline

#10 25 Mar 2016 08:03

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: Issue with Closing Parentheses [Notepad++ bug]

Well, I think there are two points in the conclusion of this matter. The second point is your confusion caused by the Notepad++ highlight that, as you said, isn't the craziest assumption to make.

However, the first point is more important: in the whole question you did not said what the real problem was! You didn't described a syntax error nor a bad result, you just mentioned "a strange problem" and later that you "was getting anomalous results from parts of the code". This means that you have not idea of the cause of the original problem! In this situation, you also forgot to mention a point that later becomes very important: the fact that you thought that the posted code segments caused the problems because the Notepad++ highlight showed anomalies in such segments.

The purpose of the following suggestions is to aid you to post better questions in the future, so you will quickly get right answers that ultimately is the purpose of sites like this one.

When you post a question, you should show the code segment that caused the problem, describe what is the result obtained from such code and what is the intended result. If you don't know what is the problem or what is the code segment involved in the problem, don't post a question! How we could help you if we don't even know what is the problem?

When you describe a problem, be as concise and clear as possible. I invite you to do a small experiment: suppose you know nothing about this matter and read your question again. Although the question is ample and include several examples, the description of the problem is confusing; this is because the question was written based on information that does not appear in the text of the question! When points like this one are very evident, the OP's usually receive comments like "we are not mind readers" or "we have not a crystal ball".

Finally, I invite you to read this post...

Offline

#11 25 Mar 2016 11:30

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: Issue with Closing Parentheses [Notepad++ bug]

[Thread title edited to indicate that this is an editor bug]

The Notepad++ thing is actually a bug in the Scintilla code editing component, so it very likely affects a lot of other text editors too.

This has been an open bug since July 2014

Offline

Board footer

Powered by