@@ -29,14 +29,37 @@ import qualified Reporting.Error.Syntax as E
2929-- FROM BYTE STRING
3030
3131
32−fromByteString :: Pkg.Name -> BS.ByteString -> Either E.Error Src.Module
33−fromByteString pkg source =
34− case P.fromByteString (chompModule pkg) E.ModuleBadEnd source of
35− Right modul -> checkModule modul
32+fromByteString :: ProjectType -> BS.ByteString -> Either E.Error Src.Module
33+fromByteString projectType source =
34+ case P.fromByteString (chompModule projectType) E.ModuleBadEnd source of
35+ Right modul -> checkModule projectType modul
3636 Left err -> Left (E.ParseError err)
3737
3838
3939
40+-- PROJECT TYPE
41+
42+
43+data ProjectType
44+ = Package Pkg.Name
45+ | Application
46+
47+
48+isCore :: ProjectType -> Bool
49+isCore projectType =
50+ case projectType of
51+ Package pkg -> pkg == Pkg.core
52+ Application -> False
53+
54+
55+isKernel :: ProjectType -> Bool
56+isKernel projectType =
57+ case projectType of
58+ Package pkg -> Pkg.isKernel pkg
59+ Application -> False
60+
61+
62+
4063-- MODULE
4164
4265
@@ -49,11 +72,11 @@ data Module =
4972 }
5073
5174
52−chompModule :: Pkg.Name -> Parser E.Module Module
53−chompModule pkg =
75+chompModule :: ProjectType -> Parser E.Module Module
76+chompModule projectType =
5477 do header <- chompHeader
55− imports <- chompImports (if pkg == Pkg.core then [] else Imports.defaults)
56− infixes <- if Pkg.isKernel pkg then chompInfixes [] else return []
78+ imports <- chompImports (if isCore projectType then [] else Imports.defaults)
79+ infixes <- if isKernel projectType then chompInfixes [] else return []
5780 decls <- specialize E.Declarations $ chompDecls []
5881 return (Module header imports infixes decls)
5982
@@ -62,15 +85,15 @@ chompModule pkg =
6285-- CHECK MODULE
6386
6487
65−checkModule :: Module -> Either E.Error Src.Module
66−checkModule (Module maybeHeader imports infixes decls) =
88+checkModule :: ProjectType -> Module -> Either E.Error Src.Module
89+checkModule projectType (Module maybeHeader imports infixes decls) =
6790 let
6891 (values, unions, aliases, ports) = categorizeDecls [] [] [] [] decls
6992 in
7093 case maybeHeader of
7194 Just (Header name effects exports docs) ->
7295 Src.Module (Just name) exports (toDocs docs decls) imports values unions aliases infixes
73− <$> checkEffects ports effects
96+ <$> checkEffects projectType ports effects
7497
7598 Nothing ->
7699 Right $
@@ -80,23 +103,37 @@ checkModule (Module maybeHeader imports infixes decls) =
80103 _:_ -> Src.Ports ports
81104
82105
83−checkEffects :: [Src.Port] -> Effects -> Either E.Error Src.Effects
84−checkEffects ports effects =
106+checkEffects :: ProjectType -> [Src.Port] -> Effects -> Either E.Error Src.Effects
107+checkEffects projectType ports effects =
85108 case effects of
86109 NoEffects region ->
87110 case ports of
88− [] -> Right Src.NoEffects
89− _:_ -> Left (E.UnexpectedPort region)
111+ [] ->
112+ Right Src.NoEffects
113+
114+ Src.Port name _ : _ ->
115+ case projectType of
116+ Package _ -> Left (E.NoPortsInPackage name)
117+ Application -> Left (E.UnexpectedPort region)
90118
91119 Ports region ->
92− case ports of
93− [] -> Left (E.NoPorts region)
94− _:_ -> Right (Src.Ports ports)
120+ case projectType of
121+ Package _ ->
122+ Left (E.NoPortModulesInPackage region)
123+
124+ Application ->
125+ case ports of
126+ [] -> Left (E.NoPorts region)
127+ _:_ -> Right (Src.Ports ports)
95128
96129 Manager region manager ->
97− case ports of
98− [] -> Right (Src.Manager region manager)
99− _:_ -> Left (E.UnexpectedPort region)
130+ if isKernel projectType then
131+ case ports of
132+ [] -> Right (Src.Manager region manager)
133+ _:_ -> Left (E.UnexpectedPort region)
134+ else
135+ Left (E.NoEffectsOutsideKernel region)
136+
100137
101138
102139categorizeDecls :: [A.Located Src.Value] -> [A.Located Src.Union] -> [A.Located Src.Alias] -> [Src.Port] -> [Decl.Decl] -> ( [A.Located Src.Value], [A.Located Src.Union], [A.Located Src.Alias], [Src.Port] )