on master help sign in
Fill in the module declaration parse errors / have fewer of them
commit641c8c99d8eac4b339b1e686566f56be522d99b7 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 9 May 2019, 14:53 (7 years ago) parent210d7f9
2 files changed+155−78
compiler/src/Parse/Module.hs+43−43 compiler/src/Reporting/Error/Syntax.hs+112−35
compiler/src/Parse/Module.hs+43−43
@@ -220,46 +220,46 @@ chompHeader =
220220 oneOfWithFallback
221221 [
222222 -- module MyThing exposing (..)
223− do Keyword.module_ E.Module
223+ do Keyword.module_ E.ModuleProblem
224224 end <- getPosition
225− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
225+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
226226 name <- addLocation (Var.moduleName E.ModuleName)
227− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
228− Keyword.exposing_ E.ModuleExposing
229− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
230− exports <- addLocation (specialize E.ModuleExposingList exposing)
227+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
228+ Keyword.exposing_ E.ModuleProblem
229+ Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
230+ exports <- addLocation (specialize E.ModuleExposing exposing)
231231 freshLine E.FreshLineAfterModuleLine
232232 return (Just (Header name (NoEffects (A.Region start end)) exports))
233233 ,
234234 -- port module MyThing exposing (..)
235− do Keyword.port_ E.Module
236− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentPortModule
237− Keyword.module_ E.ModulePortModule
235+ do Keyword.port_ E.PortModuleProblem
236+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
237+ Keyword.module_ E.PortModuleProblem
238238 end <- getPosition
239− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentName
240− name <- addLocation (Var.moduleName E.ModuleName)
241− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
242− Keyword.exposing_ E.ModuleExposing
243− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
244− exports <- addLocation (specialize E.ModuleExposingList exposing)
239+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
240+ name <- addLocation (Var.moduleName E.PortModuleName)
241+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
242+ Keyword.exposing_ E.PortModuleProblem
243+ Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
244+ exports <- addLocation (specialize E.PortModuleExposing exposing)
245245 freshLine E.FreshLineAfterModuleLine
246246 return (Just (Header name (Ports (A.Region start end)) exports))
247247 ,
248248 -- effect module MyThing where { command = MyCmd } exposing (..)
249− do Keyword.effect_ E.Module
250− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
251− Keyword.module_ E.ModuleEffect
249+ do Keyword.effect_ E.Effect
250+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
251+ Keyword.module_ E.Effect
252252 end <- getPosition
253− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
253+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
254254 name <- addLocation (Var.moduleName E.ModuleName)
255− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
256− Keyword.where_ E.ModuleEffect
257− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
255+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
256+ Keyword.where_ E.Effect
257+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
258258 manager <- chompManager
259− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposing
260− Keyword.exposing_ E.ModuleExposing
261− Space.chompAndCheckIndent E.ModuleSpace E.ModuleIndentExposingList
262− exports <- addLocation (specialize E.ModuleExposingList exposing)
259+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
260+ Keyword.exposing_ E.Effect
261+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
262+ exports <- addLocation (specialize (const E.Effect) exposing)
263263 freshLine E.FreshLineAfterModuleLine
264264 return (Just (Header name (Manager (A.Region start end) manager) exports))
265265 ]
@@ -269,34 +269,34 @@ chompHeader =
269269
270270chompManager :: Parser E.Module Src.Manager
271271chompManager =
272− do word1 0x7B {- { -} E.ModuleEffect
272+ do word1 0x7B {- { -} E.Effect
273273 spaces_em
274− oneOf E.ModuleEffect
274+ oneOf E.Effect
275275 [ do cmd <- chompCommand
276276 spaces_em
277− oneOf E.ModuleEffect
278− [ do word1 0x7D {-}-} E.ModuleEffect
277+ oneOf E.Effect
278+ [ do word1 0x7D {-}-} E.Effect
279279 spaces_em
280280 return (Src.Cmd cmd)
281− , do word1 0x2C {-,-} E.ModuleEffect
281+ , do word1 0x2C {-,-} E.Effect
282282 spaces_em
283283 sub <- chompSubscription
284284 spaces_em
285− word1 0x7D {-}-} E.ModuleEffect
285+ word1 0x7D {-}-} E.Effect
286286 spaces_em
287287 return (Src.Fx cmd sub)
288288 ]
289289 , do sub <- chompSubscription
290290 spaces_em
291− oneOf E.ModuleEffect
292− [ do word1 0x7D {-}-} E.ModuleEffect
291+ oneOf E.Effect
292+ [ do word1 0x7D {-}-} E.Effect
293293 spaces_em
294294 return (Src.Sub sub)
295− , do word1 0x2C {-,-} E.ModuleEffect
295+ , do word1 0x2C {-,-} E.Effect
296296 spaces_em
297297 cmd <- chompCommand
298298 spaces_em
299− word1 0x7D {-}-} E.ModuleEffect
299+ word1 0x7D {-}-} E.Effect
300300 spaces_em
301301 return (Src.Fx cmd sub)
302302 ]
@@ -305,25 +305,25 @@ chompManager =
305305
306306chompCommand :: Parser E.Module (A.Located Name.Name)
307307chompCommand =
308− do Keyword.command_ E.ModuleEffect
308+ do Keyword.command_ E.Effect
309309 spaces_em
310− word1 0x3D {-=-} E.ModuleEffect
310+ word1 0x3D {-=-} E.Effect
311311 spaces_em
312− addLocation (Var.upper E.ModuleEffect)
312+ addLocation (Var.upper E.Effect)
313313
314314
315315chompSubscription :: Parser E.Module (A.Located Name.Name)
316316chompSubscription =
317− do Keyword.subscription_ E.ModuleEffect
317+ do Keyword.subscription_ E.Effect
318318 spaces_em
319− word1 0x3D {-=-} E.ModuleEffect
319+ word1 0x3D {-=-} E.Effect
320320 spaces_em
321− addLocation (Var.upper E.ModuleEffect)
321+ addLocation (Var.upper E.Effect)
322322
323323
324324spaces_em :: Parser E.Module ()
325325spaces_em =
326− Space.chompAndCheckIndent E.ModuleSpace E.ModuleEffect
326+ Space.chompAndCheckIndent E.ModuleSpace E.Effect
327327
328328
329329
compiler/src/Reporting/Error/Syntax.hs+112−35
@@ -78,19 +78,16 @@ data Error
7878data Module
7979 = ModuleSpace Space Row Col
8080 | ModuleEndOfFile Row Col
81− | Module Row Col
81+ --
82+ | ModuleProblem Row Col
8283 | ModuleName Row Col
83− | ModuleExposing Row Col
84− | ModuleExposingList Exposing Row Col
84+ | ModuleExposing Exposing Row Col
8585 --
86− | ModulePortModule Row Col
87− | ModuleEffect Row Col
86+ | PortModuleProblem Row Col
87+ | PortModuleName Row Col
88+ | PortModuleExposing Exposing Row Col
8889 --
89− | ModuleIndentStart Row Col
90− | ModuleIndentName Row Col
91− | ModuleIndentExposing Row Col
92− | ModuleIndentExposingList Row Col
93− | ModuleIndentPortModule Row Col
90+ | Effect Row Col
9491 --
9592 | FreshLineModuleStart Row Col
9693 | FreshLineAfterModuleLine Row Col
@@ -577,38 +574,118 @@ toParseErrorReport source modul =
577574 \ left to see, so whatever I am running into is confusing me a lot!"
578575 )
579576
580− Module row col ->
581− error "TODO Module" row col
577+ ModuleProblem 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+ )
582600
583601 ModuleName row col ->
584− error "TODO ModuleName" row col
585−
586− ModuleExposing row col ->
587− error "TODO ModuleExposing" row col
588−
589− ModuleExposingList exposing row col ->
590− error "TODO ModuleExposingList" exposing row col
591−
592− ModulePortModule row col ->
593− error "TODO ModulePortModule" row col
594−
595− ModuleEffect row col ->
596− error "TODO ModuleEffect" row col
602+ let
603+ region = toRegion row col
604+ in
605+ Report.Report "EXPECTING MODULE NAME" region [] $
606+ Code.toSnippet source region Nothing
607+ (
608+ D.reflow $
609+ "I was parsing an `module` declaration until I got stuck here:"
610+ ,
611+ D.stack
612+ [ D.reflow $
613+ "I was expecting to see the module name next, like in these examples:"
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+ )
597624
598− ModuleIndentStart row col ->
599− error "TODO ModuleIndentStart" row col
625+ ModuleExposing exposing row col ->
626+ error "TODO ModuleExposing" exposing row col
600627
601− ModuleIndentName row col ->
602− error "TODO ModuleIndentName" row col
628+ PortModuleProblem 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+ )
603649
604− ModuleIndentExposing row col ->
605− error "TODO ModuleIndentExposing" row col
650+ PortModuleName 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+ )
606671
607− ModuleIndentExposingList row col ->
608− error "TODO ModuleIndentExposingList" row col
672+ PortModuleExposing exposing row col ->
673+ error "TODO PortModuleExposing" exposing row col
609674
610− ModuleIndentPortModule row col ->
611− error "TODO ModuleIndentPortModule" row col
675+ Effect 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+ )
612689
613690 FreshLineModuleStart row col ->
614691 error "TODO FreshLineModuleStart" row col