As patterns translated.

This commit is contained in:
Robbie Gleichman 2016-03-04 13:24:09 -08:00
parent ea99c9bfe4
commit f886a945e5
2 changed files with 18 additions and 1 deletions

View File

@ -20,6 +20,10 @@ import Translate(translateString, drawingsFromModule)
-- Test reference lookup in case rhs.
-- Have the file be a command line argument to main.
-- In evalPatBind, give the edge from the rhs to the pattern a special arrowhead.
-- Use GraphViz circles to represent rotateable icons.
-- Line intersections should have a small circle. This could probably be done with
-- a line ending.
-- Move tests out of main.
-- TODO Later --
-- Add function name and type to LambdaIcons.
@ -311,7 +315,9 @@ patternTests = [
"y = let F x y = g in x y",
"F x = g x",
"Foo (Bar x) (Baz y) = f 1 2 x y",
"Foo x y = f 1 y x"
"Foo x y = f 1 y x",
"t@(x,y) = (x,y)",
"y = let {t@(_,_) = (3,4)} in t + 3"
]
lambdaTests = [

View File

@ -57,6 +57,14 @@ evalPLit :: Exts.Sign -> Exts.Literal -> State IDState (IconGraph, NameAndPort)
evalPLit Exts.Signless l = evalLit l
evalPLit Exts.Negative l = makeBox ('-' : showLiteral l)
evalPAsPat :: Name -> Pat -> State IDState GraphAndRef
evalPAsPat n p = do
(evaledPatGraph, evaledPatRef) <- evalPattern p
let
newBind = [(nameToString n, evaledPatRef)]
newGraph = mempty{igBindings = newBind}
pure (newGraph <> evaledPatGraph, evaledPatRef)
evalPattern :: Pat -> State IDState GraphAndRef
evalPattern p = case p of
PVar n -> pure (mempty, Left $ nameToString n)
@ -65,7 +73,10 @@ evalPattern p = case p of
-- TODO special tuple handling.
PTuple _ patterns -> fmap Right <$> evalPApp (Exts.UnQual $ Ident "(,)") patterns
PParen pat -> evalPattern pat
PAsPat n subPat -> evalPAsPat n subPat
PWildCard -> fmap Right <$> makeBox "_"
_ -> error $ "evalPattern: No pattern in case for " ++ show p
-- TODO: Other cases
--TODO: Consider making this have unique values.
evalQName :: QName -> EvalContext -> State IDState (IconGraph, Reference)