@@ -0,0 +1,119 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
9+import qualified Data.Map as Map
10+import Data.Monoid ((<>))
11+import Data.Text (Text)
12+import qualified Data.Text as Text
14+import qualified AST.Exposing as Exposing
15+import qualified AST.Module as Module
16+import qualified AST.Module.Name as Module
17+import Parse.Helpers (Parser)
18+import qualified Parse.Helpers as Parse
19+import qualified Parse.Module as Parse
20+import qualified Reporting.Annotation as A
29+ | Var Module.Raw Text
32+parse :: Text -> ( [(Module.Raw, Text)], [Chunk] )
34+ case Parse.run parser source of
36+ error "problem parsing kernel code"
46+parser :: Parser ( [(Module.Raw, Text)], [Chunk] )
48+ do imports <- Parse.kernelHeader
49+ let table = Map.unions (map importToTable imports)
50+ chunks <- parserHelp table
51+ return ( Map.elems table, chunks )
54+parserHelp :: Table -> Parser [Chunk]
56+ do chunk <- Parse.kernelChunk
62+ case Map.lookup var table of
64+ error $ show $ "could not find " <> var <> " when parsing kernel code"
67+ do rest <- parserHelp table
68+ return (JS js : Var home name : rest)
76+ Map.Map Text (Module.Raw, Text)
79+importToTable :: Module.UserImport -> Table
80+importToTable (A.A _ ( fullName, Module.ImportMethod maybeAlias exposed )) =
88+ if Module.isKernel fullName then
89+ Module.getKernel fullName
90+ else if Text.isInfixOf "." fullName then
91+ error ("modules with dots in kernel code need an alias: " ++ show fullName)
96+ ( "__" <> shortName <> "_" <> value, ( fullName, value ) )
98+ Map.fromList $ map toEntry $
99+ concatMap entryToValues $ getExplicits exposed
102+getExplicits :: Exposing.Exposing a -> [a]
103+getExplicits exposed =
106+ error "cannot have open imports in kernel code"
108+ Exposing.Explicit entries ->
112+entryToValues :: Exposing.Entry -> [Text]
113+entryToValues entry =
115+ Exposing.Lower name ->
118+ Exposing.Upper name ctors ->
119+ maybe [name] getExplicits ctors