module lang::pico::format::Formatting
rascal-Not specified
Demonstrates the use of ((util::Formatting)) for constructing a declarative and HiFi Pico formatting pipeline
Usage
import lang::pico::format::Formatting;
Dependencies
extend lang::box::util::Tree2Box;
import IO;
import ParseTree;
import lang::pico::\syntax::Main;
import util::Formatters;
import analysis::diff::edits::TextEdits;
Benefits
- The formatting is style is programmed declaratively by mapping language patterns to Box expressions.
- The pipeline never loses source code comments, and this requires no attention from the language engineer.
Pitfalls
- Box2 Text must be extended for the open recursive calls of To Box to reach the extensions in the current module. If you import Box2 Text the extended To Box rules will only be found if they describe top-level tree nodes.
function toBox
Format while
Box toBox((Statement) `while <Expression e> do <{Statement ";"}* block> od`)
function toBox
Format if-then-else
Box toBox((Statement) `if <Expression e> then <{Statement ";"}* thenPart> else <{Statement ";"}* elsePart> fi`)
function toBox
Format if-then
Box toBox((Statement) `if <Expression e> then <{Statement ";"}* thenPart> fi`)
Box toBox((Declarations) `declare <{IdType ","}* decls>;`)
Box toBox((Program) `begin <Declarations decls> <{Statement ";"}* body> end`)