Made a test encoder/decored for a simple namespace declaration with Fantomas OAK Ast, see fantomas tools page
given
Oak (1,0-1,15)
ModuleOrNamespaceNode (1,0-1,15)
ModuleOrNamespaceHeaderNode (1,0-1,15)
MultipleTextsNode (1,0-1,9)
namespace (1,0-1,9)
IdentListNode (1,10-1,15)
A (1,10-1,11)
B (1,12-1,13)
C (1,14-1,15)
it will output A.B.C
(lowered)
you can run it as dotnet fsi script.fsx
or in vscode with dotnet
sdk installed. cheers!
let oakAst =
"hello.one.two"
|> FantomasWriter.makeNamespace []
oakAst
|> FantomasReader.extractNsFromOak
|> Option.iter (printfn "NAMESPACE: %s")
Fabulous.AST
if you want to make your life easier and drop the custom write part for Oak, you can make use of the awesome Fabulous.AST DSL nuget package
#r "nuget:Fabulous.AST"
open System
open Fabulous.AST
open type Fabulous.AST.Ast
// using Fabulous.AST life becomes easier for writing oak
let oakAst =
Ast.Oak(){
Ast.Namespace("hello.one.two") {}
}
|> Gen.mkOak
Top comments (0)