1module AST.Variable where
3import Control.Applicative ((<$>), (<*>))
5import qualified Data.List as List
6import Text.PrettyPrint as P
7import qualified AST.Helpers as Help
13newtype Raw = Raw String
14 deriving (Eq,Ord,Show)
21 deriving (Eq,Ord,Show)
24data Canonical = Canonical
28 deriving (Eq,Ord,Show)
31local :: String -> Canonical
32local x = Canonical Local x
35builtin :: String -> Canonical
36builtin x = Canonical BuiltIn x
39-- VARIABLE RECOGNIZERS
41is :: [String] -> String -> Canonical -> Bool
43 var == Canonical (Module home) name
46isJson :: Canonical -> Bool
48 is ["Json", "Encode"] "Value"
51isMaybe :: Canonical -> Bool
55isArray :: Canonical -> Bool
60isSignal :: Canonical -> Bool
62 is ["Signal"] "Signal"
65isList :: Canonical -> Bool
67 v == Canonical BuiltIn "List"
70isTuple :: Canonical -> Bool
73 Canonical BuiltIn name -> Help.isTuple name
77isPrimitive :: Canonical -> Bool
80 Canonical BuiltIn name -> name `elem` ["Int","Float","String","Bool"]
84isPrim :: String -> Canonical -> Bool
87 Canonical BuiltIn name -> name == prim
91isText :: Canonical -> Bool
99 toString :: a -> String
102instance ToString Raw where
106instance ToString Canonical where
107 toString (Canonical home name) =
110 Module path -> List.intercalate "." (path ++ [name])
116-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
117data Listing a = Listing
120 } deriving (Eq,Ord,Show)
123openListing :: Listing a
128-- | A value that can be imported or exported
132 | ADT !String !(Listing String)
133 deriving (Eq,Ord,Show)
138instance Pretty Raw where
139 pretty (Raw var) = variable var
142instance Pretty Canonical where
143 pretty var = P.text (toString var)
146instance Pretty a => Pretty (Listing a) where
147 pretty (Listing explicits open) =
148 P.parens (commaCat (map pretty explicits ++ dots))
150 dots = [if open then P.text ".." else P.empty]
153instance Pretty Value where
156 Value name -> P.text name
157 Alias name -> P.text name
159 P.text name <> pretty (ctors { _explicits = map P.text (_explicits ctors) })
162-- BINARY SERIALIZATION
164instance Binary Canonical where
165 put (Canonical home name) =
167 BuiltIn -> putWord8 0 >> put name
168 Module path -> putWord8 1 >> put path >> put name
169 Local -> putWord8 2 >> put name
171 get = do tag <- getWord8
173 0 -> Canonical BuiltIn <$> get
174 1 -> Canonical . Module <$> get <*> get
175 2 -> Canonical Local <$> get
176 _ -> error "Unexpected tag when deserializing canonical variable"
179instance Binary Value where
182 Value name -> putWord8 0 >> put name
183 Alias name -> putWord8 1 >> put name
184 ADT name ctors -> putWord8 2 >> put name >> put ctors
186 get = do tag <- getWord8
190 2 -> ADT <$> get <*> get
191 _ -> error "Error reading valid import/export information from serialized string"
194instance (Binary a) => Binary (Listing a) where
195 put (Listing explicits open) =
196 put explicits >> put open
198 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