Pascal Source code formatter
This is a simple Pascal source formatter, only meant to give correct and readable indentation to Pascal code.
The tool is started up from within the mP IDE, one of the IDE "tools" is programmed to start up the formatter and pass
the currently selected file to it (which has to be "saved" beforehand).
The tool also provides the possibility to open other Pascal files via the "File" menu.
The software: PascalFormat.zip
Usage
On startup, the pascal source is loaded automatically and the tool shows this window:

The left side pane shows the original (unprocessed) source code, and hitting the "Process" button produces the
formatted (processed) code in the right hand pane.
This processed source code can be saved (overwriting the original code) by pressing "Save".
Additionally one can, before hitting "Process" trim (delete spaces) the code in the left pane. This is done with a popup menu
(right mouse click inside the left pane). Two options are offered: trimming all lines, and trimming only the lines that
do not start with a comment.
If wanted, one can reload a saved file in the left page by hitting "Reload"
Remarks:
- before hitting "Process" one can make changes in the original source code in the left pane, they will be taken into account.
- before hitting "Save" one can make changes in the "processed" source file in the right pane, they will be taken into account.
How to make it work from within the IDE
To make the tool work from within the mP IDE the following has to be done:
1. The tool must be added in the "Tools" (Tools menu --> Options --> Tools --> Toolx) menu:

As you can see, the path to the tool must be given and one parameter: "%UNIT_FILE_NAME".
2. Additionally mP has to be told to accept changes in source files made by an external tool,
this is done in the IDE menu "Tools -> Options -> Editor -> Editor settings":

Details
The tool expects the following to be true in the original source code (précondition):
- the keywords 'uses', 'var', 'const', 'type', 'label', 'implementation', 'procedure', 'function' should be at the beginning of a line (only spaces before it are allowed)
- keywords must always be surrounded by spaces, or start at the beginning of a line or end at the end of a line. The exception
to this rule is 'end' which can be followed by ';' or '.'
The indentation in the processed file is done according the detection of the following keywords:
- 'uses', 'var', 'const', 'type' and 'label': the indentation of the keyword itself is zero, the indentation following it is 2
- 'implementation', 'procedure' and 'function': the indentation of the keyword itself and the following lines is zero
- 'begin', 'record', 'case' and 'repeat': the indentation of the following lines is incremented by 2
- 'end' and 'until': the indentation of itself and its following lines is decremented by 2.
Additionally,
- the keywords 'begin', 'asm', 'case', 'repeat', 'end' and 'until' are always placed at a new line, the line is splitted up for that if necessary
- text after the keywords 'begin', 'asm', 'record', 'repeat' and 'end' on the same line is moved to the next line (the line is splitted up for that if necessary),
unless the text is pure comments
- if a ';' is preceded by one or more spaces then the spaces are deleted
- if nothing is behind the ':' in a case value of a case statement then '//' is added to prevent a compiler error
- the tool recognises as comments //, (* and { (and of course their counterparts: *) and } )
-------------------------------------------