Is there a way in notepad++ to search for missing braces/brackets/parenthesis?
I use asterisk VOIP which has large config files. If there are errors, all I get is "MISSING }" -- no line number or even file name...that would be too easy.
So, I need a way to open a file and go right to the missing tag. The best way would be some type of search. Second best would be a function which would highlight all the missing tags in a file. I tried changing language to perl, but I tested by typing a line with a missing parenthesis and it didn't go red. These files are just configuration files and not tied to a specific language.
If Notepad doesn't do this, does anyone know of a tool? A google search did not reveal one that would check an entire file.
Thanks,
Cliff
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Someone could extend this by writing a 'bracket interpreter' which goes through a given file (selection) and checks to make sure that all of the brackets match up (and giving an error if you have a situation like this: "[...{..]...}" where the numbers match up, but there's a single bracket between each pair).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1. Does a closing bracket have to be on the same line as the opening bracket?
If so, you could find them by searching for or applying the following regular expression:
^[^{]*{[^}]*$
Notice that this doesn't account for multiple pairs (or mismatches) on the same line.
The regex searches for a { from the start of the line, not followed by any } on the same line. There may be more than one { on a matching line.
You can use this regex in either Find Dialog (CTRL+F or the advanced alternative CTRL+R) or with the TextFX Viz Show and Hide features.
See the thread references in this message for more information:
2. If the opening and closing brackets may appear on different lines, you can filter these lines (TextFX Viz Show) by using a simple regular expression to find either of them:
[{}]
You could probably scan all lines now for (missing) matches, preferrably after copying all lines to a separate document.
It may help you to insert the original lines numbers first, before doing any filtering.
You could also use either of the tools mentioned in the thread references above to extract either all matching lines or, less usable, only all matching brackets, but this wouldn't allow you to insert the original line numbers first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was in a rush, so I wrote a quick perl program before I saw your response.
It's crude, but I was in a hurry, and it does exactly what I need. It counts the number of left brackets, braces, parenthesis, less than, and the number of right brackets, etc, and alerts if they are not equal. I was able to find the one screwed up line out of thousands. The perfect place for this in Notepad++ would be in the SEARCH dialog.
Hello,
Is there a way in notepad++ to search for missing braces/brackets/parenthesis?
I use asterisk VOIP which has large config files. If there are errors, all I get is "MISSING }" -- no line number or even file name...that would be too easy.
So, I need a way to open a file and go right to the missing tag. The best way would be some type of search. Second best would be a function which would highlight all the missing tags in a file. I tried changing language to perl, but I tested by typing a line with a missing parenthesis and it didn't go red. These files are just configuration files and not tied to a specific language.
If Notepad doesn't do this, does anyone know of a tool? A google search did not reveal one that would check an entire file.
Thanks,
Cliff
This is a good idea.
Someone could extend this by writing a 'bracket interpreter' which goes through a given file (selection) and checks to make sure that all of the brackets match up (and giving an error if you have a situation like this: "[...{..]...}" where the numbers match up, but there's a single bracket between each pair).
1. Does a closing bracket have to be on the same line as the opening bracket?
If so, you could find them by searching for or applying the following regular expression:
^[^{]*{[^}]*$
Notice that this doesn't account for multiple pairs (or mismatches) on the same line.
The regex searches for a { from the start of the line, not followed by any } on the same line. There may be more than one { on a matching line.
You can use this regex in either Find Dialog (CTRL+F or the advanced alternative CTRL+R) or with the TextFX Viz Show and Hide features.
See the thread references in this message for more information:
"RE: Need help using regex" - 2008-04-23 21:22
http://sourceforge.net/forum/message.php?msg_id=4923889
2. If the opening and closing brackets may appear on different lines, you can filter these lines (TextFX Viz Show) by using a simple regular expression to find either of them:
[{}]
You could probably scan all lines now for (missing) matches, preferrably after copying all lines to a separate document.
It may help you to insert the original lines numbers first, before doing any filtering.
Select the complete text by pressing CTRL+A.
Menu_____ : TextFX
Submenu__ : TextFX Tools
Option___ : Insert Line Numbers
You could also use either of the tools mentioned in the thread references above to extract either all matching lines or, less usable, only all matching brackets, but this wouldn't allow you to insert the original line numbers first.
Thanks for the info :)
I was in a rush, so I wrote a quick perl program before I saw your response.
It's crude, but I was in a hurry, and it does exactly what I need. It counts the number of left brackets, braces, parenthesis, less than, and the number of right brackets, etc, and alerts if they are not equal. I was able to find the one screwed up line out of thousands. The perfect place for this in Notepad++ would be in the SEARCH dialog.
#!/usr/bin/perl -w
#this program scans for missing tags
$fileName=$ARGV[0];
open(i1file, "<$fileName");
open(o1file, ">taglog");
print o1file ("********** BEGIN SCAN ********** \n");
$counter = 1;
while(<i1file>)
{
$leftCount = 0;
$rightCount = 0;
my($instring) = $_;
chomp($instring);
$leftCount = ($instring =~ tr/\(//);
$rightCount = ($instring =~ tr/\)//);
if ($leftCount != $rightCount) {
print o1file ("Line $counter : $_ \n");
}
$leftCount = ($instring =~ tr/\{//);
$rightCount = ($instring =~ tr/\}//);
if ($leftCount != $rightCount) {
print o1file ("Line $counter : $_ \n");
}
$leftCount = ($instring =~ tr/\[//);
$rightCount = ($instring =~ tr/\]//);
if ($leftCount != $rightCount) {
print o1file ("Line $counter : $_ \n");
}
$leftCount = ($instring =~ tr/\<//);
$rightCount = ($instring =~ tr/\>//);
if ($leftCount != $rightCount) {
print o1file ("Line $counter : $_ \n");
}
$counter++
}
print o1file ("*********** END SCAN *********** \n");
close i1file;
close o1file;
exit(0);