Support data declarations.

This commit is contained in:
Robbie Gleichman 2019-01-04 15:34:03 -08:00
parent e18b2a1bd8
commit 10fe364e76
3 changed files with 13 additions and 0 deletions

View File

@ -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]

View File

@ -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

View File

@ -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
]