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-29 06:53:51 +03:00
|
|
|
import Icons(ColorStyle(..), colorScheme, multilineComment)
|
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-05-23 09:19:06 +03:00
|
|
|
renderFile :: String -> String -> IO (Diagram B)
|
|
|
|
renderFile inputFilename includeComments = do
|
|
|
|
parseResult <- Exts.parseFileWithComments
|
|
|
|
(Exts.defaultParseMode
|
|
|
|
{Exts.extensions = [Exts.EnableExtension Exts.MultiParamTypeClasses, Exts.EnableExtension Exts.FlexibleContexts],
|
|
|
|
Exts.parseFilename = inputFilename
|
|
|
|
})
|
2016-05-16 08:02:17 +03:00
|
|
|
inputFilename
|
2016-02-24 10:14:00 +03:00
|
|
|
let
|
2016-05-23 09:19:06 +03:00
|
|
|
(parsedModule, comments) = Exts.fromParseResult parseResult
|
2016-02-24 10:14:00 +03:00
|
|
|
drawings = drawingsFromModule parsedModule
|
2016-11-22 08:51:35 +03:00
|
|
|
--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-29 06:53:51 +03:00
|
|
|
commentsInBoxes = fmap (\(Exts.Comment _ _ c) -> alignL $ multilineComment white (opaque white) c) comments
|
2016-05-23 09:19:06 +03:00
|
|
|
diagramsAndComments = vsep 2 $ zipWith (\x y -> x === strutY 0.4 === y) commentsInBoxes (fmap alignL diagrams)
|
|
|
|
justDiagrams = vsep 1 $ fmap alignL diagrams
|
|
|
|
diagramsAndMaybeComments = if includeComments == "c" then diagramsAndComments else justDiagrams
|
2016-11-22 08:51:35 +03:00
|
|
|
--print comments
|
2016-05-23 09:19:06 +03:00
|
|
|
pure (bgFrame 1 (backgroundC colorScheme) diagramsAndMaybeComments :: 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
|