mirror of
https://github.com/Smaug123/WoofWare.Whippet
synced 2025-10-10 02:08:41 +00:00
Some checks failed
.NET / build (Debug) (push) Has been cancelled
.NET / build (Release) (push) Has been cancelled
.NET / analyzers (push) Has been cancelled
.NET / build-nix (push) Has been cancelled
.NET / check-dotnet-format (push) Has been cancelled
.NET / check-nix-format (push) Has been cancelled
.NET / Check links (push) Has been cancelled
.NET / Check flake (push) Has been cancelled
.NET / nuget-pack (push) Has been cancelled
.NET / expected-pack (push) Has been cancelled
.NET / all-required-checks-complete (push) Has been cancelled
48 lines
1.6 KiB
Forth
48 lines
1.6 KiB
Forth
namespace WoofWare.Whippet.Fantomas
|
|
|
|
open Fantomas.Core
|
|
open Fantomas.FCS.Syntax
|
|
open Fantomas.FCS.SyntaxTrivia
|
|
|
|
/// Helper methods to convert between source code and FCS ASTs.
|
|
[<RequireQualifiedAccess>]
|
|
module Ast =
|
|
/// Given the contents of an F# source file, parse it into an AST. This is sync-over-async internally, which is
|
|
/// naughty.
|
|
let parse (fileContents : string) : ParsedInput =
|
|
CodeFormatter.ParseAsync (false, fileContents)
|
|
|> Async.RunSynchronously
|
|
|> Array.head
|
|
|> fst
|
|
|
|
/// Concatenate the input modules/namespaces and render them as a single F# source file.
|
|
///
|
|
/// This can return `None`, if the input was empty.
|
|
/// This is sync-over-async internally, which is naughty.
|
|
let render (contents : SynModuleOrNamespace list) : string option =
|
|
if contents.IsEmpty then
|
|
None
|
|
else
|
|
|
|
let parseTree =
|
|
ParsedInput.ImplFile (
|
|
ParsedImplFileInput.ParsedImplFileInput (
|
|
"file.fs",
|
|
false,
|
|
QualifiedNameOfFile.QualifiedNameOfFile (Ident.create "file"),
|
|
[],
|
|
[],
|
|
contents,
|
|
(false, false),
|
|
{
|
|
ParsedImplFileInputTrivia.CodeComments = []
|
|
ConditionalDirectives = []
|
|
},
|
|
Set.empty
|
|
)
|
|
)
|
|
|
|
let cfg = FormatConfig.Default
|
|
|
|
CodeFormatter.FormatASTAsync (parseTree, cfg) |> Async.RunSynchronously |> Some
|