PowerBuilder Code Beautifier / Formatter

 A new code beautifier for PowerBuilder (PowerScript) code has been added to NotepadPB:


This is the first and initial version which uses a very simple approach to formatting the code. NotepadPB will use multiple passes to adjust spacing, casing, and indenting of the script. The process works as follows:

  1. Start by tokenizing the script by splitting everything into words or characters (characters for things like quotes). We then loop through each token and determine if it's a keyword, datatype, quote, comment, carriage return, or user defined text (like variable names). We change the case on keywords and datatypes, and track indent level if the keyword is an indent-able keyword (e.g. IF, FOR, CHOOSE, etc). Comments and quoted text are ignored, we don't want to modify them. At the end, we reassemble our script.

  2. In our second pass, we parse our script by line. We will apply some formatting on a line by line bases. The second pass is meant to adjust alignments for lines that end in ampersand. We'll also take the opportunity to remove blank lines.

    e.g.   IF val = TRUE OR &
                 val2 = FALSE THEN  <----add spacing to align this line with the top line

  3. The third will also deal with the script on a per line basis. This time we'll apply some line spacing around code blocks:

    IF val = TRUE THEN
        IF val2 = FALSE THEN
        END IF

    END IF

  4. The forth and final pass will again remove any unneeded line spacing.

This initial version should hopefully cover most coding scenarios. There's work that needs to be done to format inline SQL. This will be an interesting task seeing that this will require an SQL formatter to be created.

If you're interested, give NotepadPB a try to see how it works for you. If you see issues with how your code is formatted, send a sample of the code to support@werysoft.com.

Note that NotepadPB also has other PowerBuilder focused features:
  1. Syntax highlighting
  2. Syntax folding
  3. Go to definition when viewing a PowerBuilder source file (.sr*)


Post a Comment

Popular posts from this blog

Develop a web browser in PowerBuilder.

Update the look of all your PowerBuilder message boxes in a few easy steps