on master help sign in
Add new error reporting to Parse.Module
35a43f4Evan Czaplicki
compiler/src/Parse/Module.hs+214−194
@@ -4,14 +4,12 @@ module Parse.Module
4 ( fromByteString
4 ( fromByteString
5 , Header(..)
5 , Header(..)
6 , Effects(..)
6 , Effects(..)
7− , chompHeader
8 , chompImports
7 , chompImports
9− , freshLine
10 )
8 )
11 where
9 where
12
10
13
11
14−import qualified Data.ByteString as B
12+import qualified Data.ByteString as BS
15import qualified Data.Name as Name
13import qualified Data.Name as Name
16
14
17import qualified AST.Source as Src
15import qualified AST.Source as Src
@@ -19,21 +17,20 @@ import qualified Elm.Compiler.Imports as Imports
19import qualified Elm.Package as Pkg
17import qualified Elm.Package as Pkg
20import qualified Parse.Declaration as Decl
18import qualified Parse.Declaration as Decl
21import qualified Parse.Keyword as Keyword
19import qualified Parse.Keyword as Keyword
20+import qualified Parse.Space as Space
22import qualified Parse.Symbol as Symbol
21import qualified Parse.Symbol as Symbol
23import qualified Parse.Variable as Var
22import qualified Parse.Variable as Var
24import qualified Parse.Primitives as P
23import qualified Parse.Primitives as P
25−import Parse.Primitives hiding (Parser, State, fromByteString)
24+import Parse.Primitives hiding (State, fromByteString)
26−import Parse.Utils
27import qualified Reporting.Annotation as A
25import qualified Reporting.Annotation as A
28import qualified Reporting.Error.Syntax as E
26import qualified Reporting.Error.Syntax as E
29−import qualified Reporting.Result as Result
30
27
31
28
32
29
33-- FROM BYTE STRING
30-- FROM BYTE STRING
34
31
35
32
36−fromByteString :: Pkg.Name -> B.ByteString -> Result.Result i w E.Error Src.Module
33+fromByteString :: Pkg.Name -> BS.ByteString -> Either E.Error Src.Module
37fromByteString pkg source =
34fromByteString pkg source =
38 let
35 let
39 parser
36 parser
@@ -44,80 +41,91 @@ fromByteString pkg source =
44 case P.fromByteString parser source of
41 case P.fromByteString parser source of
45 P.Ok outcome _ ->
42 P.Ok outcome _ ->
46 case outcome of
43 case outcome of
47− Right modul -> Result.ok modul
44+ Right modul -> Right modul
48− Left err -> Result.throw err
45+ Left err -> Left err
49
46
50− P.Err row col ctx err ->
47+ P.Err err ->
51− Result.throw (E.ParseError row col ctx err)
48+ Left (E.ParseError err)
52
49
53
50
54
51
55-- MODULE
52-- MODULE
56
53
57
54
58−normal :: Parser (Either E.Error Src.Module)
55+normal :: Parser E.Module (Either E.Error Src.Module)
59normal =
56normal =
60− do freshLine
57+ do freshLine E.FreshLineModuleStart
61 header <- chompHeader
58 header <- chompHeader
59+ comment <- chompModuleDocComment
62 imports <- chompImports []
60 imports <- chompImports []
63− decls <- chompDecls []
61+ decls <- specialize E.Declarations $ chompDecls []
64 endOfFile
62 endOfFile
65− return (checkModule header (Imports.addDefaults imports) [] decls)
63+ return (checkModule header comment (Imports.addDefaults imports) [] decls)
66
64
67
65
68−core :: Parser (Either E.Error Src.Module)
66+core :: Parser E.Module (Either E.Error Src.Module)
69core =
67core =
70− do freshLine
68+ do freshLine E.FreshLineModuleStart
71 header <- chompHeader
69 header <- chompHeader
70+ comment <- chompModuleDocComment
72 imports <- chompImports []
71 imports <- chompImports []
73 binops <- chompBinops []
72 binops <- chompBinops []
74− decls <- chompDecls []
73+ decls <- specialize E.Declarations $ chompDecls []
75 endOfFile
74 endOfFile
76− return (checkModule header imports binops decls)
75+ return (checkModule header comment imports binops decls)
77
76
78
77
79−platform :: Parser (Either E.Error Src.Module)
78+platform :: Parser E.Module (Either E.Error Src.Module)
80platform =
79platform =
81− do freshLine
80+ do freshLine E.FreshLineModuleStart
82 header <- chompHeader
81 header <- chompHeader
82+ comment <- chompModuleDocComment
83 imports <- chompImports []
83 imports <- chompImports []
84 binops <- chompBinops []
84 binops <- chompBinops []
85− decls <- chompDecls []
85+ decls <- specialize E.Declarations $ chompDecls []
86 endOfFile
86 endOfFile
87− return (checkModule header (Imports.addDefaults imports) binops decls)
87+ return (checkModule header comment (Imports.addDefaults imports) binops decls)
88
88
89
89
90
90
91-- CHECK MODULE
91-- CHECK MODULE
92
92
93
93
94−checkModule :: Maybe Header -> [Src.Import] -> [A.Located Src.Binop] -> [Decl.Decl] -> Either E.Error Src.Module
94+checkModule :: Maybe Header -> Maybe Space.DocComment -> [Src.Import] -> [A.Located Src.Binop] -> [Decl.Decl] -> Either E.Error Src.Module
95−checkModule maybeHeader imports binops decls =
95+checkModule maybeHeader _maybeDocs imports binops decls =
96 let
96 let
97− (Header name effects exports) = maybe (Header "Main" NoEffects (A.At A.one Src.Open)) id maybeHeader
98 (values, unions, aliases, ports) = categorizeDecls [] [] [] [] decls
97 (values, unions, aliases, ports) = categorizeDecls [] [] [] [] decls
99 in
98 in
99+ case maybeHeader of
100+ Just (Header name effects exports) ->
100− Src.Module name exports imports values unions aliases binops
101+ Src.Module (Just name) exports imports values unions aliases binops
101− <$> checkEffects ports effects
102+ <$> checkEffects ports effects
103+
104+ Nothing ->
105+ Right $
106+ Src.Module Nothing (A.At A.one Src.Open) imports values unions aliases binops $
107+ case ports of
108+ [] -> Src.NoEffects
109+ _:_ -> Src.Ports ports
102
110
103
111
104checkEffects :: [Src.Port] -> Effects -> Either E.Error Src.Effects
112checkEffects :: [Src.Port] -> Effects -> Either E.Error Src.Effects
105checkEffects ports effects =
113checkEffects ports effects =
106 case effects of
114 case effects of
107− NoEffects ->
115+ NoEffects region ->
108 case ports of
116 case ports of
109 [] -> Right Src.NoEffects
117 [] -> Right Src.NoEffects
110− _:_ -> Left (error "TODO no ports")
118+ _:_ -> Left (E.UnexpectedPort region)
111
119
112 Ports region ->
120 Ports region ->
113 case ports of
121 case ports of
114− [] -> Left (error "TODO no ports in port module" region)
122+ [] -> Left (E.NoPorts region)
115 _:_ -> Right (Src.Ports ports)
123 _:_ -> Right (Src.Ports ports)
116
124
117 Manager region manager ->
125 Manager region manager ->
118 case ports of
126 case ports of
119 [] -> Right (Src.Manager region manager)
127 [] -> Right (Src.Manager region manager)
120− _:_ -> Left (error "TODO ports in effect manager")
128+ _:_ -> Left (E.UnexpectedPort region)
121
129
122
130
123categorizeDecls :: [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] )
131categorizeDecls :: [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] )
@@ -128,26 +136,27 @@ categorizeDecls values unions aliases ports decls =
128
136
129 decl:otherDecls ->
137 decl:otherDecls ->
130 case decl of
138 case decl of
131− Decl.Value value -> categorizeDecls (value:values) unions aliases ports otherDecls
139+ Decl.Value _ value -> categorizeDecls (value:values) unions aliases ports otherDecls
132− Decl.Union union -> categorizeDecls values (union:unions) aliases ports otherDecls
140+ Decl.Union _ union -> categorizeDecls values (union:unions) aliases ports otherDecls
133− Decl.Alias alias -> categorizeDecls values unions (alias:aliases) ports otherDecls
141+ Decl.Alias _ alias -> categorizeDecls values unions (alias:aliases) ports otherDecls
134− Decl.Port port_ -> categorizeDecls values unions aliases (port_:ports) otherDecls
142+ Decl.Port _ port_ -> categorizeDecls values unions aliases (port_:ports) otherDecls
135
143
136
144
137
145
138-- FRESH LINES
146-- FRESH LINES
139
147
140
148
141−freshLine :: Parser ()
149+freshLine :: (Row -> Col -> E.Module) -> Parser E.Module ()
142−freshLine =
150+freshLine toFreshLineError =
151+ do Space.chomp E.ModuleSpace
143− checkFreshLine =<< whitespace
152+ Space.checkFreshLine toFreshLineError
144
153
145
154
146−endOfFile :: Parser ()
155+endOfFile :: Parser E.Module ()
147endOfFile =
156endOfFile =
148− P.Parser $ \state@(P.State pos end _ row col ctx) _ eok _ eerr ->
157+ P.Parser $ \state@(P.State pos end _ row col) _ eok _ eerr ->
149 if pos < end then
158 if pos < end then
150− eerr row col ctx E.EndOfFile
159+ eerr row col E.ModuleEndOfFile
151 else
160 else
152 eok () state
161 eok () state
153
162
@@ -156,23 +165,39 @@ endOfFile =
156-- CHOMP DECLARATIONS
165-- CHOMP DECLARATIONS
157
166
158
167
159−chompDecls :: [Decl.Decl] -> Parser [Decl.Decl]
168+chompDecls :: [Decl.Decl] -> Parser E.Decl [Decl.Decl]
160chompDecls decls =
169chompDecls decls =
161− do (decl, _, pos) <- Decl.declaration
170+ do (decl, _) <- Decl.declaration
162− oneOf E.XXX
171+ oneOfWithFallback
163− [ do checkFreshLine pos
172+ [ do Space.checkFreshLine E.DeclFreshLineStart
164 chompDecls (decl:decls)
173 chompDecls (decl:decls)
165− , return (reverse (decl:decls))
166 ]
174 ]
175+ (reverse (decl:decls))
167
176
168
177
169−chompBinops :: [A.Located Src.Binop] -> Parser [A.Located Src.Binop]
178+chompBinops :: [A.Located Src.Binop] -> Parser E.Module [A.Located Src.Binop]
170chompBinops binops =
179chompBinops binops =
171− oneOf E.XXX
180+ oneOfWithFallback
172 [ do binop <- Decl.infix_
181 [ do binop <- Decl.infix_
173 chompBinops (binop:binops)
182 chompBinops (binop:binops)
174− , return binops
175 ]
183 ]
184+ binops
185+
186+
187+
188+-- MODULE DOC COMMENT
189+
190+
191+chompModuleDocComment :: Parser E.Module (Maybe Space.DocComment)
192+chompModuleDocComment =
193+ oneOfWithFallback
194+ [
195+ do docComment <- Space.docComment E.ImportStart E.ModuleSpace
196+ Space.chomp E.ModuleSpace
197+ Space.checkFreshLine E.FreshLineAfterDocComment
198+ return (Just docComment)
199+ ]
200+ Nothing
176
201
177
202
178
203
@@ -184,175 +209,170 @@ data Header =
184
209
185
210
186data Effects
211data Effects
187− = NoEffects
212+ = NoEffects A.Region
188 | Ports A.Region
213 | Ports A.Region
189 | Manager A.Region Src.Manager
214 | Manager A.Region Src.Manager
190
215
191
216
192−chompHeader :: Parser (Maybe Header)
217+chompHeader :: Parser E.Module (Maybe Header)
193chompHeader =
218chompHeader =
194 do start <- getPosition
219 do start <- getPosition
195− oneOf E.XXX
220+ oneOfWithFallback
196 [
221 [
197 -- module MyThing exposing (..)
222 -- module MyThing exposing (..)
198− do Keyword.module_
223+ do Keyword.module_ E.Module
199− pushContext start E.Module
224+ end <- getPosition
200− spaces
225+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
201− name <- Var.moduleName
226+ name <- Var.moduleName E.ModuleName
202− spaces
227+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
203− Keyword.exposing_
228+ Keyword.exposing_ E.ModuleExposing
204− spaces
229+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
205− exports <- addLocation exposing
230+ exports <- addLocation (specialize E.ModuleExposingList exposing)
206− popContext ()
207− freshLine
231+ freshLine E.FreshLineAfterModuleLine
208− return (Just (Header name NoEffects exports))
232+ return (Just (Header name (NoEffects (A.Region start end)) exports))
209 ,
233 ,
210 -- port module MyThing exposing (..)
234 -- port module MyThing exposing (..)
211− do Keyword.port_
235+ do Keyword.port_ E.Module
212− pushContext start E.Module
236+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentPortModule
213− spaces
214− Keyword.module_
237+ Keyword.module_ E.ModulePortModule
215 end <- getPosition
238 end <- getPosition
216− spaces
239+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
217− name <- Var.moduleName
240+ name <- Var.moduleName E.ModuleName
218− spaces
241+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
219− Keyword.exposing_
242+ Keyword.exposing_ E.ModuleExposing
220− spaces
243+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
221− exports <- addLocation exposing
244+ exports <- addLocation (specialize E.ModuleExposingList exposing)
222− popContext ()
223− freshLine
245+ freshLine E.FreshLineAfterModuleLine
224 return (Just (Header name (Ports (A.Region start end)) exports))
246 return (Just (Header name (Ports (A.Region start end)) exports))
225 ,
247 ,
226 -- effect module MyThing where { command = MyCmd } exposing (..)
248 -- effect module MyThing where { command = MyCmd } exposing (..)
227− do Keyword.effect_
249+ do Keyword.effect_ E.Module
228− pushContext start E.Module
250+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
229− spaces
230− Keyword.module_
251+ Keyword.module_ E.ModuleEffect
231 end <- getPosition
252 end <- getPosition
232− spaces
253+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
233− name <- Var.moduleName
254+ name <- Var.moduleName E.ModuleName
234− spaces
255+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
235− Keyword.where_
256+ Keyword.where_ E.ModuleEffect
236− spaces
257+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
237 manager <- chompManager
258 manager <- chompManager
238− spaces
259+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
239− Keyword.exposing_
260+ Keyword.exposing_ E.ModuleExposing
240− spaces
261+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
241− exports <- addLocation exposing
262+ exports <- addLocation (specialize E.ModuleExposingList exposing)
242− popContext ()
243− freshLine
263+ freshLine E.FreshLineAfterModuleLine
244 return (Just (Header name (Manager (A.Region start end) manager) exports))
264 return (Just (Header name (Manager (A.Region start end) manager) exports))
245− ,
246− -- default header
247− return Nothing
248 ]
265 ]
266+ -- default header
267+ Nothing
249
268
250
269
251−chompManager :: Parser Src.Manager
270+chompManager :: Parser E.Module Src.Manager
252chompManager =
271chompManager =
253− do word1 0x7B {- { -} E.XXX
272+ do word1 0x7B {- { -} E.ModuleEffect
254− spaces
273+ spaces_em
255− oneOf E.XXX
274+ oneOf E.ModuleEffect
256 [ do cmd <- chompCommand
275 [ do cmd <- chompCommand
257− spaces
276+ spaces_em
258− oneOf E.XXX
277+ oneOf E.ModuleEffect
259− [ do word1 0x7D {-}-} E.XXX
278+ [ do word1 0x7D {-}-} E.ModuleEffect
260− spaces
279+ spaces_em
261 return (Src.Cmd cmd)
280 return (Src.Cmd cmd)
262− , do word1 0x2C {-,-} E.XXX
281+ , do word1 0x2C {-,-} E.ModuleEffect
263− spaces
282+ spaces_em
264 sub <- chompSubscription
283 sub <- chompSubscription
265− spaces
284+ spaces_em
266− word1 0x7D {-}-} E.XXX
285+ word1 0x7D {-}-} E.ModuleEffect
267− spaces
286+ spaces_em
268 return (Src.Fx cmd sub)
287 return (Src.Fx cmd sub)
269 ]
288 ]
270 , do sub <- chompSubscription
289 , do sub <- chompSubscription
271− spaces
290+ spaces_em
272− oneOf E.XXX
291+ oneOf E.ModuleEffect
273− [ do word1 0x7D {-}-} E.XXX
292+ [ do word1 0x7D {-}-} E.ModuleEffect
274− spaces
293+ spaces_em
275 return (Src.Sub sub)
294 return (Src.Sub sub)
276− , do word1 0x2C {-,-} E.XXX
295+ , do word1 0x2C {-,-} E.ModuleEffect
277− spaces
296+ spaces_em
278 cmd <- chompCommand
297 cmd <- chompCommand
279− spaces
298+ spaces_em
280− word1 0x7D {-}-} E.XXX
299+ word1 0x7D {-}-} E.ModuleEffect
281− spaces
300+ spaces_em
282 return (Src.Fx cmd sub)
301 return (Src.Fx cmd sub)
283 ]
302 ]
284 ]
303 ]
285
304
286
305
287−chompCommand :: Parser (A.Located Name.Name)
306+chompCommand :: Parser E.Module (A.Located Name.Name)
288chompCommand =
307chompCommand =
289− do Keyword.command_
308+ do Keyword.command_ E.ModuleEffect
290− spaces
309+ spaces_em
291− word1 0x3D {-=-} E.XXX
310+ word1 0x3D {-=-} E.ModuleEffect
292− spaces
311+ spaces_em
293− addLocation Var.upper
312+ addLocation (Var.upper E.ModuleEffect)
294
313
295
314
296−chompSubscription :: Parser (A.Located Name.Name)
315+chompSubscription :: Parser E.Module (A.Located Name.Name)
297chompSubscription =
316chompSubscription =
298− do Keyword.subscription_
317+ do Keyword.subscription_ E.ModuleEffect
299− spaces
318+ spaces_em
300− word1 0x3D {-=-} E.XXX
319+ word1 0x3D {-=-} E.ModuleEffect
301− spaces
320+ spaces_em
302− addLocation Var.upper
321+ addLocation (Var.upper E.ModuleEffect)
322+
323+
324+spaces_em :: Parser E.Module ()
325+spaces_em =
326+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
303
327
304
328
305
329
306-- IMPORTS
330-- IMPORTS
307
331
308
332
309−chompImports :: [Src.Import] -> Parser [Src.Import]
333+chompImports :: [Src.Import] -> Parser E.Module [Src.Import]
310chompImports imports =
334chompImports imports =
311− oneOf E.XXX
335+ oneOfWithFallback
312− [ do start <- getPosition
313− Keyword.import_
336+ [ do Keyword.import_ E.ImportStart
314− pushContext start E.Import
337+ Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentName
315− spaces
316− name <- addLocation Var.moduleName
338+ name@(A.At (A.Region _ end) _) <- addLocation (Var.moduleName E.ImportName)
317− pos <- whitespace
339+ Space.chomp E.ModuleSpace
318− oneOf E.XXX
340+ oneOf E.ImportEnd
319− [ do checkFreshLine pos
341+ [ do Space.checkFreshLine E.ImportEnd
320− popContext ()
321 chompImports $
342 chompImports $
322 Src.Import name Nothing (Src.Explicit []) : imports
343 Src.Import name Nothing (Src.Explicit []) : imports
323− , do checkSpace pos
344+ , do Space.checkIndent end E.ImportIndentAs
324− oneOf E.XXX
345+ oneOf E.ImportAs
325 [ chompAs name imports
346 [ chompAs name imports
326 , chompExposing name Nothing imports
347 , chompExposing name Nothing imports
327 ]
348 ]
328 ]
349 ]
329− , return (reverse imports)
330 ]
350 ]
351+ (reverse imports)
331
352
332
353
333−chompAs :: A.Located Name.Name -> [Src.Import] -> Parser [Src.Import]
354+chompAs :: A.Located Name.Name -> [Src.Import] -> Parser E.Module [Src.Import]
334chompAs name imports =
355chompAs name imports =
335− do Keyword.as_
356+ do Keyword.as_ E.ImportAs
336− spaces
357+ Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentAlias
337− alias <- Var.upper
358+ alias <- Var.upper E.ImportAlias
338− pos <- whitespace
359+ end <- getPosition
360+ Space.chomp E.ModuleSpace
339− oneOf E.XXX
361+ oneOf E.ImportEnd
340− [ do checkFreshLine pos
362+ [ do Space.checkFreshLine E.ImportEnd
341− popContext ()
342 chompImports $
363 chompImports $
343 Src.Import name (Just alias) (Src.Explicit []) : imports
364 Src.Import name (Just alias) (Src.Explicit []) : imports
344− , do checkSpace pos
365+ , do Space.checkIndent end E.ImportIndentExposing
345 chompExposing name (Just alias) imports
366 chompExposing name (Just alias) imports
346 ]
367 ]
347
368
348
369
349−chompExposing :: A.Located Name.Name -> Maybe Name.Name -> [Src.Import] -> Parser [Src.Import]
370+chompExposing :: A.Located Name.Name -> Maybe Name.Name -> [Src.Import] -> Parser E.Module [Src.Import]
350chompExposing name maybeAlias imports =
371chompExposing name maybeAlias imports =
351− do Keyword.exposing_
372+ do Keyword.exposing_ E.ImportExposing
352− spaces
373+ Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentExposingList
353− exposed <- exposing
374+ exposed <- specialize E.ImportExposingList exposing
354− freshLine
375+ freshLine E.ImportEnd
355− popContext ()
356 chompImports $
376 chompImports $
357 Src.Import name maybeAlias exposed : imports
377 Src.Import name maybeAlias exposed : imports
358
378
@@ -361,56 +381,56 @@ chompExposing name maybeAlias imports =
361-- LISTING
381-- LISTING
362
382
363
383
364−exposing :: Parser Src.Exposing
384+exposing :: Parser E.Exposing Src.Exposing
365exposing =
385exposing =
366− do word1 0x28 {-(-} E.XXX
386+ do word1 0x28 {-(-} E.ExposingStart
367− spaces
387+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentValue
368− oneOf E.XXX
388+ oneOf E.ExposingIndentValue
369− [ do word2 0x2E 0x2E {-..-} E.XXX
389+ [ do word2 0x2E 0x2E {-..-} E.ExposingIndentValue
370− spaces
390+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
371− word1 0x29 {-)-} E.XXX
391+ word1 0x29 {-)-} E.ExposingEnd
372 return Src.Open
392 return Src.Open
373− , do entry <- addLocation chompEntry
393+ , do exposed <- addLocation chompExposed
374− spaces
394+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
375− exposingHelp [entry]
395+ exposingHelp [exposed]
376 ]
396 ]
377
397
378
398
379−exposingHelp :: [A.Located Src.Exposed] -> Parser Src.Exposing
399+exposingHelp :: [A.Located Src.Exposed] -> Parser E.Exposing Src.Exposing
380−exposingHelp revEntries =
400+exposingHelp revExposed =
381− oneOf E.XXX
401+ oneOf E.ExposingEnd
382− [ do word1 0x2C {-,-} E.XXX
402+ [ do word1 0x2C {-,-} E.ExposingEnd
383− spaces
403+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentValue
384− entry <- addLocation chompEntry
404+ exposed <- addLocation chompExposed
385− spaces
405+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentValueEnd
386− exposingHelp (entry:revEntries)
406+ exposingHelp (exposed:revExposed)
387− , do word1 0x29 {-)-} E.XXX
407+ , do word1 0x29 {-)-} E.ExposingEnd
388− return (Src.Explicit (reverse revEntries))
408+ return (Src.Explicit (reverse revExposed))
389 ]
409 ]
390
410
391
411
392−chompEntry :: Parser Src.Exposed
412+chompExposed :: Parser E.Exposing Src.Exposed
393−chompEntry =
413+chompExposed =
394− oneOf E.XXX
414+ oneOf E.ExposingValue
395− [ Src.Lower <$> Var.lower
415+ [ Src.Lower <$> Var.lower E.ExposingValue
396− , do word1 0x28 {-(-} E.XXX
416+ , do word1 0x28 {-(-} E.ExposingValue
397− op <- Symbol.binop
417+ op <- Symbol.operator E.ExposingOperator E.ExposingOperatorReserved
398− word1 0x29 {-)-} E.XXX
418+ word1 0x29 {-)-} E.ExposingOperatorRightParen
399 return (Src.Operator op)
419 return (Src.Operator op)
400− , do name <- Var.upper
420+ , do name <- Var.upper E.ExposingValue
401− spaces
421+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentTypePrivacy
402 Src.Upper name <$> privacy
422 Src.Upper name <$> privacy
403 ]
423 ]
404
424
405
425
406−privacy :: Parser Src.Privacy
426+privacy :: Parser E.Exposing Src.Privacy
407privacy =
427privacy =
408− oneOf E.XXX
428+ oneOfWithFallback
409− [ do word1 0x28 {-(-} E.XXX
429+ [ do word1 0x28 {-(-} E.ExposingTypePrivacy
410− spaces
430+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentTypePrivacyDots
411− word2 0x2E 0x2E {-..-} E.XXX
431+ word2 0x2E 0x2E {-..-} E.ExposingTypePrivacyDots
412− spaces
432+ Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentTypePrivacyEnd
413− word1 0x29 {-)-} E.XXX
433+ word1 0x29 {-)-} E.ExposingTypePrivacyEnd
414 return Src.Public
434 return Src.Public
415− , return Src.Private
416 ]
435 ]
436+ Src.Private
compiler/src/Reporting/Error/Syntax.hs+65−5
@@ -4,6 +4,8 @@ module Reporting.Error.Syntax
4 ( Error(..)
4 ( Error(..)
5 --
5 --
6 , Module(..)
6 , Module(..)
7+ , Exposing(..)
8+ --
7 , Decl(..)
9 , Decl(..)
8 , DeclType(..)
10 , DeclType(..)
9 , TypeAlias(..)
11 , TypeAlias(..)
@@ -65,7 +67,7 @@ data Error
65 = CommentOnNothing A.Region
67 = CommentOnNothing A.Region
66 | UnexpectedPort A.Region
68 | UnexpectedPort A.Region
67 | NoPorts A.Region
69 | NoPorts A.Region
68− | ParseError Decl
70+ | ParseError Module
69
71
70
72
71
73
@@ -73,13 +75,66 @@ data Error
73
75
74
76
75data Module
77data Module
76− = Module Row Col
77− | ModuleSpace Space Row Col
78+ = ModuleSpace Space Row Col
78− | Import Row Col
79+ | ModuleEndOfFile Row Col
80+ | Module Row Col
81+ | ModuleName Row Col
82+ | ModuleExposing Row Col
83+ | ModuleExposingList Exposing Row Col
84+ --
85+ | ModulePortModule Row Col
86+ | ModuleEffect Row Col
87+ --
88+ | ModuleIndentStart Row Col
89+ | ModuleIndentName Row Col
90+ | ModuleIndentExposing Row Col
91+ | ModuleIndentExposingList Row Col
92+ | ModuleIndentPortModule Row Col
93+ --
94+ | FreshLineModuleStart Row Col
95+ | FreshLineAfterModuleLine Row Col
96+ | FreshLineAfterDocComment Row Col
97+ --
98+ | ImportStart Row Col
99+ | ImportName Row Col
100+ | ImportAs Row Col
101+ | ImportAlias Row Col
102+ | ImportExposing Row Col
103+ | ImportExposingList Exposing Row Col
104+ | ImportEnd Row Col -- different based on col=1 or if greater
105+ --
106+ | ImportIndentName Row Col
107+ | ImportIndentAs Row Col
108+ | ImportIndentAlias Row Col
109+ | ImportIndentExposing Row Col
110+ | ImportIndentExposingList Row Col
111+ --
79 | Infix Row Col
112 | Infix Row Col
113+ --
80 | Declarations Decl Row Col
114 | Declarations Decl Row Col
81
115
82
116
117+data Exposing
118+ = ExposingSpace Space Row Col
119+ | ExposingStart Row Col
120+ | ExposingValue Row Col
121+ | ExposingOperator Row Col
122+ | ExposingOperatorReserved Operator Row Col
123+ | ExposingOperatorRightParen Row Col
124+ | ExposingEnd Row Col
125+ --
126+ | ExposingTypePrivacy Row Col
127+ | ExposingTypePrivacyDots Row Col
128+ | ExposingTypePrivacyEnd Row Col
129+ --
130+ | ExposingIndentEnd Row Col
131+ | ExposingIndentValue Row Col
132+ | ExposingIndentValueEnd Row Col
133+ | ExposingIndentTypePrivacy Row Col
134+ | ExposingIndentTypePrivacyDots Row Col
135+ | ExposingIndentTypePrivacyEnd Row Col
136+
137+
83
138
84-- DECLARATIONS
139-- DECLARATIONS
85
140
@@ -91,20 +146,25 @@ data Decl
91 | Port Port Row Col
146 | Port Port Row Col
92 | DeclType DeclType Row Col
147 | DeclType DeclType Row Col
93 | DeclDef Name.Name DeclDef Row Col
148 | DeclDef Name.Name DeclDef Row Col
149+ --
150+ | DeclFreshLineStart Row Col
151+ | DeclFreshLineAfterDocComment Row Col
94
152
95
153
96data DeclDef
154data DeclDef
97 = DeclDefSpace Space Row Col
155 = DeclDefSpace Space Row Col
98 | DeclDefEquals Row Col
156 | DeclDefEquals Row Col
99 | DeclDefType Type Row Col
157 | DeclDefType Type Row Col
100− | DeclDefAlignment Row Col
101 | DeclDefArg Pattern Row Col
158 | DeclDefArg Pattern Row Col
102 | DeclDefBody Expr Row Col
159 | DeclDefBody Expr Row Col
103 | DeclDefNameRepeat Name.Name Row Col
160 | DeclDefNameRepeat Name.Name Row Col
104 | DeclDefNameMatch Name.Name Name.Name Row Col
161 | DeclDefNameMatch Name.Name Name.Name Row Col
162+ --
105 | DeclDefIndentType Row Col
163 | DeclDefIndentType Row Col
106 | DeclDefIndentEquals Row Col
164 | DeclDefIndentEquals Row Col
107 | DeclDefIndentBody Row Col
165 | DeclDefIndentBody Row Col
166+ --
167+ | DeclDefFreshLineAfterType Row Col
108
168
109
169
110data Port
170data Port