A Formatter Using Quadroids Binaries that also supports DelphiScript and Code Snippets
Formatting Altium Delphi Script Code is not trivial. The problem is that tools like JEDI Code Format and the newer CLI version JCF pascal Format refuse to format DelphiScript Code because it is "not complete".
Here is a little Python program that:
- Completes your DelphiScript code by inserting "unit Test;" + "interface" + "implementation" at the beginning and "end." at the end
- Optionally pre- and postprocesses the following elements that make proplems with JCF:
- Commas as variable delimiters in function declarations (instead of semicolons)
- The 'like' - operator
- Formats the Result with Quadroids CLI Formatter
- Removes the formerly added elements from the result and writes the formatted code back
- A backup of your code can be generated (.bak)
Usage:
- Get the latest release from HERE
- Extract everything to a folder and run "FormatDS.exe"
- Open your DelphiScript file with "Open"
- Optionally load a different Config File (than the pascal-format.cfg in the folder)
- Click on "Process" to Format your file
- Function declaration comma Handling:
- If this box is checked, it will replace all commas in function and procedure declarations with semicolons so that JCF can handle it
- If "Change declaration delimiters to semicolons" is set then the declaration delimiters will stay semicolons, else they will be changed back to commas after formatting
- Preprocess 'like' operator: Check this box to preprocess the 'like' operators so that JCF can format the code
- Make backup (.bak) file: If this is enabled, the file will be copied to a backup file with extra .bak as extension
- Keep work (.wrk) file: If this is enabled, the .wrk file that is passed to and processed by JCF is kept (for debugging porposes)
- Generate Breakpoints: Generate Breakpoints in Altium, see below
Config File:
Optionally, you can load your own Config File. Config files made with the GUI of the old JEDI Code Format are automatically detected and converted.
Processing of 'like' operators:
Optionally, the unsupported 'like' operators are preprocessed so that JCF can handle the file. A non-comment line (or the non comment part of a line) will be analysed by a preprocessor. Example:
if (a=b) and (a like c) and not (c = e) and (e like f) and (u = i) and (u = i) and (a like c) then // test something like nothing
Found 'like' operators will each be replaced by a '=' and a comment line will be added above containing restoring info:
// LIKEPROCESSING_INFO: 1,3,6
if (a=b) and (a = c) and not (c = e) and (e = f) and (u = i) and (u = i) and (a = c) then // test something like nothing
After formatting with JCF, the tool searches for these comment lines and restores the 'like' operators to their original positions. Finally, the processing comments are removed from the formatted code.
Generate Breakpoints (for Altium):
If this checkbox is set, the Program searches for a Altium Scripting Project File (.PrjScr) in the folder where the code file is located. When a single Script Project File is found, and a formatting error is occured, the programm processes the information and generates a breakpoint on the line where the formatting error has occured. Since JCF is pretty strict, this can be used to check for programming errors before running.