2{-# LANGUAGE FlexibleContexts #-}
3module Metadata.Prelude (add) where
5import qualified Data.Map as Map
6import qualified Data.Set as Set
8import qualified AST.Module as Module
9import qualified AST.Variable as Var
12-- DEFINITION OF THE PRELUDE
15 Map.Map Module.Name ([String], Var.Listing Var.Value)
20 Map.unions [ string, text, maybe, openImports ]
22 importing :: Module.Name -> [Var.Value] -> ImportDict
23 importing name values =
24 Map.singleton name ([], Var.Listing values False)
26 openImports :: ImportDict
28 Map.fromList $ map (\name -> (name, ([], Var.openListing))) $
29 [ ["Basics"], ["Signal"], ["List"], ["Time"], ["Color"]
30 , ["Graphics","Element"], ["Graphics","Collage"]
31 , ["Native","Ports"], ["Native","Json"]
35 maybe = importing ["Maybe"] [ Var.ADT "Maybe" Var.openListing ]
38 string = importing ["String"] [Var.Value "show"]
41 text = importing ["Text"] (Var.ADT "Text" (Var.Listing [] False) : values)
45 [ "toText", "leftAligned", "rightAligned", "centered", "justified"
46 , "plainText", "asText", "typeface", "monospace", "bold", "italic"
50-- ADDING PRELUDE TO A MODULE
52add :: Bool -> Module.Module exs body -> Module.Module exs body
53add noPrelude (Module.Module moduleName path exports imports decls) =
54 Module.Module moduleName path exports ammendedImports decls
58 foldr addImport (if noPrelude then Map.empty else prelude) imports
61importDictToList :: ImportDict -> [(Module.Name, Module.ImportMethod)]
62importDictToList dict =
63 concatMap toImports (Map.toList dict)
65 toImports (name, (qualifiers, listing@(Var.Listing explicits open))) =
66 map (\qualifier -> (name, Module.As qualifier)) qualifiers
68 if open || not (null explicits)
69 then [(name, Module.Open listing)]
73addImport :: (Module.Name, Module.ImportMethod) -> ImportDict -> ImportDict
74addImport (name, method) importDict =
75 Map.alter mergeMethods name importDict
77 mergeMethods :: Maybe ([String], Var.Listing Var.Value)
78 -> Maybe ([String], Var.Listing Var.Value)
80 let (qualifiers, listing) =
82 Nothing -> ([], Var.Listing [] False)
86 Module.As qualifier ->
87 Just (qualifier : qualifiers, listing)
89 Module.Open newListing ->
90 Just (qualifiers, mergeListings newListing listing)
92 mergeListings (Var.Listing explicits1 open1) (Var.Listing explicits2 open2) =
94 (Set.toList (Set.fromList (explicits1 ++ explicits2)))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list