Fantomas is definitely the right thing to see here. If you want to generate F # source code, you basically need two things:
Create an AST that represents the source code you want to create. To do this, you need to use untyped AST from the F # compiler service. an untyped syntax tree on the docs page, how you can handle it, but this should be a good starting point to learn this. AST expressions are determined by the type of SynExpr .
Once you create an AST, you need to format it. The F # compiler does not contain a nice printer, but this is exactly what Fantomas does in the CodePrinter file, so you should be able to copy it and transfer your AST to formatting implemented there. I think Visual F # PowerTools may have a newer version of Fantomas, so check this out first.
This answer uses untyped AST, which is probably suitable for working with language syntax. AST (created after type inference completion) is also printed, but it is difficult to use and is not suitable for this.
source share