diff --git a/app/SimplifySyntax.hs b/app/SimplifySyntax.hs index c3d229b..3ac8828 100644 --- a/app/SimplifySyntax.hs +++ b/app/SimplifySyntax.hs @@ -15,6 +15,7 @@ import Data.List(foldl') import Data.Maybe(catMaybes, isJust) import qualified Language.Haskell.Exts as Exts +import qualified Language.Haskell.Exts.Pretty as PExts import TranslateCore(nTupleSectionString, nTupleString, nListString) @@ -57,6 +58,8 @@ data SimpDecl l = -- These don't have decl lists, since only lets have decl lists SdPatBind l (SimpPat l) (SimpExp l) | SdTypeSig l [Exts.Name l] (Exts.Type l) + -- TODO Add a visual representation of data declarations + | SdDataDecl l String deriving (Show, Eq) data SimpPat l = @@ -182,6 +185,7 @@ hsDeclToSimpDecl decl = case decl of Exts.PatBind l pat rhs maybeBinds -> SdPatBind l (hsPatToSimpPat pat) expr where expr = whereToLet l rhs maybeBinds + Exts.DataDecl l _ _ _ _ _ -> SdDataDecl l (PExts.prettyPrint decl) _ -> error $ "Unsupported syntax in hsDeclToSimpDecl: " ++ show decl hsBindsToDecls :: Show a => Exts.Binds a -> [SimpDecl a] diff --git a/app/Translate.hs b/app/Translate.hs index 9c709d7..f522933 100644 --- a/app/Translate.hs +++ b/app/Translate.hs @@ -365,6 +365,7 @@ getBoundVarName d = case d of -- TODO Should evalState be used here? $ evalState (evalPattern pat) initialIdState SdTypeSig _ _ _ -> [] + SdDataDecl _ _ -> [] evalDecls :: Show l => EvalContext -> [SimpDecl l] -> State IDState (SyntaxGraph, EvalContext) @@ -610,6 +611,7 @@ evalDecl :: Show l => EvalContext -> SimpDecl l -> State IDState SyntaxGraph evalDecl c d = case d of SdPatBind l pat e -> evalPatBind l c pat e SdTypeSig _ names typeForNames -> fst <$> evalTypeSig names typeForNames + SdDataDecl _ declStr -> fst <$> makeBox declStr -- END evalDecl diff --git a/test/VisualTranslateTests.hs b/test/VisualTranslateTests.hs index 6801b3f..baf726c 100644 --- a/test/VisualTranslateTests.hs +++ b/test/VisualTranslateTests.hs @@ -274,6 +274,12 @@ typeSigTests = [ , "f :: Int -> Bool" ] +dataDeclTests :: [String] +dataDeclTests = [ + "data Foo" + , "data Foo = Foo Int" + ] + testDecls :: [String] testDecls = mconcat [ simpleTests @@ -291,6 +297,7 @@ testDecls = mconcat [ , operatorTests , otherTests , typeSigTests + , dataDeclTests ]