on master help sign in
Fill in the module declaration parse errors / have fewer of them
641c8c9Evan Czaplicki
compiler/src/Parse/Module.hs+43−43
@@ -220,46 +220,46 @@ chompHeader =
220 oneOfWithFallback
220 oneOfWithFallback
221 [
221 [
222 -- module MyThing exposing (..)
222 -- module MyThing exposing (..)
223− do Keyword.module_ E.Module
223+ do Keyword.module_ E.ModuleProblem
224 end <- getPosition
224 end <- getPosition
225− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
225+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
226 name <- addLocation (Var.moduleName E.ModuleName)
226 name <- addLocation (Var.moduleName E.ModuleName)
227− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
227+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
228− Keyword.exposing_ E.ModuleExposing
228+ Keyword.exposing_ E.ModuleProblem
229− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
229+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
230− exports <- addLocation (specialize E.ModuleExposingList exposing)
230+ exports <- addLocation (specialize E.ModuleExposing exposing)
231 freshLine E.FreshLineAfterModuleLine
231 freshLine E.FreshLineAfterModuleLine
232 return (Just (Header name (NoEffects (A.Region start end)) exports))
232 return (Just (Header name (NoEffects (A.Region start end)) exports))
233 ,
233 ,
234 -- port module MyThing exposing (..)
234 -- port module MyThing exposing (..)
235− do Keyword.port_ E.Module
235+ do Keyword.port_ E.PortModuleProblem
236− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentPortModule
236+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
237− Keyword.module_ E.ModulePortModule
237+ Keyword.module_ E.PortModuleProblem
238 end <- getPosition
238 end <- getPosition
239− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
239+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
240− name <- addLocation (Var.moduleName E.ModuleName)
240+ name <- addLocation (Var.moduleName E.PortModuleName)
241− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
241+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
242− Keyword.exposing_ E.ModuleExposing
242+ Keyword.exposing_ E.PortModuleProblem
243− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
243+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
244− exports <- addLocation (specialize E.ModuleExposingList exposing)
244+ exports <- addLocation (specialize E.PortModuleExposing exposing)
245 freshLine E.FreshLineAfterModuleLine
245 freshLine E.FreshLineAfterModuleLine
246 return (Just (Header name (Ports (A.Region start end)) exports))
246 return (Just (Header name (Ports (A.Region start end)) exports))
247 ,
247 ,
248 -- effect module MyThing where { command = MyCmd } exposing (..)
248 -- effect module MyThing where { command = MyCmd } exposing (..)
249− do Keyword.effect_ E.Module
249+ do Keyword.effect_ E.Effect
250− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
250+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
251− Keyword.module_ E.ModuleEffect
251+ Keyword.module_ E.Effect
252 end <- getPosition
252 end <- getPosition
253− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
253+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
254 name <- addLocation (Var.moduleName E.ModuleName)
254 name <- addLocation (Var.moduleName E.ModuleName)
255− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
255+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
256− Keyword.where_ E.ModuleEffect
256+ Keyword.where_ E.Effect
257− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
257+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
258 manager <- chompManager
258 manager <- chompManager
259− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
259+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
260− Keyword.exposing_ E.ModuleExposing
260+ Keyword.exposing_ E.Effect
261− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
261+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
262− exports <- addLocation (specialize E.ModuleExposingList exposing)
262+ exports <- addLocation (specialize (const E.Effect) exposing)
263 freshLine E.FreshLineAfterModuleLine
263 freshLine E.FreshLineAfterModuleLine
264 return (Just (Header name (Manager (A.Region start end) manager) exports))
264 return (Just (Header name (Manager (A.Region start end) manager) exports))
265 ]
265 ]
@@ -269,34 +269,34 @@ chompHeader =
269
269
270chompManager :: Parser E.Module Src.Manager
270chompManager :: Parser E.Module Src.Manager
271chompManager =
271chompManager =
272− do word1 0x7B {- { -} E.ModuleEffect
272+ do word1 0x7B {- { -} E.Effect
273 spaces_em
273 spaces_em
274− oneOf E.ModuleEffect
274+ oneOf E.Effect
275 [ do cmd <- chompCommand
275 [ do cmd <- chompCommand
276 spaces_em
276 spaces_em
277− oneOf E.ModuleEffect
277+ oneOf E.Effect
278− [ do word1 0x7D {-}-} E.ModuleEffect
278+ [ do word1 0x7D {-}-} E.Effect
279 spaces_em
279 spaces_em
280 return (Src.Cmd cmd)
280 return (Src.Cmd cmd)
281− , do word1 0x2C {-,-} E.ModuleEffect
281+ , do word1 0x2C {-,-} E.Effect
282 spaces_em
282 spaces_em
283 sub <- chompSubscription
283 sub <- chompSubscription
284 spaces_em
284 spaces_em
285− word1 0x7D {-}-} E.ModuleEffect
285+ word1 0x7D {-}-} E.Effect
286 spaces_em
286 spaces_em
287 return (Src.Fx cmd sub)
287 return (Src.Fx cmd sub)
288 ]
288 ]
289 , do sub <- chompSubscription
289 , do sub <- chompSubscription
290 spaces_em
290 spaces_em
291− oneOf E.ModuleEffect
291+ oneOf E.Effect
292− [ do word1 0x7D {-}-} E.ModuleEffect
292+ [ do word1 0x7D {-}-} E.Effect
293 spaces_em
293 spaces_em
294 return (Src.Sub sub)
294 return (Src.Sub sub)
295− , do word1 0x2C {-,-} E.ModuleEffect
295+ , do word1 0x2C {-,-} E.Effect
296 spaces_em
296 spaces_em
297 cmd <- chompCommand
297 cmd <- chompCommand
298 spaces_em
298 spaces_em
299− word1 0x7D {-}-} E.ModuleEffect
299+ word1 0x7D {-}-} E.Effect
300 spaces_em
300 spaces_em
301 return (Src.Fx cmd sub)
301 return (Src.Fx cmd sub)
302 ]
302 ]
@@ -305,25 +305,25 @@ chompManager =
305
305
306chompCommand :: Parser E.Module (A.Located Name.Name)
306chompCommand :: Parser E.Module (A.Located Name.Name)
307chompCommand =
307chompCommand =
308− do Keyword.command_ E.ModuleEffect
308+ do Keyword.command_ E.Effect
309 spaces_em
309 spaces_em
310− word1 0x3D {-=-} E.ModuleEffect
310+ word1 0x3D {-=-} E.Effect
311 spaces_em
311 spaces_em
312− addLocation (Var.upper E.ModuleEffect)
312+ addLocation (Var.upper E.Effect)
313
313
314
314
315chompSubscription :: Parser E.Module (A.Located Name.Name)
315chompSubscription :: Parser E.Module (A.Located Name.Name)
316chompSubscription =
316chompSubscription =
317− do Keyword.subscription_ E.ModuleEffect
317+ do Keyword.subscription_ E.Effect
318 spaces_em
318 spaces_em
319− word1 0x3D {-=-} E.ModuleEffect
319+ word1 0x3D {-=-} E.Effect
320 spaces_em
320 spaces_em
321− addLocation (Var.upper E.ModuleEffect)
321+ addLocation (Var.upper E.Effect)
322
322
323
323
324spaces_em :: Parser E.Module ()
324spaces_em :: Parser E.Module ()
325spaces_em =
325spaces_em =
326− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
326+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
327
327
328
328
329
329
compiler/src/Reporting/Error/Syntax.hs+112−35
@@ -78,19 +78,16 @@ data Error
78data Module
78data Module
79 = ModuleSpace Space Row Col
79 = ModuleSpace Space Row Col
80 | ModuleEndOfFile Row Col
80 | ModuleEndOfFile Row Col
81− | Module Row Col
81+ --
82+ | ModuleProblem Row Col
82 | ModuleName Row Col
83 | ModuleName Row Col
83− | ModuleExposing Row Col
84+ | ModuleExposing Exposing Row Col
84− | ModuleExposingList Exposing Row Col
85 --
85 --
86− | ModulePortModule Row Col
86+ | PortModuleProblem Row Col
87− | ModuleEffect Row Col
87+ | PortModuleName Row Col
88+ | PortModuleExposing Exposing Row Col
88 --
89 --
89− | ModuleIndentStart Row Col
90+ | Effect Row Col
90− | ModuleIndentName Row Col
91− | ModuleIndentExposing Row Col
92− | ModuleIndentExposingList Row Col
93− | ModuleIndentPortModule Row Col
94 --
91 --
95 | FreshLineModuleStart Row Col
92 | FreshLineModuleStart Row Col
96 | FreshLineAfterModuleLine Row Col
93 | FreshLineAfterModuleLine Row Col
@@ -577,38 +574,118 @@ toParseErrorReport source modul =
577 \ left to see, so whatever I am running into is confusing me a lot!"
574 \ left to see, so whatever I am running into is confusing me a lot!"
578 )
575 )
579
576
580− Module row col ->
577+ ModuleProblem row col ->
581− error "TODO Module" row col
578+ let
579+ region = toRegion row col
580+ in
581+ Report.Report "UNFINISHED MODULE DECLARATION" region [] $
582+ Code.toSnippet source region Nothing
583+ (
584+ D.reflow $
585+ "I am parsing an `module` declaration, but I got stuck here:"
586+ ,
587+ D.stack
588+ [ D.reflow $
589+ "Here are some examples of valid `module` declarations:"
590+ , D.indent 4 $ D.vcat $
591+ [ D.fillSep [D.blue "module","Main",D.blue "exposing","(..)"]
592+ , D.fillSep [D.blue "module","Dict",D.blue "exposing","(Dict, empty, get)"]
593+ ]
594+ , D.reflow $
595+ "I generally recommend using an explicit exposing list. I can skip compiling a bunch\
596+ \ of files when the public interface of a module stays the same, so exposing fewer\
597+ \ values can help improve compile times!"
598+ ]
599+ )
582
600
583 ModuleName row col ->
601 ModuleName row col ->
584− error "TODO ModuleName" row col
602+ let
585−
603+ region = toRegion row col
586− ModuleExposing row col ->
604+ in
587− error "TODO ModuleExposing" row col
605+ Report.Report "EXPECTING MODULE NAME" region [] $
588−
606+ Code.toSnippet source region Nothing
589− ModuleExposingList exposing row col ->
607+ (
590− error "TODO ModuleExposingList" exposing row col
608+ D.reflow $
591−
609+ "I was parsing an `module` declaration until I got stuck here:"
592− ModulePortModule row col ->
610+ ,
593− error "TODO ModulePortModule" row col
611+ D.stack
594−
612+ [ D.reflow $
595− ModuleEffect row col ->
613+ "I was expecting to see the module name next, like in these examples:"
596− error "TODO ModuleEffect" row col
614+ , D.indent 4 $ D.vcat $
615+ [ D.fillSep [D.blue "module","Dict",D.blue "exposing","(..)"]
616+ , D.fillSep [D.blue "module","Maybe",D.blue "exposing","(..)"]
617+ , D.fillSep [D.blue "module","Html.Attributes",D.blue "exposing","(..)"]
618+ , D.fillSep [D.blue "module","Json.Decode",D.blue "exposing","(..)"]
619+ ]
620+ , D.reflow $
621+ "Notice that the module names all start with capital letters. That is required!"
622+ ]
623+ )
597
624
598− ModuleIndentStart row col ->
625+ ModuleExposing exposing row col ->
599− error "TODO ModuleIndentStart" row col
626+ error "TODO ModuleExposing" exposing row col
600
627
601− ModuleIndentName row col ->
628+ PortModuleProblem row col ->
602− error "TODO ModuleIndentName" row col
629+ let
630+ region = toRegion row col
631+ in
632+ Report.Report "UNFINISHED PORT MODULE DECLARATION" region [] $
633+ Code.toSnippet source region Nothing
634+ (
635+ D.reflow $
636+ "I am parsing an `port module` declaration, but I got stuck here:"
637+ ,
638+ D.stack
639+ [ D.reflow $
640+ "Here are some examples of valid `port module` declarations:"
641+ , D.indent 4 $ D.vcat $
642+ [ D.fillSep [D.blue "port",D.blue "module","WebSockets",D.blue "exposing","(send, listen, keepAlive)"]
643+ , D.fillSep [D.blue "port",D.blue "module","Maps",D.blue "exposing","(Location, goto)"]
644+ ]
645+ , D.reflow $
646+ "Go to the section in https://guide.elm-lang.org on ports for more information!"
647+ ]
648+ )
603
649
604− ModuleIndentExposing row col ->
650+ PortModuleName row col ->
605− error "TODO ModuleIndentExposing" row col
651+ let
652+ region = toRegion row col
653+ in
654+ Report.Report "EXPECTING MODULE NAME" region [] $
655+ Code.toSnippet source region Nothing
656+ (
657+ D.reflow $
658+ "I was parsing an `module` declaration until I got stuck here:"
659+ ,
660+ D.stack
661+ [ D.reflow $
662+ "I was expecting to see the module name next, like in these examples:"
663+ , D.indent 4 $ D.vcat $
664+ [ D.fillSep [D.blue "port",D.blue "module","WebSockets",D.blue "exposing","(send, listen, keepAlive)"]
665+ , D.fillSep [D.blue "port",D.blue "module","Maps",D.blue "exposing","(Location, goto)"]
666+ ]
667+ , D.reflow $
668+ "Notice that the module names start with capital letters. That is required!"
669+ ]
670+ )
606
671
607− ModuleIndentExposingList row col ->
672+ PortModuleExposing exposing row col ->
608− error "TODO ModuleIndentExposingList" row col
673+ error "TODO PortModuleExposing" exposing row col
609
674
610− ModuleIndentPortModule row col ->
675+ Effect row col ->
611− error "TODO ModuleIndentPortModule" row col
676+ let
677+ region = toRegion row col
678+ in
679+ Report.Report "BAD MODULE DECLARATION" region [] $
680+ Code.toSnippet source region Nothing
681+ (
682+ D.reflow $
683+ "I cannot parse this module declaration:"
684+ ,
685+ D.reflow $
686+ "This type of module is reserved for the @elm organization. It is used to\
687+ \ define certain effects, avoiding building them into the compiler."
688+ )
612
689
613 FreshLineModuleStart row col ->
690 FreshLineModuleStart row col ->
614 error "TODO FreshLineModuleStart" row col
691 error "TODO FreshLineModuleStart" row col