Fabulous.AST
0.3.0
See the version list below for details.
dotnet add package Fabulous.AST --version 0.3.0
NuGet\Install-Package Fabulous.AST -Version 0.3.0
<PackageReference Include="Fabulous.AST" Version="0.3.0" />
<PackageVersion Include="Fabulous.AST" Version="0.3.0" />
<PackageReference Include="Fabulous.AST" />
paket add Fabulous.AST --version 0.3.0
#r "nuget: Fabulous.AST, 0.3.0"
#:package Fabulous.AST@0.3.0
#addin nuget:?package=Fabulous.AST&version=0.3.0
#tool nuget:?package=Fabulous.AST&version=0.3.0
Fabulous.AST
Welcome to the Fabulous.AST, an Abstract Syntax Tree (AST) Domain Specific Language (DSL) for F#.
Fabulous.AST uses Fantomas to generate F# code from AST. This means that you can use Fabulous.AST to generate F# code that is formatted according to the Fantomas style guide. It's designed to provide a simple and expressive way to represent code as a tree of nodes. This makes it easier to manipulate and analyze code programmatically.
Let's take a look at an AST example in Fantomas:
open FSharp.Compiler.Text
open Fantomas.Core.SyntaxOak
let implementationSyntaxTree =
Oak(
[],
[ ModuleOrNamespaceNode(
None,
[ BindingNode(
None,
None,
MultipleTextsNode([ SingleTextNode("let", Range.Zero) ], Range.Zero),
false,
None,
None,
Choice1Of2(IdentListNode([ IdentifierOrDot.Ident(SingleTextNode("x", Range.Zero)) ], Range.Zero)),
None,
[],
None,
SingleTextNode("=", Range.Zero),
Expr.Constant(Constant.FromText(SingleTextNode("12", Range.Zero))),
Range.Zero
)
|> ModuleDecl.TopLevelBinding ],
Range.Zero
) ],
Range.Zero
)
open Fantomas.Core
CodeFormatter.FormatOakAsync(implementationSyntaxTree)
|> Async.RunSynchronously
|> printfn "%s"
produces the following code:
let x = 12
Now let's take a look at same example using Fabulous.AST:
open type Fabulous.AST.Ast
let source =
AnonymousModule() {
Value("x", "12")
}
open Fantomas.Core
let oak = Tree.compile source
let res = CodeFormatter.FormatOakAsync(oak) |> Async.RunSynchronously
printfn $"%s{res}"
produces the following code:
let x = 12
You can use an Escape Hatch to generate code that is not supported by Fabulous.AST yet. For example, the following code:
open type Fabulous.AST.Ast
let source =
AnonymousModule() {
Value("a", "11")
BindingNode(
None,
None,
MultipleTextsNode([ SingleTextNode("let", Range.Zero) ], Range.Zero),
false,
None,
None,
Choice1Of2(IdentListNode([ IdentifierOrDot.Ident(SingleTextNode("x", Range.Zero)) ], Range.Zero)),
None,
List.Empty,
None,
SingleTextNode("=", Range.Zero),
Expr.Constant(Constant.FromText(SingleTextNode("12", Range.Zero))),
Range.Zero
)
}
open Fantomas.Core
let oak = Tree.compile source
let oak = Tree.compile source
let res = CodeFormatter.FormatOakAsync(oak) |> Async.RunSynchronously
printfn $"%s{res}"
produces the following code:
let a = 11
let x = 12
Using Fabulous.AST, you can easily create and manipulate ASTs like this one using F# functions. For example, you can add new nodes to the AST, modify existing nodes, or traverse the AST to perform analysis or transformation tasks.
Fabulous.AST is a powerful tool for anyone who works with code and wants to automate or streamline their development workflow. Whether you're a compiler writer, a code generator, or just someone who wants to write better code faster, Fabulous.AST can help you achieve your goals.
Available widgets
Namespaces and modules
| Widget | Description | F# code |
|---|---|---|
| AnonymousModule | An anonymous module | () |
| Namespace | A namespace | namespace ABC |
| Module | A module | module ABC |
| NestedModule | A module | module ABC = |
Open directives
| Widget | Description | F# code |
|---|---|---|
| Open | An open directive | open ABC |
| OpenType | An open directive | open type ABC.XYZ |
Let bindings
| Widget | Description | F# code |
|---|---|---|
| Value | A let binding | let x = 12 |
| Literal | A literal definition | [<Literal>] let x = 12 |
| Function | A function definition | let f x = x + 1 |
Type definitions
| Widget | Description | F# code |
|---|---|---|
| Alias | A type definition | type MyInt = int |
| Record | A record type | type R = { x: int; y: int } |
| Union | A union type | type U = A \| B of int |
| Class | A class type | type MyClass() = class end |
| Struct | A struct type | type MyStruct() = struct end |
| Interface | An interface type | type I = interface end |
Control flow definitions
| Widget | Description | F# code |
|---|---|---|
| If | An if expression | if x = 12 then 1 |
| IfElse | An if expression | if x = 12 then 1 else 2 |
| Match | A match expression | match x with |
| For | A for loop | for i in 1..10 do |
| While | A while loop | while x < 10 do |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Fantomas.Core (= 6.0.0-beta-001)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Fabulous.AST:
| Package | Downloads |
|---|---|
|
MigrateLib
Declarative migrations for SQLite |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.6.0 | 364 | 6/7/2025 |
| 1.5.0 | 158 | 5/10/2025 |
| 1.4.0 | 253 | 4/4/2025 |
| 1.3.0 | 227 | 3/16/2025 |
| 1.2.0 | 403 | 3/5/2025 |
| 1.1.0 | 188 | 1/12/2025 |
| 1.0.0 | 196 | 12/15/2024 |
| 1.0.0-pre9 | 249 | 5/13/2024 |
| 1.0.0-pre8 | 168 | 5/12/2024 |
| 1.0.0-pre7 | 189 | 5/10/2024 |
| 1.0.0-pre6 | 183 | 5/10/2024 |
| 1.0.0-pre5 | 217 | 4/14/2024 |
| 1.0.0-pre4 | 168 | 4/7/2024 |
| 1.0.0-pre3 | 187 | 4/1/2024 |
| 1.0.0-pre2 | 189 | 3/27/2024 |
| 1.0.0-pre17 | 147 | 10/6/2024 |
| 1.0.0-pre16 | 188 | 7/14/2024 |
| 1.0.0-pre15 | 187 | 7/1/2024 |
| 1.0.0-pre14 | 155 | 6/13/2024 |
| 1.0.0-pre13 | 167 | 6/2/2024 |
| 1.0.0-pre12 | 385 | 5/20/2024 |
| 1.0.0-pre11 | 182 | 5/16/2024 |
| 1.0.0-pre10 | 175 | 5/13/2024 |
| 1.0.0-pre1 | 182 | 3/25/2024 |
| 0.9.0 | 247 | 3/12/2024 |
| 0.8.2 | 215 | 3/11/2024 |
| 0.8.1 | 202 | 3/10/2024 |
| 0.8.0 | 218 | 3/8/2024 |
| 0.7.0 | 603 | 2/11/2024 |
| 0.6.2 | 345 | 6/8/2023 |
| 0.6.1 | 309 | 6/4/2023 |
| 0.6.0 | 288 | 5/29/2023 |
| 0.5.0 | 329 | 4/21/2023 |
| 0.4.0 | 348 | 4/13/2023 |
| 0.3.0 | 334 | 4/11/2023 |
| 0.2.0 | 315 | 4/6/2023 |
| 0.1.0 | 346 | 4/3/2023 |
### Added
- Add initial support for members in Record and Unions
### Changed
- Update 6.0.0-beta-001