02-19-2015, 04:00 PM
So, I've finished making the autoprogram templater. I'll comment it better and clean up the code later, but it works as intended right now so I'm uploading it.
TODO: add more error messages and warnings and stuff for template syntax errors
TODO: general cleanup. (more comments, less stupid code, remove references to nonexistent methods.)
TODO: support parsing hex files to support writing to hex rom.
TODO: add support for basic escape characters like \n
TODO: allow (0){ ... } declarations.
TODO: have a check for endless recursive template calling. e.g. check for stoopid definitions.
usage: binScripter.py (sourcefile) (templatefile) (outputfile)
basic syntax etc:
Here's the code:
(v1.5) https://github.com/MagicalGentleman/binScripter
(This is a python 3 program)
TODO: add more error messages and warnings and stuff for template syntax errors
TODO: general cleanup. (more comments, less stupid code, remove references to nonexistent methods.)
TODO: support parsing hex files to support writing to hex rom.
TODO: add support for basic escape characters like \n
TODO: allow (0){ ... } declarations.
TODO: have a check for endless recursive template calling. e.g. check for stoopid definitions.
usage: binScripter.py (sourcefile) (templatefile) (outputfile)
basic syntax etc:
The syntax is simple, but you can be quite creative
There are 3 main declaration types.
The var declaration defines what should go in the autoprogram file when it reaches a reference to variableName. If the next bit to write is 0, it will write "zero_block_id", and vice versa:
The template declaration acts similarly to a function definition. When templateName is called, its contents will be processed and then the parser will return back to where the template was called from:
This declaration is what is first executable. The number in brackets tells the program how many times this sequence should be repeated:
Other things to note:
you can't declare a new template or var inside the body of another declaration. That has to be done at the top level of the templater file.
The program will warn you if your source binary is bigger than your templated rom's capacity.
The program terminates when it runs out of binary to parse. This is why it can handle recursive functions without going into an infinite loop ;3
Declarations can be made later in the file, but they are not known to loops that are executed before the declaration.
There are 3 main declaration types.
The var declaration defines what should go in the autoprogram file when it reaches a reference to variableName. If the next bit to write is 0, it will write "zero_block_id", and vice versa:
Code:
(~variableName){"zero_block_id" : "one_block_id"}
The template declaration acts similarly to a function definition. When templateName is called, its contents will be processed and then the parser will return back to where the template was called from:
Code:
(templateName){"abcdefg"}
This declaration is what is first executable. The number in brackets tells the program how many times this sequence should be repeated:
Code:
(9){"This text would repeat 9 times"}
Other things to note:
you can't declare a new template or var inside the body of another declaration. That has to be done at the top level of the templater file.
The program will warn you if your source binary is bigger than your templated rom's capacity.
The program terminates when it runs out of binary to parse. This is why it can handle recursive functions without going into an infinite loop ;3
Declarations can be made later in the file, but they are not known to loops that are executed before the declaration.
Here's the code:
(v1.5) https://github.com/MagicalGentleman/binScripter
(This is a python 3 program)