Pretty Printer

Revision as of 09:22, 16 June 2011 by Alexander Kogtenkov (Talk | contribs) (Added a new page about Pretty Printer)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Background

The tool can be used to reformat the source code in a standard way that follows the recommended style. It can be invoked either from the command line by the corresponding command or in IDE via the menu entry. The tool does not address all coding rules, but only those related to text layout: indentation, spacing, new lines, etc.

Options

Not all processing expectations are covered by the rules. Some of them may affect resulting code and are therefore controlled by optional settings.

Options
Option Affected constructs Example Recommended setting
Shall trailing white space be stripped? Comments
-- "[
-- Trailing spaces
-- ]"
True

Limitations

Some language constructs are difficult to format automatically without breaking original idea of the formatting. These include:

  • inline comments: when used inside larger construct they break normal text flow and it may be difficult to guess how the construct should be continued on a new line

Testing

The eweasel tests that address potential or found and fixed issues are tagged with the keyword pretty and use prettyNNN for test directory names.

Apart from the visual style the formatting should preserve the original code. This allows for completely automated validation of the tool. If there is a generator of source code streams from the given grammar, the generated text can be feed to the tool. Then the input and output can be compared side by side after serializing them into a sequence of tokens. If the sequences match, the conversion went without an error. Otherwise it renders a bug in the tool.