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
61inCore :: ModuleName.Raw -> Text -> Canonical
63 Canonical (Module (ModuleName.inCore home)) name
66inHtml :: ModuleName.Raw -> Text -> Canonical
68 Canonical (Module (ModuleName.inHtml home)) name
71inWebGL :: ModuleName.Raw -> Text -> Canonical
73 Canonical (Module (ModuleName.inWebGL home)) name
76inLinearAlgebra :: ModuleName.Raw -> Text -> Canonical
77inLinearAlgebra home name =
78 Canonical (Module (ModuleName.inLinearAlgebra home)) name
83 inCore "Platform.Cmd" "Cmd"
88 inCore "Platform.Sub" "Sub"
92-- VARIABLE RECOGNIZERS
95isLocalHome :: Home -> Bool
111is :: ModuleName.Raw -> Text -> Canonical -> Bool
113 var == inCore home name
116isJson :: Canonical -> Bool
118 is "Json.Encode" "Value"
121isMaybe :: Canonical -> Bool
125isArray :: Canonical -> Bool
130isTask :: Canonical -> Bool
135isList :: Canonical -> Bool
137 v == Canonical BuiltIn "List"
140isNative :: Canonical -> Bool
143 Canonical (Module name) _ ->
144 ModuleName.canonicalIsNative name
150isTuple :: Canonical -> Bool
153 Canonical BuiltIn name ->
160isPrimitive :: Canonical -> Bool
163 Canonical BuiltIn name ->
164 elem name ["Int","Float","String","Bool"]
170isPrim :: Text -> Canonical -> Bool
171isPrim prim (Canonical home name) =
180isLocal :: (Text -> Bool) -> Canonical -> Bool
181isLocal check (Canonical home name) =
194class ToString a where
195 toString :: a -> String
198instance ToString Raw where
199 toString (Raw name) =
203instance ToString Canonical where
204 toString (Canonical home name) =
210 ModuleName.canonicalToString moduleName ++ "." ++ Text.unpack name
223-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
232openListing :: Listing a
237closedListing :: Listing a
242listing :: [a] -> Listing a
247-- | A value that can be imported or exported
251 | Union !Text !(Listing Text)
256-- CATEGORIZING VALUES
259getValues :: [Value] -> [Text]
261 Maybe.mapMaybe getValue values
264getValue :: Value -> Maybe Text
267 Value name -> Just name
272getAliases :: [Value] -> [Text]
274 Maybe.mapMaybe getAlias values
277getAlias :: Value -> Maybe Text
281 Alias name -> Just name
285getUnions :: [Value] -> [(Text, Listing Text)]
287 Maybe.mapMaybe getUnion values
290getUnion :: Value -> Maybe (Text, Listing Text)
295 Union name ctors -> Just (name, ctors)
299-- BINARY SERIALIZATION
302instance Binary Canonical where
303 put (Canonical home name) =
306 putWord8 0 >> put name
309 putWord8 1 >> put path >> put name
312 putWord8 2 >> put path >> put name
315 putWord8 3 >> put name
320 0 -> Canonical BuiltIn <$> get
321 1 -> Canonical . Module <$> get <*> get
322 2 -> Canonical . TopLevel <$> get <*> get
323 3 -> Canonical Local <$> get
324 _ -> error "Unexpected tag when deserializing canonical variable"
327instance Binary Value where
331 putWord8 0 >> put name
334 putWord8 1 >> put name
337 putWord8 2 >> put name >> put ctors
344 2 -> Union <$> get <*> get
345 _ -> error "Error reading valid import/export information from serialized string"
348instance (Binary a) => Binary (Listing a) where
349 put (Listing explicits open) =
350 put explicits >> put open
352 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