mirror of
https://github.com/rgleichman/glance.git
synced 2024-08-16 18:30:36 +03:00
Support data declarations.
This commit is contained in:
parent
e18b2a1bd8
commit
10fe364e76
@ -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]
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user