1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module AST.Variable where
6import qualified Data.Maybe as Maybe
7import Data.Monoid ((<>))
8import qualified Data.Set as Set
9import qualified Data.Text as Text
10import Data.Text (Text)
12import qualified AST.Helpers as Help
13import qualified AST.Module.Name as ModuleName
30 | Module ModuleName.Canonical
31 | TopLevel ModuleName.Canonical
36data Canonical = Canonical
43local :: Text -> Canonical
48topLevel :: ModuleName.Canonical -> Text -> Canonical
50 Canonical (TopLevel home) x
53builtin :: Text -> Canonical
58fromModule :: ModuleName.Canonical -> Text -> Canonical
60 Canonical (Module home) name
63localize :: Canonical -> Canonical
64localize var@(Canonical home name) =
73inCore :: ModuleName.Raw -> Text -> Canonical
75 Canonical (Module (ModuleName.inCore home)) name
78inHtml :: ModuleName.Raw -> Text -> Canonical
80 Canonical (Module (ModuleName.inHtml home)) name
85 inCore "Platform.Cmd" "Cmd"
90 inCore "Platform.Sub" "Sub"
94-- VARIABLE RECOGNIZERS
97isLocalHome :: Home -> Bool
113is :: ModuleName.Raw -> Text -> Canonical -> Bool
115 var == inCore home name
118isJson :: Canonical -> Bool
120 is "Json.Encode" "Value"
123isMaybe :: Canonical -> Bool
127isArray :: Canonical -> Bool
132isTask :: Canonical -> Bool
137isList :: Canonical -> Bool
139 v == Canonical BuiltIn "List"
142isNative :: Canonical -> Bool
145 Canonical (Module name) _ ->
146 ModuleName.canonicalIsNative name
152isTuple :: Canonical -> Bool
155 Canonical BuiltIn name ->
162isPrimitive :: Canonical -> Bool
165 Canonical BuiltIn name ->
166 Set.member name primitiveSet
172primitiveSet :: Set.Set Text
174 Set.fromList ["Int","Float","String","Bool"]
177isPrim :: Text -> Canonical -> Bool
178isPrim prim (Canonical home name) =
187isLocal :: (Text -> Bool) -> Canonical -> Bool
188isLocal check (Canonical home name) =
201toString :: (ToText a) => a -> String
203 Text.unpack (toText var)
210instance ToText Raw where
215instance ToText Canonical where
216 toText (Canonical home name) =
222 ModuleName.canonicalToText moduleName <> "." <> name
235-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
244openListing :: Listing a
249closedListing :: Listing a
254listing :: [a] -> Listing a
259-- | A value that can be imported or exported
263 | Union !Text !(Listing Text)
268-- CATEGORIZING VALUES
271getValues :: [Value] -> [Text]
273 Maybe.mapMaybe getValue values
276getValue :: Value -> Maybe Text
279 Value name -> Just name
284getAliases :: [Value] -> [Text]
286 Maybe.mapMaybe getAlias values
289getAlias :: Value -> Maybe Text
293 Alias name -> Just name
297getUnions :: [Value] -> [(Text, Listing Text)]
299 Maybe.mapMaybe getUnion values
302getUnion :: Value -> Maybe (Text, Listing Text)
307 Union name ctors -> Just (name, ctors)
311-- BINARY SERIALIZATION
314instance Binary Canonical where
315 put (Canonical home name) =
318 putWord8 0 >> put name
321 putWord8 1 >> put path >> put name
324 putWord8 2 >> put path >> put name
327 putWord8 3 >> put name
332 0 -> Canonical BuiltIn <$> get
333 1 -> Canonical . Module <$> get <*> get
334 2 -> Canonical . TopLevel <$> get <*> get
335 3 -> Canonical Local <$> get
336 _ -> error "Unexpected tag when deserializing canonical variable"
339instance Binary Value where
343 putWord8 0 >> put name
346 putWord8 1 >> put name
349 putWord8 2 >> put name >> put ctors
356 2 -> Union <$> get <*> get
357 _ -> error "Error reading valid import/export information from serialized string"
360instance (Binary a) => Binary (Listing a) where
361 put (Listing explicits open) =
362 put explicits >> put open
364 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