diff --git a/WoofWare.Myriad.Plugins/TeqLicence.txt b/WoofWare.Myriad.Plugins/ApacheLicence.txt similarity index 100% rename from WoofWare.Myriad.Plugins/TeqLicence.txt rename to WoofWare.Myriad.Plugins/ApacheLicence.txt diff --git a/WoofWare.Myriad.Plugins/ArgParserGenerator.fs b/WoofWare.Myriad.Plugins/ArgParserGenerator.fs index e7be6c5..6e13b6a 100644 --- a/WoofWare.Myriad.Plugins/ArgParserGenerator.fs +++ b/WoofWare.Myriad.Plugins/ArgParserGenerator.fs @@ -4,6 +4,7 @@ open System open System.Text open Fantomas.FCS.Syntax open Fantomas.FCS.Text.Range +open TypeEquality open WoofWare.Whippet.Fantomas type internal ArgParserOutputSpec = diff --git a/WoofWare.Myriad.Plugins/CataGenerator.fs b/WoofWare.Myriad.Plugins/CataGenerator.fs index ef767b6..6b7d29c 100644 --- a/WoofWare.Myriad.Plugins/CataGenerator.fs +++ b/WoofWare.Myriad.Plugins/CataGenerator.fs @@ -1174,6 +1174,29 @@ module internal CataGenerator = ] |> SynModuleOrNamespace.createNamespace ns + /// This function comes from Myriad, and is therefore derived from an Apache 2.0-licenced work. + /// https://github.com/MoiraeSoftware/myriad/blob/3c9818faabf9d508c10c28d5ecd26e66fafb48a1/src/Myriad.Core/Ast.fs#L160 + /// A copy of the Apache 2.0 licence is at ApacheLicence.txt. + let groupedTypeDefns (ast : ParsedInput) : (LongIdent * SynTypeDefn list) list = + let rec extractTypes (moduleDecls : SynModuleDecl list) (ns : LongIdent) = + [ + for moduleDecl in moduleDecls do + match moduleDecl with + | SynModuleDecl.Types (types, _) -> yield (ns, types) + | SynModuleDecl.NestedModule (SynComponentInfo (_, _, _, longId, _, _, _, _), _, decls, _, _, _) -> + let combined = longId |> List.append ns + yield! (extractTypes decls combined) + | _ -> () + ] + + [ + match ast with + | ParsedInput.ImplFile (ParsedImplFileInput (_, _, _, _, _, modules, _, _, _)) -> + for SynModuleOrNamespace (namespaceId, _, _, moduleDecls, _, _, _, _, _) in modules do + yield! extractTypes moduleDecls namespaceId + | _ -> () + ] + open Myriad.Core /// Myriad generator that provides a catamorphism for an algebraic data type. @@ -1187,7 +1210,7 @@ type CreateCatamorphismGenerator () = let ast, _ = Ast.fromFilename context.InputFilename |> Async.RunSynchronously |> Array.head - let types = Ast.extractTypeDefn ast + let types = CataGenerator.groupedTypeDefns ast let opens = AstHelper.extractOpens ast diff --git a/WoofWare.Myriad.Plugins/Teq.fs b/WoofWare.Myriad.Plugins/Teq.fs deleted file mode 100644 index 860e345..0000000 --- a/WoofWare.Myriad.Plugins/Teq.fs +++ /dev/null @@ -1,18 +0,0 @@ -namespace WoofWare.Myriad.Plugins - -// Extracted from https://github.com/G-Research/TypeEquality -// which is Apache-2.0 licenced. See `TeqLicence.txt`. -// We inline this code because Myriad doesn't seem to reliably load package references in the generator. -// I have reformatted a little, and stripped out all the code I don't use. - -type internal Teq<'a, 'b> = private | Teq of ('a -> 'b) * ('b -> 'a) - -[] -module internal Teq = - - let refl<'a> : Teq<'a, 'a> = Teq (id, id) - let cast (Teq (f, _)) a = f a - - [] - module Cong = - let believeMe<'a, 'b, 'a2, 'b2> (_ : Teq<'a, 'b>) : Teq<'a2, 'b2> = unbox <| (refl : Teq<'a2, 'a2>) diff --git a/WoofWare.Myriad.Plugins/WoofWare.Myriad.Plugins.fsproj b/WoofWare.Myriad.Plugins/WoofWare.Myriad.Plugins.fsproj index 59df1bd..af29d92 100644 --- a/WoofWare.Myriad.Plugins/WoofWare.Myriad.Plugins.fsproj +++ b/WoofWare.Myriad.Plugins/WoofWare.Myriad.Plugins.fsproj @@ -20,6 +20,7 @@ + @@ -28,7 +29,6 @@ - @@ -41,7 +41,7 @@ - +