1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module AST.Variable where
6import qualified Data.Maybe as Maybe
7import qualified Data.Text as Text
10import qualified AST.Helpers as Help
11import qualified AST.Module.Name as ModuleName
28 | Module ModuleName.Canonical
29 | TopLevel ModuleName.Canonical
34data Canonical = Canonical
41local :: Text -> Canonical
46topLevel :: ModuleName.Canonical -> Text -> Canonical
48 Canonical (TopLevel home) x
51builtin :: Text -> Canonical
56fromModule :: ModuleName.Canonical -> Text -> Canonical
58 Canonical (Module home) name
61localize :: Canonical -> Canonical
62localize var@(Canonical home name) =
71inCore :: ModuleName.Raw -> Text -> Canonical
73 Canonical (Module (ModuleName.inCore home)) name
76inHtml :: ModuleName.Raw -> Text -> Canonical
78 Canonical (Module (ModuleName.inHtml home)) name
81inWebGL :: ModuleName.Raw -> Text -> Canonical
83 Canonical (Module (ModuleName.inWebGL home)) name
86inLinearAlgebra :: ModuleName.Raw -> Text -> Canonical
87inLinearAlgebra home name =
88 Canonical (Module (ModuleName.inLinearAlgebra home)) name
93 inCore "Platform.Cmd" "Cmd"
98 inCore "Platform.Sub" "Sub"
102-- VARIABLE RECOGNIZERS
105isLocalHome :: Home -> Bool
121is :: ModuleName.Raw -> Text -> Canonical -> Bool
123 var == inCore home name
126isJson :: Canonical -> Bool
128 is "Json.Encode" "Value"
131isMaybe :: Canonical -> Bool
135isArray :: Canonical -> Bool
140isTask :: Canonical -> Bool
145isList :: Canonical -> Bool
147 v == Canonical BuiltIn "List"
150isNative :: Canonical -> Bool
153 Canonical (Module name) _ ->
154 ModuleName.canonicalIsNative name
160isTuple :: Canonical -> Bool
163 Canonical BuiltIn name ->
170isPrimitive :: Canonical -> Bool
173 Canonical BuiltIn name ->
174 elem name ["Int","Float","String","Bool"]
180isPrim :: Text -> Canonical -> Bool
181isPrim prim (Canonical home name) =
190isLocal :: (Text -> Bool) -> Canonical -> Bool
191isLocal check (Canonical home name) =
204class ToString a where
205 toString :: a -> String
208instance ToString Raw where
209 toString (Raw name) =
213instance ToString Canonical where
214 toString (Canonical home name) =
220 ModuleName.canonicalToString moduleName ++ "." ++ Text.unpack name
233-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
242openListing :: Listing a
247closedListing :: Listing a
252listing :: [a] -> Listing a
257-- | A value that can be imported or exported
261 | Union !Text !(Listing Text)
266-- CATEGORIZING VALUES
269getValues :: [Value] -> [Text]
271 Maybe.mapMaybe getValue values
274getValue :: Value -> Maybe Text
277 Value name -> Just name
282getAliases :: [Value] -> [Text]
284 Maybe.mapMaybe getAlias values
287getAlias :: Value -> Maybe Text
291 Alias name -> Just name
295getUnions :: [Value] -> [(Text, Listing Text)]
297 Maybe.mapMaybe getUnion values
300getUnion :: Value -> Maybe (Text, Listing Text)
305 Union name ctors -> Just (name, ctors)
309-- BINARY SERIALIZATION
312instance Binary Canonical where
313 put (Canonical home name) =
316 putWord8 0 >> put name
319 putWord8 1 >> put path >> put name
322 putWord8 2 >> put path >> put name
325 putWord8 3 >> put name
330 0 -> Canonical BuiltIn <$> get
331 1 -> Canonical . Module <$> get <*> get
332 2 -> Canonical . TopLevel <$> get <*> get
333 3 -> Canonical Local <$> get
334 _ -> error "Unexpected tag when deserializing canonical variable"
337instance Binary Value where
341 putWord8 0 >> put name
344 putWord8 1 >> put name
347 putWord8 2 >> put name >> put ctors
354 2 -> Union <$> get <*> get
355 _ -> error "Error reading valid import/export information from serialized string"
358instance (Binary a) => Binary (Listing a) where
359 put (Listing explicits open) =
360 put explicits >> put open
362 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