diff options
Diffstat (limited to 'src/Language/Fiddle/GenericTree.hs')
-rw-r--r-- | src/Language/Fiddle/GenericTree.hs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/Language/Fiddle/GenericTree.hs b/src/Language/Fiddle/GenericTree.hs index f0ac96a..165949a 100644 --- a/src/Language/Fiddle/GenericTree.hs +++ b/src/Language/Fiddle/GenericTree.hs @@ -10,6 +10,7 @@ module Language.Fiddle.GenericTree where +import Control.Monad.Identity (Identity) import Data.Aeson.Encoding (text) import Data.Aeson.Types as Aeson import Data.Foldable (Foldable (toList)) @@ -20,6 +21,7 @@ import qualified Data.Vector import GHC.Generics import GHC.TypeLits (KnownSymbol, symbolVal) import Language.Fiddle.Ast +import Language.Fiddle.Internal.UnitInterface import Language.Fiddle.Types type Context stage = @@ -28,9 +30,26 @@ type Context stage = ToGenericSyntaxTreeValue (NumberType stage), Show (ImportInterface stage), Show (FiddleUnitInterface stage), - Show (QualificationMetadata stage ()) + Show (QualificationMetadata stage ()), + Show (QualificationMetadata stage ExportedPackageDecl), + Show (QualificationMetadata stage ExportedLocationDecl), + Show (QualificationMetadata stage ExportedBitsDecl), + Show (QualificationMetadata stage ExportedTypeDecl), + Show (QualificationMetadata stage ExportedObjectDecl) ) +class FunctorShow f where + showf :: (Show a) => f a -> String + +instance (Show l) => FunctorShow (Either l) where + showf = show + +instance FunctorShow Maybe where + showf = show + +instance FunctorShow Identity where + showf = show + data GenericSyntaxTree f a where {- GenericSyntaxtTree with a name and children. -} SyntaxTreeObject :: @@ -103,6 +122,9 @@ class ToGenericSyntaxTreeValue v where forall f a. (Show v) => v -> Maybe (GenericSyntaxTree f a) toGenericSyntaxTreeValue = Just . SyntaxTreeValue . show +instance ToGenericSyntaxTreeValue (f a) where + toGenericSyntaxTreeValue = const Nothing + instance ToGenericSyntaxTreeValue Data.Text.Text where toGenericSyntaxTreeValue = Just . SyntaxTreeValue . Data.Text.unpack @@ -140,6 +162,11 @@ instance gToGenericSyntaxTree _ k1 = SyntaxTreeDeferred (toGenericSyntaxTree <$> unK1 k1) instance + GToGenericSyntaxTree (Rec0 (f x)) f a + where + gToGenericSyntaxTree _ k1 = SyntaxTreeList [] + +instance (GenericContext r f a, Traversable f1) => GToGenericSyntaxTree (Rec0 (f1 (r f a))) f a where @@ -157,6 +184,7 @@ instance instance (GenericContext t f a) => GToMemberList (Rec0 (t f a)) f a where gToMemberList _ a = [toGenericSyntaxTree (unK1 a)] + instance (GenericContext t f a, Foldable l) => GToMemberList (Rec0 (l (t f a))) f a |