Macro Bracket Checker

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

Post Reply
User avatar
davout
Cave Troll
Posts: 78
Joined: Wed Oct 12, 2011 2:28 am

Macro Bracket Checker

Post by davout »

I don't know about you but I've spent too much time debugging macros only to find out I've missed a square bracket, curly bracket, or paren (From now on I will refer to all 3 as brackets) . So I've come up with simple tool. Actually it's code I modified that I found on the Internet.

Basically it checks for matching brackets and parens. It's not very sophisticated. It does not take into account the context of the code. So if you have one half of a bracket in a comment it will alert of missing bracket. It will report more than 1 issue at each run, however, the way it works it that for each issue it displays from the beginning of the file to the location of the problem. So I recommend directing output to a file.

Note: It requires at least Java 1.5

Simple method to use:
1. copy BracketChecker.class and Stack.class to the directory where the files you want to check.
1a. Alternatively you could place the two files in a directory and then add that directory to your java class path.
2. java -cp . BracketChecker fileToCheck.macro > check.txt
2a. If you alternatively performed 1a, you just need to execute: java BracketChecker fileToCheck.macro > check.txt
3. Examine check.txt if the file is empty no problems were found. Probably should display a message to that effect. Maybe later.

Remove the .txt extensions from each file. I added those in order to be able to upload the files.

The BrackerChecker.java file is the source code in case anyone wants to improve it.

Thanks.
Attachments
BracketChecker.java.txt
(3.72 KiB) Downloaded 345 times
Stack.class.txt
(619 Bytes) Downloaded 171 times
BracketChecker.class.txt
(2.81 KiB) Downloaded 186 times

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Macro Bracket Checker

Post by wolph42 »

Aliasmask created a erm MT language def. file for np++. Which highlights brackets open and close (and the others as well) So if you're on so if you're on windows I would suggest using that. Link to it can be found in his sig.

For non windows users this is however great to use!!

User avatar
davout
Cave Troll
Posts: 78
Joined: Wed Oct 12, 2011 2:28 am

Re: Macro Bracket Checker

Post by davout »

Yes I have and use that. But at least for me it's still easy to miss one.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Macro Bracket Checker

Post by aliasmask »

Yeah, I'm always leaving off ending ] or )'s, but I just rely on whatever I'm doing to crash so I can catch it. I probably would be easy enough to add a bracket checker to rpedit when uploading code. Well, for normal code at least. I'm always doing funky things that wouldn't make it useful for me.. ie I put []'s inside of quotes as a code segment I can run later. But I could just do a count as well to make sure the number of [ equal the number ] rather than checking to see if ['s get nested incorrectly.

Post Reply

Return to “Drop-In Macro Resources”