Mismatched brackets error message

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Mismatched brackets error message

Post by BarryG »

Check out this snippet:

Code: Select all

Dim a$(1)
Dim b(1)
b$=Left(a$(1),Len(a$(1))-b(1)))
b$=Left(a$(1),Len(a$(1))-b(1)
At first glance, they look fine. But the first b$ line gives an error of Garbage at the end of the line, and the second gives a Syntax error.

However, both these error messages are not very helpful to immediately and intuitively indicate what the problem is.

I'd rather see an error message like this: Opening and closing brackets are mismatched.
Last edited by BarryG on Thu Mar 02, 2023 6:22 am, edited 2 times in total.
User avatar
mrv2k
User
User
Posts: 51
Joined: Fri Jan 20, 2012 3:40 pm
Location: SE England
Contact:

Re: Mismatched brackets error message

Post by mrv2k »

If you go to Preferences - Coloring and scroll down a bit, there is an option for "Mark mismatched Braces and Keywords". Make sure that is ticked and a colour is set. If you tick the option above "Mark matching Braces and Keywords" it's easier to see when you are writing the command.
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Mismatched brackets error message

Post by BarryG »

Yep, I know about that, and I do have it set. However, when pasting a copied line (or block of code) like that, are you really going to sit there and cursor through all lines to make sure all the brackets match? Nope. You just want to compile and go; not check and count all the brackets manually. So, this is more about changing the error message, which doesn't indicate the true problem.

I'd even say that checking for mismatched brackets would increase compile time, because if the brackets don't match then the entire line (and any other commands on it) can immediately be ignored (since the line won't compile until the brackets are resolved).
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Mismatched brackets error message

Post by Marc56us »

BarryG wrote:I'd rather see an error message like this: Opening and closing brackets are mismatched.
Yes, but this would require specific processing (so slow down), because currently this message is generic for a lot of characters.
Give it a try:
( ) { } [ ]
but also, this is the same message for:
# " ' @ ` ^
So 'Garbage at the End of the line' says that the error starts there and that it's useless to go any further.
Same thing for 'Syntax error' this is basic error.

Matching brackets when displaying is a feature of Scintilla in the IDE. For the compiler to do it itself, I think it would require a lot of extra processing.

IMHO :wink:
Post Reply