on master help sign in
Get rid of some unreachable error messages for imports
df9c15aEvan Czaplicki
compiler/src/Parse/Module.hs+2−2
@@ -341,7 +341,7 @@ chompImports imports =
341 [ do Space.checkFreshLine E.ImportEnd
341 [ do Space.checkFreshLine E.ImportEnd
342 chompImports $
342 chompImports $
343 Src.Import name Nothing (Src.Explicit []) : imports
343 Src.Import name Nothing (Src.Explicit []) : imports
344− , do Space.checkIndent end E.ImportIndentAs
344+ , do Space.checkIndent end E.ImportEnd
345 oneOf E.ImportAs
345 oneOf E.ImportAs
346 [ chompAs name imports
346 [ chompAs name imports
347 , chompExposing name Nothing imports
347 , chompExposing name Nothing imports
@@ -362,7 +362,7 @@ chompAs name imports =
362 [ do Space.checkFreshLine E.ImportEnd
362 [ do Space.checkFreshLine E.ImportEnd
363 chompImports $
363 chompImports $
364 Src.Import name (Just alias) (Src.Explicit []) : imports
364 Src.Import name (Just alias) (Src.Explicit []) : imports
365− , do Space.checkIndent end E.ImportIndentExposing
365+ , do Space.checkIndent end E.ImportEnd
366 chompExposing name (Just alias) imports
366 chompExposing name (Just alias) imports
367 ]
367 ]
368
368
compiler/src/Reporting/Error/Syntax.hs+35−11
@@ -105,9 +105,7 @@ data Module
105 | ImportEnd Row Col -- different based on col=1 or if greater
105 | ImportEnd Row Col -- different based on col=1 or if greater
106 --
106 --
107 | ImportIndentName Row Col
107 | ImportIndentName Row Col
108− | ImportIndentAs Row Col
109 | ImportIndentAlias Row Col
108 | ImportIndentAlias Row Col
110− | ImportIndentExposing Row Col
111 | ImportIndentExposingList Row Col
109 | ImportIndentExposingList Row Col
112 --
110 --
113 | Infix Row Col
111 | Infix Row Col
@@ -599,7 +597,6 @@ toParseErrorReport source modul =
599 ModuleExposingList exposing row col ->
597 ModuleExposingList exposing row col ->
600 error "TODO ModuleExposingList" exposing row col
598 error "TODO ModuleExposingList" exposing row col
601
599
602− --
603 ModulePortModule row col ->
600 ModulePortModule row col ->
604 error "TODO ModulePortModule" row col
601 error "TODO ModulePortModule" row col
605
602
@@ -654,20 +651,47 @@ toParseErrorReport source modul =
654 ImportIndentName row col ->
651 ImportIndentName row col ->
655 error "TODO ImportIndentName" row col
652 error "TODO ImportIndentName" row col
656
653
657− ImportIndentAs row col ->
658− error "TODO ImportIndentAs" row col
659−
660 ImportIndentAlias row col ->
654 ImportIndentAlias row col ->
661 error "TODO ImportIndentAlias" row col
655 error "TODO ImportIndentAlias" row col
662
656
663− ImportIndentExposing row col ->
664− error "TODO ImportIndentExposing" row col
665−
666 ImportIndentExposingList row col ->
657 ImportIndentExposingList row col ->
667− error "TODO ImportIndentExposingList" row col
658+ let
659+ region = toRegion row col
660+ in
661+ Report.Report "UNFINISHED IMPORT" region [] $
662+ Report.toCodeSnippet source region Nothing
663+ (
664+ D.reflow $
665+ "I was parsing an `import` until I got stuck here:"
666+ ,
667+ D.stack
668+ [ D.reflow $
669+ "I was expecting to see the list of exposed values next. For example, here\
670+ \ are two ways to expose values from the `Html` module:"
671+ , D.indent 4 $ D.vcat $
672+ [ D.fillSep [D.blue "import","Html",D.blue "exposing",D.green "(..)"]
673+ , D.fillSep [D.blue "import","Html",D.blue "exposing",D.green "(Html, div, text)"]
674+ ]
675+ , D.reflow $
676+ "I generally recommend the second style. It is more explicit, making it\
677+ \ much easier to figure out where values are coming from in large projects!"
678+ ]
679+ )
668
680
669 Infix row col ->
681 Infix row col ->
670− error "TODO Infix" row col
682+ let
683+ region = toRegion row col
684+ in
685+ Report.Report "BAD INFIX" region [] $
686+ Report.toCodeSnippet source region Nothing
687+ (
688+ D.reflow $
689+ "Something went wrong in this infix operator declaration:"
690+ ,
691+ D.reflow $
692+ "This feature is used by the @elm organization to define the\
693+ \ languages built-in operators."
694+ )
671
695
672 Declarations decl _ _ ->
696 Declarations decl _ _ ->
673 toDeclarationsReport source decl
697 toDeclarationsReport source decl