mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-05 12:08:46 +00:00
42 lines
1.2 KiB
Forth
42 lines
1.2 KiB
Forth
namespace WoofWare.Myriad.Plugins
|
|
|
|
open Fantomas.FCS.Syntax
|
|
|
|
type internal UnionCase<'Ident> =
|
|
{
|
|
Fields : SynFieldData<'Ident> list
|
|
Attrs : SynAttribute list
|
|
Ident : Ident
|
|
}
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module internal UnionCase =
|
|
let mapIdentFields<'a, 'b> (f : 'a -> 'b) (unionCase : UnionCase<'a>) : UnionCase<'b> =
|
|
{
|
|
Fields = unionCase.Fields |> List.map (SynField.mapIdent f)
|
|
Attrs = unionCase.Attrs
|
|
Ident = unionCase.Ident
|
|
}
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module internal SynUnionCase =
|
|
let extract (SynUnionCase (attrs, id, caseType, _, _, _, _)) : UnionCase<Ident option> =
|
|
match caseType with
|
|
| SynUnionCaseKind.FullType _ -> failwith "WoofWare.Myriad does not support FullType union cases."
|
|
| SynUnionCaseKind.Fields fields ->
|
|
|
|
let fields = fields |> List.map SynField.extract
|
|
|
|
let id =
|
|
match id with
|
|
| SynIdent.SynIdent (ident, _) -> ident
|
|
|
|
// As far as I can tell, there's no way to get any attributes here? :shrug:
|
|
let attrs = attrs |> List.collect (fun l -> l.Attributes)
|
|
|
|
{
|
|
Fields = fields
|
|
Attrs = attrs
|
|
Ident = id
|
|
}
|