on master help sign in
Get rid of some unreachable error messages for imports
commitdf9c15a5afd96977ffe6c7145d282b84e5a42d21 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 8 May 2019, 22:23 (7 years ago) parentf71818d
2 files changed+37−13
compiler/src/Parse/Module.hs+2−2 compiler/src/Reporting/Error/Syntax.hs+35−11
compiler/src/Parse/Module.hs+2−2
@@ -341,7 +341,7 @@ chompImports imports =
341341 [ do Space.checkFreshLine E.ImportEnd
342342 chompImports $
343343 Src.Import name Nothing (Src.Explicit []) : imports
344− , do Space.checkIndent end E.ImportIndentAs
344+ , do Space.checkIndent end E.ImportEnd
345345 oneOf E.ImportAs
346346 [ chompAs name imports
347347 , chompExposing name Nothing imports
@@ -362,7 +362,7 @@ chompAs name imports =
362362 [ do Space.checkFreshLine E.ImportEnd
363363 chompImports $
364364 Src.Import name (Just alias) (Src.Explicit []) : imports
365− , do Space.checkIndent end E.ImportIndentExposing
365+ , do Space.checkIndent end E.ImportEnd
366366 chompExposing name (Just alias) imports
367367 ]
368368
compiler/src/Reporting/Error/Syntax.hs+35−11
@@ -105,9 +105,7 @@ data Module
105105 | ImportEnd Row Col -- different based on col=1 or if greater
106106 --
107107 | ImportIndentName Row Col
108− | ImportIndentAs Row Col
109108 | ImportIndentAlias Row Col
110− | ImportIndentExposing Row Col
111109 | ImportIndentExposingList Row Col
112110 --
113111 | Infix Row Col
@@ -599,7 +597,6 @@ toParseErrorReport source modul =
599597 ModuleExposingList exposing row col ->
600598 error "TODO ModuleExposingList" exposing row col
601599
602− --
603600 ModulePortModule row col ->
604601 error "TODO ModulePortModule" row col
605602
@@ -654,20 +651,47 @@ toParseErrorReport source modul =
654651 ImportIndentName row col ->
655652 error "TODO ImportIndentName" row col
656653
657− ImportIndentAs row col ->
658− error "TODO ImportIndentAs" row col
659−
660654 ImportIndentAlias row col ->
661655 error "TODO ImportIndentAlias" row col
662656
663− ImportIndentExposing row col ->
664− error "TODO ImportIndentExposing" row col
665−
666657 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+ )
668680
669681 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+ )
671695
672696 Declarations decl _ _ ->
673697 toDeclarationsReport source decl