2module AST.Variable where
5import Control.Applicative ((<$>), (<*>))
6import Text.PrettyPrint as P
9newtype Raw = Raw String
10 deriving (Eq,Ord,Show)
16 deriving (Eq,Ord,Show)
18data Canonical = Canonical
21 } deriving (Eq,Ord,Show)
23local :: String -> Canonical
24local x = Canonical Local x
27 toString :: a -> String
29instance ToString Raw where
32instance ToString Canonical where
33 toString (Canonical home name) =
37 Module path -> path ++ "." ++ name
39-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
40data Listing a = Listing
45openListing :: Listing a
46openListing = Listing [] True
48-- | A value that can be imported or exported
52 | ADT !String !(Listing String)
55instance Pretty Raw where
56 pretty (Raw var) = variable var
58instance Pretty Canonical where
59 pretty var = P.text (toString var)
61instance Pretty a => Pretty (Listing a) where
62 pretty (Listing explicits open) =
63 P.parens (commaCat (map pretty explicits ++ dots))
65 dots = [if open then P.text ".." else P.empty]
67instance Pretty Value where
70 Value name -> P.text name
71 Alias name -> P.text name
73 P.text name <> pretty (ctors { _explicits = map P.text (_explicits ctors) })
75instance Binary Canonical where
76 put (Canonical home name) =
78 Local -> putWord8 0 >> put name
79 BuiltIn -> putWord8 1 >> put name
80 Module path -> putWord8 2 >> put path >> put name
82 get = do tag <- getWord8
84 0 -> Canonical Local <$> get
85 1 -> Canonical BuiltIn <$> get
86 2 -> Canonical . Module <$> get <*> get
87 _ -> error "Unexpected tag when deserializing canonical variable"
89instance Binary Value where
91 let put' n info = putWord8 n >> put info in
93 Value name -> put' 0 name
94 Alias name -> put' 1 name
99 get = do tag <- getWord8
103 2 -> ADT <$> get <*> get
104 _ -> error "Error reading valid import/export information from serialized string"
106instance (Binary a) => Binary (Listing a) where
107 put (Listing explicits open) =
111 get = Listing <$> get <*> get
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