Skip to content

fpp format

Rob Bocchino edited this page Jun 28, 2023 · 4 revisions

This tool parses FPP source files into an abstract syntax tree (AST) and writes out the AST as formatted source code.

The main purpose of this tool is to test the FPP code generation capability. It is not a true formatter, in that (1) it requires syntactically valid FPP source as input and (2) it erases comments. However, it may be useful for some formatting tasks.

To preserve comments on their own lines that precede annotatable elements, you can run this script:

#!/bin/sh
sed 's/^\( *\)#/\1@ #/' | fpp-format $@ | sed 's/^\( *\)@ #/\1#/'

It converts comments to annotations, runs fpp-format, and converts the annotations back to comments.

Options:

  1. -i: Resolve include specifiers.

Input: A list fl of files: either the single file stdin or a list of files specified on the command line.

Output: Formatted FPP source code, minus comments, written to standard output.

Procedure:

  1. Parse each of the files in fl to a translation unit tu, reporting any errors that occur.

  2. If -i is present, then recursively resolve include specifiers. Check for include cycles. Upon detecting an include cycle, halt with an error message.

  3. Write out the formatted source code.