mirror of
https://github.com/rgleichman/glance.git
synced 2024-09-11 15:05:41 +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 Data.Maybe(catMaybes, isJust)
|
||||||
|
|
||||||
import qualified Language.Haskell.Exts as Exts
|
import qualified Language.Haskell.Exts as Exts
|
||||||
|
import qualified Language.Haskell.Exts.Pretty as PExts
|
||||||
|
|
||||||
import TranslateCore(nTupleSectionString, nTupleString, nListString)
|
import TranslateCore(nTupleSectionString, nTupleString, nListString)
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ data SimpDecl l =
|
|||||||
-- These don't have decl lists, since only lets have decl lists
|
-- These don't have decl lists, since only lets have decl lists
|
||||||
SdPatBind l (SimpPat l) (SimpExp l)
|
SdPatBind l (SimpPat l) (SimpExp l)
|
||||||
| SdTypeSig l [Exts.Name l] (Exts.Type l)
|
| SdTypeSig l [Exts.Name l] (Exts.Type l)
|
||||||
|
-- TODO Add a visual representation of data declarations
|
||||||
|
| SdDataDecl l String
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
data SimpPat l =
|
data SimpPat l =
|
||||||
@ -182,6 +185,7 @@ hsDeclToSimpDecl decl = case decl of
|
|||||||
Exts.PatBind l pat rhs maybeBinds -> SdPatBind l (hsPatToSimpPat pat) expr
|
Exts.PatBind l pat rhs maybeBinds -> SdPatBind l (hsPatToSimpPat pat) expr
|
||||||
where
|
where
|
||||||
expr = whereToLet l rhs maybeBinds
|
expr = whereToLet l rhs maybeBinds
|
||||||
|
Exts.DataDecl l _ _ _ _ _ -> SdDataDecl l (PExts.prettyPrint decl)
|
||||||
_ -> error $ "Unsupported syntax in hsDeclToSimpDecl: " ++ show decl
|
_ -> error $ "Unsupported syntax in hsDeclToSimpDecl: " ++ show decl
|
||||||
|
|
||||||
hsBindsToDecls :: Show a => Exts.Binds a -> [SimpDecl a]
|
hsBindsToDecls :: Show a => Exts.Binds a -> [SimpDecl a]
|
||||||
|
@ -365,6 +365,7 @@ getBoundVarName d = case d of
|
|||||||
-- TODO Should evalState be used here?
|
-- TODO Should evalState be used here?
|
||||||
$ evalState (evalPattern pat) initialIdState
|
$ evalState (evalPattern pat) initialIdState
|
||||||
SdTypeSig _ _ _ -> []
|
SdTypeSig _ _ _ -> []
|
||||||
|
SdDataDecl _ _ -> []
|
||||||
|
|
||||||
evalDecls :: Show l =>
|
evalDecls :: Show l =>
|
||||||
EvalContext -> [SimpDecl l] -> State IDState (SyntaxGraph, EvalContext)
|
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
|
evalDecl c d = case d of
|
||||||
SdPatBind l pat e -> evalPatBind l c pat e
|
SdPatBind l pat e -> evalPatBind l c pat e
|
||||||
SdTypeSig _ names typeForNames -> fst <$> evalTypeSig names typeForNames
|
SdTypeSig _ names typeForNames -> fst <$> evalTypeSig names typeForNames
|
||||||
|
SdDataDecl _ declStr -> fst <$> makeBox declStr
|
||||||
|
|
||||||
-- END evalDecl
|
-- END evalDecl
|
||||||
|
|
||||||
|
@ -274,6 +274,12 @@ typeSigTests = [
|
|||||||
, "f :: Int -> Bool"
|
, "f :: Int -> Bool"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
dataDeclTests :: [String]
|
||||||
|
dataDeclTests = [
|
||||||
|
"data Foo"
|
||||||
|
, "data Foo = Foo Int"
|
||||||
|
]
|
||||||
|
|
||||||
testDecls :: [String]
|
testDecls :: [String]
|
||||||
testDecls = mconcat [
|
testDecls = mconcat [
|
||||||
simpleTests
|
simpleTests
|
||||||
@ -291,6 +297,7 @@ testDecls = mconcat [
|
|||||||
, operatorTests
|
, operatorTests
|
||||||
, otherTests
|
, otherTests
|
||||||
, typeSigTests
|
, typeSigTests
|
||||||
|
, dataDeclTests
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user