SkillAgentSearch skills...

Fabulous.AST

Abstract Syntax Tree (AST) Domain Specific Language (DSL) for F#

Install / Use

/learn @edgarfgp/Fabulous.AST
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Fabulous.AST

build NuGet version NuGet downloads

Welcome to Fabulous.AST, an Abstract Syntax Tree (AST) Domain Specific Language (DSL) for F#.

Fabulous.AST leverages Fantomas to generate F# code from AST. This allows you to create F# code that adheres to the Fantomas style guide while providing a simple and expressive way to represent code as a tree of nodes. This approach simplifies programmatic code manipulation and analysis.

Features

  • Simplified AST creation for F# code
  • Integration with Fantomas for consistent code formatting
  • Expressive DSL for representing code structures
  • Easy-to-use API for code generation and manipulation

Installation

Install Fabulous.AST via NuGet:

dotnet add package Fabulous.AST

Usage

Let's compare AST creation using Fantomas directly and Fabulous.AST:

Fantomas AST Example

open Fantomas.Core
open Fantomas.Core.SyntaxOak
open Fantomas.FCS.Text

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
)
|> CodeFormatter.FormatOakAsync
|> Async.RunSynchronously
|> printfn "%s"

Fabulous.AST Example

open Fantomas.Core
open Fabulous.AST
open type Fabulous.AST.Ast

Oak() { 
    AnonymousModule() { 
        Value("x", "12") 
    }
}
|> Gen.mkOak
|> Gen.run

Both examples produce the following F# code:

let x = 12

As you can see, Fabulous.AST significantly simplifies the process of creating ASTs for F# code.

Documentation

For comprehensive information about Fabulous.AST, visit our documentation site.

Additional resources:

Supporting Fabulous.AST

Show your support for Fabulous.AST:

  1. Star this repository and the Fabulous.AST project on GitHub.
  2. Become a sponsor through the GitHub Sponsors program.

Contributing

We welcome contributions to Fabulous.AST!

  • Found a bug or have a suggestion? Open an issue, and we'll look into it promptly.
  • Want to contribute code? PRs are always welcome! Please create them from the main branch and follow our Contributor Guide.

License

Fabulous.AST is released under the MIT License.

View on GitHub
GitHub Stars65
CategoryProduct
Updated1mo ago
Forks9

Languages

F#

Security Score

100/100

Audited on Feb 16, 2026

No findings