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
83inWebGL :: ModuleName.Raw -> Text -> Canonical
85 Canonical (Module (ModuleName.inWebGL home)) name
88inLinearAlgebra :: ModuleName.Raw -> Text -> Canonical
89inLinearAlgebra home name =
90 Canonical (Module (ModuleName.inLinearAlgebra home)) name
95 inCore "Platform.Cmd" "Cmd"
100 inCore "Platform.Sub" "Sub"
104-- VARIABLE RECOGNIZERS
107isLocalHome :: Home -> Bool
123is :: ModuleName.Raw -> Text -> Canonical -> Bool
125 var == inCore home name
128isJson :: Canonical -> Bool
130 is "Json.Encode" "Value"
133isMaybe :: Canonical -> Bool
137isArray :: Canonical -> Bool
142isTask :: Canonical -> Bool
147isList :: Canonical -> Bool
149 v == Canonical BuiltIn "List"
152isNative :: Canonical -> Bool
155 Canonical (Module name) _ ->
156 ModuleName.canonicalIsNative name
162isTuple :: Canonical -> Bool
165 Canonical BuiltIn name ->
172isPrimitive :: Canonical -> Bool
175 Canonical BuiltIn name ->
176 Set.member name primitiveSet
182primitiveSet :: Set.Set Text
184 Set.fromList ["Int","Float","String","Bool"]
187isPrim :: Text -> Canonical -> Bool
188isPrim prim (Canonical home name) =
197isLocal :: (Text -> Bool) -> Canonical -> Bool
198isLocal check (Canonical home name) =
211toString :: (ToText a) => a -> String
213 Text.unpack (toText var)
220instance ToText Raw where
225instance ToText Canonical where
226 toText (Canonical home name) =
232 ModuleName.canonicalToText moduleName <> "." <> name
245-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
254openListing :: Listing a
259closedListing :: Listing a
264listing :: [a] -> Listing a
269-- | A value that can be imported or exported
273 | Union !Text !(Listing Text)
278-- CATEGORIZING VALUES
281getValues :: [Value] -> [Text]
283 Maybe.mapMaybe getValue values
286getValue :: Value -> Maybe Text
289 Value name -> Just name
294getAliases :: [Value] -> [Text]
296 Maybe.mapMaybe getAlias values
299getAlias :: Value -> Maybe Text
303 Alias name -> Just name
307getUnions :: [Value] -> [(Text, Listing Text)]
309 Maybe.mapMaybe getUnion values
312getUnion :: Value -> Maybe (Text, Listing Text)
317 Union name ctors -> Just (name, ctors)
321-- BINARY SERIALIZATION
324instance Binary Canonical where
325 put (Canonical home name) =
328 putWord8 0 >> put name
331 putWord8 1 >> put path >> put name
334 putWord8 2 >> put path >> put name
337 putWord8 3 >> put name
342 0 -> Canonical BuiltIn <$> get
343 1 -> Canonical . Module <$> get <*> get
344 2 -> Canonical . TopLevel <$> get <*> get
345 3 -> Canonical Local <$> get
346 _ -> error "Unexpected tag when deserializing canonical variable"
349instance Binary Value where
353 putWord8 0 >> put name
356 putWord8 1 >> put name
359 putWord8 2 >> put name >> put ctors
366 2 -> Union <$> get <*> get
367 _ -> error "Error reading valid import/export information from serialized string"
370instance (Binary a) => Binary (Listing a) where
371 put (Listing explicits open) =
372 put explicits >> put open
374 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