2016-01-05 04:18:42 +03:00
|
|
|
{-# LANGUAGE NoMonomorphismRestriction, FlexibleContexts, TypeFamilies #-}
|
|
|
|
module Main where
|
|
|
|
|
2016-05-10 09:45:37 +03:00
|
|
|
-- Note: (#) and (&) are hidden in all Glance source files, since they would require
|
|
|
|
-- - an special case when translating when Glance is run on its own source code.
|
|
|
|
import Diagrams.Prelude hiding ((#), (&))
|
2016-01-05 04:18:42 +03:00
|
|
|
import Diagrams.Backend.SVG.CmdLine
|
2016-02-24 10:14:00 +03:00
|
|
|
import qualified Language.Haskell.Exts as Exts
|
2016-01-08 04:03:04 +03:00
|
|
|
|
2016-04-06 08:19:05 +03:00
|
|
|
import Icons(flatLambda, textBox, colorScheme, ColorStyle(..), nestedApplyDia)
|
2016-01-23 05:28:55 +03:00
|
|
|
import Rendering(renderDrawing)
|
|
|
|
import Util(toNames, portToPort, iconToPort, iconToIcon,
|
2016-01-27 02:29:02 +03:00
|
|
|
iconToIconEnds, iconTailToPort)
|
2016-01-21 05:24:42 +03:00
|
|
|
import Types(Icon(..), Drawing(..), EdgeEnd(..))
|
2016-02-27 09:58:49 +03:00
|
|
|
import Translate(translateString, drawingsFromModule)
|
2016-02-24 10:14:00 +03:00
|
|
|
|
2016-01-05 04:18:42 +03:00
|
|
|
|
2016-01-21 05:24:42 +03:00
|
|
|
-- TODO Now --
|
2016-05-10 09:45:37 +03:00
|
|
|
-- Fix icon nesting if a non-nestable icon (eg. flatLambdaIcon) is part of the expression.
|
|
|
|
-- - eg. y = f $ g (\x -> x)
|
|
|
|
-- Fix rotation missing edges to nested diagrams.
|
|
|
|
|
|
|
|
-- Add a maximum nesting depth.
|
2016-03-22 07:37:19 +03:00
|
|
|
-- Clean up Rendering and Icons.
|
2016-03-28 00:17:50 +03:00
|
|
|
|
2016-02-26 04:10:12 +03:00
|
|
|
-- Refactor Translate
|
2016-02-27 09:58:49 +03:00
|
|
|
-- Add documentation.
|
2016-02-26 04:10:12 +03:00
|
|
|
-- Have the file be a command line argument to main.
|
2016-03-28 02:49:58 +03:00
|
|
|
|
2016-03-05 00:24:09 +03:00
|
|
|
-- Move tests out of main.
|
2016-01-21 05:24:42 +03:00
|
|
|
|
|
|
|
-- TODO Later --
|
2016-05-10 09:45:37 +03:00
|
|
|
-- Why is totalLengthOfLines not nesting?
|
|
|
|
|
2016-03-28 02:49:58 +03:00
|
|
|
-- Visual todos:
|
2016-05-10 09:45:37 +03:00
|
|
|
-- Don't rotate text and nested icons, give them rectangualar bounding boxes in GraphViz. (Perhaps use a typeclass for isRotateAble)
|
2016-03-23 08:15:29 +03:00
|
|
|
-- Give lines a black border to make line crossings easier to see.
|
|
|
|
-- Give lines that cross the border of a lambda function a special color.
|
2016-03-28 02:49:58 +03:00
|
|
|
-- Line intersections should have a small circle. This could probably be done with
|
|
|
|
-- a line ending.
|
|
|
|
-- Let each bool, value pair in Guard icon be flipped to reduce line crossings. Do the same for case.
|
|
|
|
-- Let lines connect to ports in multiple locations (eg. case value, or guard result)
|
|
|
|
-- Rotate icons based on the outgoing line's difference from ideal angle, not line distance.
|
|
|
|
-- Improve line routing. Draw curved lines with outgoing lines at fixed angles.
|
|
|
|
-- - connectPerim might be useful for this.
|
2016-05-10 09:45:37 +03:00
|
|
|
-- For nested apply, cycle through different colors and line styles (eg. dashed, solid, wavy)
|
|
|
|
-- - for each nesting level. This will help distinguish what is an argument to which funciton.
|
2016-03-23 08:15:29 +03:00
|
|
|
|
2016-03-28 00:17:50 +03:00
|
|
|
-- Translate todos:
|
2016-05-10 09:45:37 +03:00
|
|
|
-- Make nested version of FlatLambdaIcon
|
2016-03-28 00:17:50 +03:00
|
|
|
-- Fix test case x of {0 -> 1; y -> y}.
|
2016-03-06 09:26:03 +03:00
|
|
|
-- Add proper RecConstr, and RecUpdate support.
|
2016-02-27 09:58:49 +03:00
|
|
|
-- Eliminate BranchIcon in Alts.
|
2016-02-10 09:29:07 +03:00
|
|
|
-- Eliminate BranchIcon for the identity funciton "y x = x"
|
2016-02-22 02:15:16 +03:00
|
|
|
-- otherwise Guard special case
|
2016-03-28 02:49:58 +03:00
|
|
|
|
2016-01-22 12:38:28 +03:00
|
|
|
(d0A, d0B, d0Res, d0Foo, d0Bar) = ("A", "B", "res", "foo", "bar")
|
2016-01-09 06:54:07 +03:00
|
|
|
d0Icons = toNames
|
2016-03-22 01:42:32 +03:00
|
|
|
[(d0A, ApplyAIcon 1),
|
|
|
|
(d0B, ApplyAIcon 1),
|
2016-01-22 12:38:28 +03:00
|
|
|
(d0Res, ResultIcon),
|
|
|
|
(d0Foo, TextBoxIcon d0Foo),
|
|
|
|
(d0Bar, TextBoxIcon d0Bar)
|
2016-01-09 04:53:12 +03:00
|
|
|
]
|
2016-01-08 04:03:04 +03:00
|
|
|
|
2016-01-09 06:54:07 +03:00
|
|
|
d0Edges =
|
2016-01-08 13:15:37 +03:00
|
|
|
[
|
2016-02-10 10:50:38 +03:00
|
|
|
portToPort d0A 0 d0B 1,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort d0Foo d0B 0,
|
2016-02-10 10:50:38 +03:00
|
|
|
iconToPort d0Res d0A 1,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort d0Foo d0B 0,
|
2016-02-10 10:50:38 +03:00
|
|
|
iconToPort d0Bar d0B 2,
|
|
|
|
iconToPort d0Bar d0A 2
|
2016-01-08 13:15:37 +03:00
|
|
|
]
|
2016-01-08 04:03:04 +03:00
|
|
|
|
2016-01-10 06:17:22 +03:00
|
|
|
drawing0 = Drawing d0Icons d0Edges []
|
|
|
|
d0Name = toName "d0"
|
|
|
|
|
2016-01-22 12:38:28 +03:00
|
|
|
(s1Lam, s1y, s1z, s1q) = ("lam0", "y", "z", "q")
|
|
|
|
superIcons = toNames [
|
|
|
|
(s1Lam, LambdaRegionIcon 3 d0Name),
|
|
|
|
(s1y, TextBoxIcon s1y),
|
|
|
|
(s1z, TextBoxIcon s1z),
|
|
|
|
(s1q, TextBoxIcon s1q)
|
2016-01-09 04:53:12 +03:00
|
|
|
]
|
|
|
|
|
2016-01-22 12:38:28 +03:00
|
|
|
superEdges =
|
|
|
|
[
|
|
|
|
portToPort (s1Lam .> d0A) 1 s1Lam 0,
|
|
|
|
iconToIcon s1y s1Lam,
|
|
|
|
iconToIcon s1z s1Lam,
|
|
|
|
iconToIcon s1q s1Lam,
|
|
|
|
iconToIcon d0A s1z,
|
|
|
|
iconToPort (s1Lam .> d0Foo .> d0Foo) s1Lam 0
|
2016-01-09 04:53:12 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
--superDrawing = Drawing [((toName "lam0"), LambdaRegionIcon 3 (toName"d0"))] superEdges [((toName "d0"), drawing0)]
|
2016-01-09 06:54:07 +03:00
|
|
|
superDrawing = Drawing superIcons superEdges [(d0Name, drawing0)]
|
2016-01-08 13:15:37 +03:00
|
|
|
|
2016-01-10 06:17:22 +03:00
|
|
|
super2Icons = toNames [
|
2016-01-22 12:38:28 +03:00
|
|
|
(s1Lam, LambdaRegionIcon 1 d0Name),
|
2016-01-10 06:17:22 +03:00
|
|
|
--("y", TextBoxIcon "y"),
|
|
|
|
("lam1", LambdaRegionIcon 2 d0Name)
|
|
|
|
]
|
|
|
|
|
|
|
|
super2Edges =
|
|
|
|
[
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToIcon s1Lam "lam1"
|
2016-01-10 06:17:22 +03:00
|
|
|
--iconToIcon "y" "lam0"
|
|
|
|
]
|
|
|
|
|
|
|
|
super2Drawing = Drawing super2Icons super2Edges [(d0Name, drawing0)]
|
|
|
|
super2Name = toName "s2"
|
|
|
|
|
|
|
|
super3Icons = toNames [
|
2016-01-22 12:38:28 +03:00
|
|
|
(s1Lam, LambdaRegionIcon 3 super2Name),
|
2016-01-10 06:17:22 +03:00
|
|
|
--("y", TextBoxIcon "y"),
|
2016-01-22 12:38:28 +03:00
|
|
|
("lam1", LambdaRegionIcon 4 super2Name)
|
2016-01-10 06:17:22 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
super3Edges =
|
|
|
|
[
|
|
|
|
-- iconToIcon "lam0" "lam1",
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToIcon s1Lam "A"
|
2016-01-10 06:17:22 +03:00
|
|
|
]
|
2016-01-22 12:38:28 +03:00
|
|
|
|
|
|
|
super3Drawing = Drawing super3Icons super2Edges [(super2Name, super2Drawing)]
|
|
|
|
|
|
|
|
(fG0, fOne, fEq0, fMinus1, fEq0Ap, fMinus1Ap, fTimes, fRecurAp, fTimesAp, fArg, fRes) =
|
|
|
|
("g0", "one", "eq0", "-1", "eq0Ap", "-1Ap", "*", "recurAp", "*Ap", "arg", "res")
|
2016-01-10 06:17:22 +03:00
|
|
|
|
2016-01-20 02:52:56 +03:00
|
|
|
fact0Icons = toNames
|
2016-01-14 02:08:08 +03:00
|
|
|
[
|
2016-01-22 12:38:28 +03:00
|
|
|
(fG0, GuardIcon 2),
|
|
|
|
(fOne, TextBoxIcon "1"),
|
|
|
|
(fEq0, TextBoxIcon "== 0"),
|
|
|
|
(fMinus1, TextBoxIcon fMinus1),
|
2016-03-22 01:42:32 +03:00
|
|
|
(fEq0Ap, ApplyAIcon 1),
|
|
|
|
(fMinus1Ap, ApplyAIcon 1),
|
2016-01-22 12:38:28 +03:00
|
|
|
(fTimes, TextBoxIcon fTimes),
|
2016-03-22 01:42:32 +03:00
|
|
|
(fRecurAp, ApplyAIcon 1),
|
|
|
|
(fTimesAp, ApplyAIcon 2),
|
2016-01-22 12:38:28 +03:00
|
|
|
(fArg, BranchIcon),
|
|
|
|
(fRes, ResultIcon)
|
2016-01-14 02:08:08 +03:00
|
|
|
]
|
|
|
|
|
2016-01-20 02:52:56 +03:00
|
|
|
fact0Edges = [
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort fEq0 fEq0Ap 0,
|
2016-02-10 10:50:38 +03:00
|
|
|
portToPort fEq0Ap 1 fG0 3,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort fMinus1 fMinus1Ap 0,
|
|
|
|
iconToPort fTimes fTimesAp 0,
|
|
|
|
iconToPort fOne fG0 2,
|
2016-02-10 10:50:38 +03:00
|
|
|
portToPort fTimesAp 2 fG0 4,
|
|
|
|
portToPort fRecurAp 1 fTimesAp 3,
|
|
|
|
iconToPort fArg fEq0Ap 2,
|
|
|
|
iconToPort fArg fMinus1Ap 2,
|
|
|
|
iconToPort fArg fTimesAp 1,
|
|
|
|
portToPort fMinus1Ap 1 fRecurAp 2,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort fRes fG0 0
|
2016-01-14 02:08:08 +03:00
|
|
|
]
|
|
|
|
|
2016-01-20 02:52:56 +03:00
|
|
|
fact0Drawing = Drawing fact0Icons fact0Edges []
|
|
|
|
fact0Name = toName "fac0"
|
|
|
|
|
|
|
|
factLam0Icons = toNames [
|
|
|
|
("lam0", LambdaRegionIcon 1 fact0Name),
|
|
|
|
("fac", TextBoxIcon "factorial")
|
|
|
|
]
|
|
|
|
|
|
|
|
factLam0Edges = [
|
2016-02-10 10:50:38 +03:00
|
|
|
iconToPort ("lam0" .> fArg) "lam0" 0,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort "lam0" ("lam0" .> fRecurAp) 0,
|
2016-01-20 02:52:56 +03:00
|
|
|
iconToIcon "lam0" "fac"
|
|
|
|
]
|
|
|
|
|
|
|
|
factLam0Drawing = Drawing factLam0Icons factLam0Edges [(fact0Name, fact0Drawing)]
|
2016-01-14 02:08:08 +03:00
|
|
|
|
2016-01-21 06:37:03 +03:00
|
|
|
fact1Icons = toNames
|
|
|
|
[
|
2016-01-22 12:38:28 +03:00
|
|
|
(fG0, GuardIcon 2),
|
|
|
|
(fOne, TextBoxIcon "1"),
|
|
|
|
(fEq0, TextBoxIcon "== 0"),
|
|
|
|
(fMinus1, TextBoxIcon fMinus1),
|
|
|
|
(fTimes, TextBoxIcon fTimes),
|
2016-03-22 01:42:32 +03:00
|
|
|
(fRecurAp, ApplyAIcon 1),
|
|
|
|
(fTimesAp, ApplyAIcon 2),
|
2016-01-22 12:38:28 +03:00
|
|
|
(fArg, BranchIcon),
|
|
|
|
(fRes, ResultIcon)
|
2016-01-21 06:37:03 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
fact1Edges = [
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToIconEnds fArg EndNone fEq0 EndAp1Arg,
|
|
|
|
iconTailToPort fEq0 EndAp1Result fG0 3,
|
|
|
|
iconToIconEnds fArg EndNone fMinus1 EndAp1Arg,
|
2016-02-10 10:50:38 +03:00
|
|
|
iconTailToPort fMinus1 EndAp1Result fRecurAp 2,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort fTimes fTimesAp 0,
|
|
|
|
iconToPort fOne fG0 2,
|
|
|
|
portToPort fTimesAp 1 fG0 4,
|
2016-02-10 10:50:38 +03:00
|
|
|
portToPort fRecurAp 1 fTimesAp 3,
|
2016-01-22 12:38:28 +03:00
|
|
|
iconToPort fArg fTimesAp 2,
|
|
|
|
iconToPort fRes fG0 0
|
2016-01-21 06:37:03 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
fact1Drawing = Drawing fact1Icons fact1Edges []
|
|
|
|
|
|
|
|
factLam1Drawing = Drawing factLam0Icons factLam0Edges [(fact0Name, fact1Drawing)]
|
|
|
|
|
2016-01-23 05:08:53 +03:00
|
|
|
-- fact2 is like fact1, but uses fTimesAp port 2 to distrubute the argument,
|
|
|
|
-- not fArg
|
|
|
|
fact2Icons = toNames
|
|
|
|
[
|
|
|
|
(fG0, GuardIcon 2),
|
|
|
|
(fOne, TextBoxIcon "1"),
|
|
|
|
(fEq0, TextBoxIcon "== 0"),
|
|
|
|
(fMinus1, TextBoxIcon fMinus1),
|
|
|
|
(fTimes, TextBoxIcon fTimes),
|
2016-03-22 01:42:32 +03:00
|
|
|
(fRecurAp, ApplyAIcon 1),
|
|
|
|
(fTimesAp, ApplyAIcon 2),
|
2016-01-23 05:08:53 +03:00
|
|
|
--(fArg, BranchIcon),
|
|
|
|
(fRes, ResultIcon)
|
|
|
|
]
|
|
|
|
|
|
|
|
fact2Edges = [
|
|
|
|
--iconToIconEnds fArg EndNone fEq0 EndAp1Arg,
|
|
|
|
iconTailToPort fEq0 EndAp1Arg fTimesAp 2,
|
|
|
|
iconTailToPort fEq0 EndAp1Result fG0 3,
|
|
|
|
--iconToIconEnds fArg EndNone fMinus1 EndAp1Arg,
|
|
|
|
iconTailToPort fMinus1 EndAp1Arg fTimesAp 2,
|
2016-02-10 10:50:38 +03:00
|
|
|
iconTailToPort fMinus1 EndAp1Result fRecurAp 2,
|
2016-01-23 05:08:53 +03:00
|
|
|
iconToPort fTimes fTimesAp 0,
|
|
|
|
iconToPort fOne fG0 2,
|
|
|
|
portToPort fTimesAp 1 fG0 4,
|
2016-02-10 10:50:38 +03:00
|
|
|
portToPort fRecurAp 1 fTimesAp 3,
|
2016-01-23 05:08:53 +03:00
|
|
|
--iconToPort fArg fTimesAp 2,
|
|
|
|
iconToPort fRes fG0 0
|
|
|
|
]
|
|
|
|
|
|
|
|
fact2Drawing = Drawing fact2Icons fact2Edges []
|
|
|
|
|
|
|
|
factLam2Edges = [
|
|
|
|
iconToPort ("lam0" .> fTimesAp .> (2 :: Int)) "lam0" 0,
|
|
|
|
iconToPort "lam0" ("lam0" .> fRecurAp) 0,
|
|
|
|
iconToIcon "lam0" "fac"
|
|
|
|
]
|
|
|
|
factLam2Drawing = Drawing factLam0Icons factLam2Edges [(fact0Name, fact2Drawing)]
|
|
|
|
|
2016-01-23 04:06:42 +03:00
|
|
|
(arr1, arr2, arr3, arr4) = ("arr1", "arr2", "arr3", "arr4")
|
|
|
|
|
|
|
|
arrowTestIcons = toNames [
|
|
|
|
(arr1, TextBoxIcon "1"),
|
|
|
|
(arr2, TextBoxIcon "2"),
|
|
|
|
(arr3, TextBoxIcon "3"),
|
|
|
|
(arr4, TextBoxIcon "4")
|
|
|
|
]
|
|
|
|
|
|
|
|
arrowTestEdges = [
|
|
|
|
iconToIconEnds arr1 EndAp1Arg arr2 EndAp1Result,
|
|
|
|
iconToIconEnds arr1 EndAp1Result arr3 EndAp1Arg,
|
|
|
|
iconToIconEnds arr2 EndAp1Result arr3 EndAp1Result,
|
|
|
|
iconToIconEnds arr1 EndAp1Arg arr4 EndAp1Arg
|
|
|
|
]
|
|
|
|
|
|
|
|
arrowTestDrawing = Drawing arrowTestIcons arrowTestEdges []
|
|
|
|
|
2016-05-10 09:45:37 +03:00
|
|
|
nestedTestIcons = toNames [
|
|
|
|
("n1", NestedApply "N1" args),
|
|
|
|
("t1", TextBoxIcon "T1"),
|
|
|
|
("t2", TextBoxIcon "t2")
|
|
|
|
]
|
|
|
|
where
|
|
|
|
innerArgs = [Just (toName "t", TextBoxIcon "t"), Nothing, Just (toName "n2", NestedApply "n2" [Nothing])]
|
|
|
|
args = [
|
|
|
|
Nothing, Just (toName "foo", TextBoxIcon "3"),
|
|
|
|
Just (toName "in", NestedApply "inner" innerArgs)
|
|
|
|
]
|
|
|
|
|
|
|
|
nestedTestEdges = [
|
|
|
|
iconToPort "t1" "n1" 2,
|
|
|
|
--iconToPort "t1" "in" 1,
|
|
|
|
--iconToPort "t2" ("n1" .> "in") 3,
|
|
|
|
iconToPort "t2" ("n1" .> "in" .> "n2") 2
|
|
|
|
]
|
|
|
|
|
|
|
|
nestedTextDrawing = Drawing nestedTestIcons nestedTestEdges []
|
|
|
|
|
2016-01-09 08:52:41 +03:00
|
|
|
main1 :: IO ()
|
2016-01-09 04:53:12 +03:00
|
|
|
main1 = do
|
2016-05-10 09:45:37 +03:00
|
|
|
placedNodes <- renderDrawing nestedTextDrawing
|
|
|
|
mainWith (bgFrame 1 (backgroundC colorScheme) placedNodes :: Diagram B)
|
2016-01-08 04:03:04 +03:00
|
|
|
|
2016-05-10 09:45:37 +03:00
|
|
|
main2 = mainWith ((bgFrame 0.1 black $ dia False 0) :: Diagram B)
|
2016-04-06 08:19:05 +03:00
|
|
|
where
|
|
|
|
args = [Nothing, Just (toName "foo", TextBoxIcon "3"), Just (toName "in", NestedApply "inner" [Just (toName "t", TextBoxIcon "t")])]
|
|
|
|
dia = nestedApplyDia "Hello world" args
|
2016-01-14 00:50:06 +03:00
|
|
|
|
2016-02-10 10:50:38 +03:00
|
|
|
main3 :: IO ()
|
|
|
|
main3 = do
|
2016-03-21 12:00:04 +03:00
|
|
|
renderedDiagrams <- traverse renderDrawing allDrawings
|
2016-05-10 09:45:37 +03:00
|
|
|
let vCattedDrawings = vsep 0.5 renderedDiagrams
|
|
|
|
mainWith (bgFrame 1 (backgroundC colorScheme) vCattedDrawings :: Diagram B)
|
2016-02-10 10:50:38 +03:00
|
|
|
where
|
|
|
|
allDrawings = [
|
|
|
|
drawing0,
|
|
|
|
superDrawing,
|
|
|
|
super2Drawing,
|
|
|
|
super3Drawing,
|
|
|
|
fact0Drawing,
|
|
|
|
factLam0Drawing,
|
|
|
|
fact1Drawing,
|
|
|
|
factLam1Drawing,
|
|
|
|
fact2Drawing,
|
|
|
|
factLam2Drawing,
|
|
|
|
arrowTestDrawing
|
|
|
|
]
|
2016-05-10 09:45:37 +03:00
|
|
|
|
|
|
|
nestedTests = [
|
|
|
|
"y = f x",
|
|
|
|
"y = f (g x)",
|
|
|
|
"y = let x = 1 in f x",
|
|
|
|
"y = let x = 1 in f (g x)",
|
|
|
|
"y = f []",
|
|
|
|
"y = f [1]",
|
|
|
|
"y = f [1,2]",
|
|
|
|
"y = f [g 3, h 5]"
|
|
|
|
]
|
|
|
|
|
|
|
|
dollarTests = [
|
|
|
|
"y = f $ g 3",
|
|
|
|
" y = f 1 $ g 2 "
|
|
|
|
]
|
|
|
|
|
2016-02-24 10:14:00 +03:00
|
|
|
specialTests = [
|
2016-02-25 01:46:49 +03:00
|
|
|
"lookupTail EndAp1Arg = (arrowTail .~ dart')",
|
|
|
|
"y = x .~ y",
|
2016-02-24 10:14:00 +03:00
|
|
|
"initialIdState = IDState 0",
|
|
|
|
"y = f x",
|
|
|
|
"yyy = fff xxx",
|
|
|
|
"yyyyy = fffff xxxxx"
|
|
|
|
]
|
|
|
|
|
2016-03-06 09:26:03 +03:00
|
|
|
negateTests = [
|
|
|
|
"y = -1",
|
|
|
|
"y = -1/2",
|
|
|
|
"y = -x"
|
|
|
|
]
|
|
|
|
|
2016-03-06 05:01:35 +03:00
|
|
|
doTests = [
|
|
|
|
"y = do {x1}",
|
|
|
|
"y = do {x1; x2}",
|
|
|
|
"y = do {x1; x2; x3}",
|
|
|
|
"y = do {x1 <- m1; x2}",
|
|
|
|
"y = do {(x1, x2) <- m1; x1 + x2}",
|
|
|
|
"y = do {x1 <- m1; x2 <- f x1; g x2}",
|
|
|
|
"y = do {let {x = 1}; x2 <- x; f x2}"
|
|
|
|
]
|
|
|
|
|
2016-03-05 05:49:02 +03:00
|
|
|
enumTests = [
|
|
|
|
"y = [1..]",
|
|
|
|
"y = [1,2..]",
|
|
|
|
"y = [0..10]",
|
|
|
|
"y = [0,1..10]"
|
|
|
|
]
|
|
|
|
|
2016-02-24 10:14:00 +03:00
|
|
|
tupleTests = [
|
2016-02-25 01:46:49 +03:00
|
|
|
"y = ()",
|
2016-03-05 06:00:45 +03:00
|
|
|
"(x, y) = (1,2)",
|
|
|
|
"(x, y, z) = (1,2,3)"
|
2016-02-24 10:14:00 +03:00
|
|
|
]
|
2016-02-10 10:50:38 +03:00
|
|
|
|
2016-03-05 10:49:48 +03:00
|
|
|
listTests = [
|
|
|
|
"y = []",
|
|
|
|
"y = [1]",
|
|
|
|
"y = [1,2]",
|
2016-03-06 09:26:03 +03:00
|
|
|
"y = [1,2,3]",
|
|
|
|
"[x] = 1",
|
|
|
|
"[x, y] = 2",
|
|
|
|
"[x, y, z] = 3"
|
|
|
|
-- TODO: Add this test "(x:y) = 3"
|
2016-03-05 10:49:48 +03:00
|
|
|
]
|
|
|
|
|
2016-02-23 09:01:03 +03:00
|
|
|
caseTests = [
|
2016-02-24 07:47:08 +03:00
|
|
|
"y = case x of {0 -> 1; 2 -> 3}",
|
|
|
|
"y = case f x of {0 -> 1; 2 -> 3}",
|
|
|
|
"y = case x of {Foo a -> a}",
|
2016-02-25 01:46:49 +03:00
|
|
|
"y = case x of {Foo a -> f a; Bar a -> f a}",
|
|
|
|
"y = case x of {F x -> x; G x -> x}",
|
2016-03-28 00:17:50 +03:00
|
|
|
"y = case x of {F -> 0; G -> 1}",
|
|
|
|
"z = case x of {0 -> 1; y -> y}"
|
2016-02-23 09:01:03 +03:00
|
|
|
]
|
|
|
|
|
2016-02-26 04:10:12 +03:00
|
|
|
guardTests = [
|
|
|
|
"y x\n\
|
|
|
|
\ | x == 0 = 1",
|
|
|
|
"y x\n\
|
|
|
|
\ | x == 0 = 1\n\
|
|
|
|
\ | otherwise = 2"
|
|
|
|
]
|
|
|
|
|
2016-02-22 07:26:12 +03:00
|
|
|
patternTests = [
|
2016-02-24 10:14:00 +03:00
|
|
|
"Foo _ x = 3",
|
2016-02-23 00:26:47 +03:00
|
|
|
"y (F x) = x",
|
|
|
|
"y = (\\(F x) -> x)",
|
|
|
|
"y = let {g = 3; F x y = h g} in x y",
|
2016-02-26 05:37:04 +03:00
|
|
|
"y = let {F x y = 3} in x y",
|
2016-02-23 00:26:47 +03:00
|
|
|
"y = let {g = 3; F x y = g} in x y",
|
|
|
|
"y = let F x y = g in x y",
|
|
|
|
"F x = g x",
|
|
|
|
"Foo (Bar x) (Baz y) = f 1 2 x y",
|
2016-03-05 00:24:09 +03:00
|
|
|
"Foo x y = f 1 y x",
|
|
|
|
"t@(x,y) = (x,y)",
|
2016-03-05 10:49:48 +03:00
|
|
|
"y = let {t@(_,_) = (3,4)} in t + 3",
|
|
|
|
"y = let {(x, y) = (1,2)} in x + y",
|
|
|
|
-- TODO: Fix so that lines between patterns are Pattern Color.
|
2016-03-06 09:26:03 +03:00
|
|
|
"y = let {(x, y) = (1,2); (z, w) = x; (m, g) = y} in foo x y z w m g",
|
|
|
|
"(x:y) = 2"
|
2016-02-22 07:26:12 +03:00
|
|
|
]
|
|
|
|
|
2016-02-23 09:01:03 +03:00
|
|
|
lambdaTests = [
|
2016-03-21 12:00:04 +03:00
|
|
|
"y = (\\x -> (\\x -> (\\x -> x) x) x)",
|
|
|
|
"y = (\\x -> (\\x -> (\\x -> x)))",
|
|
|
|
"y = (\\y -> y)",
|
|
|
|
"y = (\\x1 -> (\\x2 -> (\\x3 -> x1 x2 x3)))",
|
|
|
|
"y x = (\\z -> x)",
|
|
|
|
"y = (\\x -> (\\z -> x))",
|
|
|
|
"y x = x",
|
|
|
|
"y x = y x",
|
|
|
|
"y x = g y y",
|
|
|
|
"y f x = f x",
|
|
|
|
"y x = x y",
|
|
|
|
"y x1 x2 = f x1 x3 x2",
|
|
|
|
"y x1 x2 = f x1 x2",
|
|
|
|
"y x = f x1 x2",
|
2016-02-23 09:01:03 +03:00
|
|
|
"{y 0 = 1; y 1= 0}",
|
|
|
|
"y (-1) = 2",
|
|
|
|
"y 1 = 0",
|
|
|
|
"{y (F x) = x; y (G x) = x}",
|
2016-02-27 02:58:50 +03:00
|
|
|
"{y (F x) z = x z; y (G x) z = z x}",
|
2016-02-23 09:01:03 +03:00
|
|
|
"y x = z 3 where z = f x y",
|
|
|
|
"y x = z where z = f x y"
|
|
|
|
]
|
|
|
|
|
2016-02-21 10:34:48 +03:00
|
|
|
letTests = [
|
2016-02-23 09:01:03 +03:00
|
|
|
"y = let {z = (\\x -> y x)} in z",
|
|
|
|
"y = let {z x = y x} in z ",
|
2016-02-22 06:34:33 +03:00
|
|
|
"y = x where x = f 3 y",
|
2016-02-22 02:15:16 +03:00
|
|
|
"y x1 = let {x2 = x1; x3 = x2; x4 = f x3} in x4",
|
|
|
|
"y x1 = let x2 = f x1 in x2 x1",
|
|
|
|
"y x = let x = 3 in x",
|
|
|
|
"y = let {a= 1; x = let {a = 27; x = f a 2} in x} in x",
|
2016-02-21 11:38:06 +03:00
|
|
|
"y = let {a = b; b = a; d = f a} in d",
|
|
|
|
"y = let {a = b; b = a} in a",
|
|
|
|
"y = let x = x in x",
|
|
|
|
"y = let {fibs = cons 0 (cons 1 (zipWith (+) fibs (tail fibs)))} in fibs",
|
|
|
|
"fibs = cons 0 (cons 1 (zipWith (+) fibs (tail fibs)))",
|
|
|
|
"y = let x = f x in x",
|
|
|
|
"y = f y",
|
2016-02-21 10:34:48 +03:00
|
|
|
"y = let {a = f b; b = g a} in b",
|
|
|
|
"y = let {a = 48; b = a + 3} in b",
|
2016-02-21 10:07:46 +03:00
|
|
|
"y = let {b = a; a = 84} in f b",
|
|
|
|
"y = let {x = 1} in f x",
|
|
|
|
"y = let z = 2 in z",
|
|
|
|
"y = let {z = 3; z2 = z} in z2",
|
2016-02-21 10:34:48 +03:00
|
|
|
"y x = let z = x in z"
|
|
|
|
]
|
|
|
|
|
2016-03-05 10:49:48 +03:00
|
|
|
operatorTests = [
|
|
|
|
"y = 1 + 2",
|
|
|
|
"y = map (1 ++) 3",
|
|
|
|
"y = map (++ 1) 3"
|
|
|
|
]
|
|
|
|
|
2016-02-21 10:34:48 +03:00
|
|
|
otherTests = [
|
2016-02-20 00:46:14 +03:00
|
|
|
"y = f 1 'c' 2.3 \"foobar\"",
|
2016-02-19 09:07:38 +03:00
|
|
|
"fact x = if (x == 0) then 1 else (fact x (x - 1))",
|
|
|
|
"fact x = if ((==) 0 x) then 1 else (fact x ((-) x 1))",
|
2016-02-19 07:34:08 +03:00
|
|
|
"y x = if x then (if z then q else x) else w",
|
2016-02-18 10:14:14 +03:00
|
|
|
"y x1 x2 x3 = if f x1 then g x2 else h x3",
|
|
|
|
"y x1 x2 x3 = if x1 then x2 else x3",
|
|
|
|
"y = if b then x else n",
|
2016-02-19 07:34:08 +03:00
|
|
|
"y2 = f x1 x2 x3 x4",
|
|
|
|
"y = x",
|
|
|
|
"y = f x",
|
|
|
|
"y = f (g x)",
|
|
|
|
"y = f (g x1 x2) x3",
|
2016-03-05 05:49:02 +03:00
|
|
|
"y = (f x1 x2) (g x1 x2)",
|
|
|
|
"y = Foo.bar"
|
2016-02-06 09:39:05 +03:00
|
|
|
]
|
|
|
|
|
2016-02-21 10:34:48 +03:00
|
|
|
testDecls = mconcat [
|
2016-05-10 09:45:37 +03:00
|
|
|
--dollarTests
|
|
|
|
nestedTests
|
|
|
|
-- ,negateTests
|
|
|
|
-- ,doTests
|
|
|
|
-- ,enumTests
|
|
|
|
-- ,caseTests
|
|
|
|
-- ,lambdaTests
|
|
|
|
-- ,guardTests
|
|
|
|
-- ,patternTests
|
|
|
|
-- ,specialTests
|
|
|
|
-- ,tupleTests
|
|
|
|
-- ,listTests
|
|
|
|
-- ,letTests
|
|
|
|
-- ,operatorTests
|
|
|
|
-- ,otherTests
|
2016-02-21 10:34:48 +03:00
|
|
|
]
|
|
|
|
|
2016-02-06 09:39:05 +03:00
|
|
|
translateStringToDrawing :: String -> IO (Diagram B)
|
|
|
|
translateStringToDrawing s = do
|
2016-02-04 11:19:08 +03:00
|
|
|
let
|
2016-02-06 09:39:05 +03:00
|
|
|
(drawing, decl) = translateString s
|
2016-02-04 11:19:08 +03:00
|
|
|
print decl
|
2016-02-09 08:54:23 +03:00
|
|
|
putStr "\n"
|
2016-02-05 08:53:21 +03:00
|
|
|
print drawing
|
2016-02-09 08:54:23 +03:00
|
|
|
putStr "\n\n"
|
2016-02-06 09:39:05 +03:00
|
|
|
renderDrawing drawing
|
|
|
|
|
2016-02-10 10:50:38 +03:00
|
|
|
main4 :: IO ()
|
|
|
|
main4 = do
|
2016-03-21 12:00:04 +03:00
|
|
|
drawings <- traverse translateStringToDrawing testDecls
|
2016-02-23 09:01:03 +03:00
|
|
|
let
|
2016-05-10 09:45:37 +03:00
|
|
|
textDrawings = fmap (\t -> alignL $ textBox t False 0) testDecls
|
|
|
|
vCattedDrawings = vsep 1 $ zipWith (===) (fmap alignL drawings) textDrawings
|
|
|
|
mainWith (bgFrame 1 (backgroundC colorScheme) vCattedDrawings :: Diagram B)
|
2016-02-04 11:19:08 +03:00
|
|
|
|
2016-02-24 10:14:00 +03:00
|
|
|
testFiles = [
|
|
|
|
"./app/Main.hs",
|
|
|
|
"./test/test_translate.hs"
|
|
|
|
]
|
|
|
|
|
|
|
|
main5 :: IO ()
|
|
|
|
main5 = do
|
|
|
|
parseResult <- Exts.parseFileWithExts [Exts.EnableExtension Exts.MultiParamTypeClasses, Exts.EnableExtension Exts.FlexibleContexts]
|
2016-05-10 09:45:37 +03:00
|
|
|
--"./app/Icons.hs"
|
|
|
|
"./test/test_nesting.hs"
|
2016-02-24 10:14:00 +03:00
|
|
|
let
|
|
|
|
parsedModule = Exts.fromParseResult parseResult
|
|
|
|
drawings = drawingsFromModule parsedModule
|
|
|
|
print parsedModule
|
|
|
|
print "\n\n"
|
2016-02-25 01:46:49 +03:00
|
|
|
--print drawings
|
2016-02-24 10:14:00 +03:00
|
|
|
|
2016-03-21 12:00:04 +03:00
|
|
|
diagrams <- traverse renderDrawing drawings
|
2016-02-24 10:14:00 +03:00
|
|
|
let
|
2016-05-10 09:45:37 +03:00
|
|
|
vCattedDrawings = vsep 1 $ fmap alignL diagrams
|
|
|
|
mainWith (bgFrame 1 (backgroundC colorScheme) vCattedDrawings :: Diagram B)
|
2016-02-24 10:14:00 +03:00
|
|
|
|
|
|
|
|
2016-01-05 04:18:42 +03:00
|
|
|
main :: IO ()
|
2016-05-10 09:45:37 +03:00
|
|
|
main = main5
|