2016-01-05 04:18:42 +03:00
|
|
|
{-# LANGUAGE NoMonomorphismRestriction, FlexibleContexts, TypeFamilies #-}
|
|
|
|
module Main where
|
2016-05-12 09:08:18 +03:00
|
|
|
import Prelude hiding (return)
|
2016-01-05 04:18:42 +03:00
|
|
|
|
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-05-12 09:08:18 +03:00
|
|
|
import Icons(ColorStyle(..), colorScheme)
|
2016-01-23 05:28:55 +03:00
|
|
|
import Rendering(renderDrawing)
|
2016-05-12 09:08:18 +03:00
|
|
|
import Translate(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-05-16 08:02:17 +03:00
|
|
|
-- Add comments as text boxes, and use that to make a getting started guide for the README.
|
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-05-12 09:08:18 +03:00
|
|
|
-- Investigate arrows not being drawn
|
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-05-16 08:02:17 +03:00
|
|
|
renderFile :: String -> IO (Diagram B)
|
|
|
|
renderFile inputFilename= do
|
2016-02-24 10:14:00 +03:00
|
|
|
parseResult <- Exts.parseFileWithExts [Exts.EnableExtension Exts.MultiParamTypeClasses, Exts.EnableExtension Exts.FlexibleContexts]
|
2016-05-16 08:02:17 +03:00
|
|
|
inputFilename
|
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
|
2016-05-16 08:02:17 +03:00
|
|
|
pure (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-16 08:02:17 +03:00
|
|
|
main = mainWith renderFile
|