on master help sign in
Fill in fresh line error / have it handle more cases
commit6e01ea50bb29eeecee149e80899bb9103fedd903 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 9 May 2019, 15:51 (7 years ago) parent641c8c9
2 files changed+51−16
compiler/src/Parse/Module.hs+7−7 compiler/src/Reporting/Error/Syntax.hs+44−9
compiler/src/Parse/Module.hs+7−7
@@ -54,7 +54,7 @@ fromByteString pkg source =
5454
5555normal :: Parser E.Module (Either E.Error Src.Module)
5656normal =
57− do freshLine E.FreshLineModuleStart
57+ do freshLine E.FreshLine
5858 header <- chompHeader
5959 comment <- chompModuleDocComment
6060 imports <- chompImports []
@@ -65,7 +65,7 @@ normal =
6565
6666core :: Parser E.Module (Either E.Error Src.Module)
6767core =
68− do freshLine E.FreshLineModuleStart
68+ do freshLine E.FreshLine
6969 header <- chompHeader
7070 comment <- chompModuleDocComment
7171 imports <- chompImports []
@@ -77,7 +77,7 @@ core =
7777
7878platform :: Parser E.Module (Either E.Error Src.Module)
7979platform =
80− do freshLine E.FreshLineModuleStart
80+ do freshLine E.FreshLine
8181 header <- chompHeader
8282 comment <- chompModuleDocComment
8383 imports <- chompImports []
@@ -194,7 +194,7 @@ chompModuleDocComment =
194194 [
195195 do docComment <- Space.docComment E.ImportStart E.ModuleSpace
196196 Space.chomp E.ModuleSpace
197− Space.checkFreshLine E.FreshLineAfterDocComment
197+ Space.checkFreshLine E.FreshLine
198198 return (Just docComment)
199199 ]
200200 Nothing
@@ -228,7 +228,7 @@ chompHeader =
228228 Keyword.exposing_ E.ModuleProblem
229229 Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
230230 exports <- addLocation (specialize E.ModuleExposing exposing)
231− freshLine E.FreshLineAfterModuleLine
231+ freshLine E.FreshLine
232232 return (Just (Header name (NoEffects (A.Region start end)) exports))
233233 ,
234234 -- port module MyThing exposing (..)
@@ -242,7 +242,7 @@ chompHeader =
242242 Keyword.exposing_ E.PortModuleProblem
243243 Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
244244 exports <- addLocation (specialize E.PortModuleExposing exposing)
245− freshLine E.FreshLineAfterModuleLine
245+ freshLine E.FreshLine
246246 return (Just (Header name (Ports (A.Region start end)) exports))
247247 ,
248248 -- effect module MyThing where { command = MyCmd } exposing (..)
@@ -260,7 +260,7 @@ chompHeader =
260260 Keyword.exposing_ E.Effect
261261 Space.chompAndCheckIndent E.ModuleSpace E.Effect
262262 exports <- addLocation (specialize (const E.Effect) exposing)
263− freshLine E.FreshLineAfterModuleLine
263+ freshLine E.FreshLine
264264 return (Just (Header name (Manager (A.Region start end) manager) exports))
265265 ]
266266 -- default header
compiler/src/Reporting/Error/Syntax.hs+44−9
@@ -89,9 +89,7 @@ data Module
8989 --
9090 | Effect Row Col
9191 --
92− | FreshLineModuleStart Row Col
93− | FreshLineAfterModuleLine Row Col
94− | FreshLineAfterDocComment Row Col
92+ | FreshLine Row Col
9593 --
9694 | ImportStart Row Col
9795 | ImportName Row Col
@@ -687,14 +685,51 @@ toParseErrorReport source modul =
687685 \ define certain effects, avoiding building them into the compiler."
688686 )
689687
690− FreshLineModuleStart row col ->
691− error "TODO FreshLineModuleStart" row col
688+ FreshLine row col ->
689+ let
690+ region = toRegion row col
692691
693− FreshLineAfterModuleLine row col ->
694− error "TODO FreshLineAfterModuleLine" row col
692+ toBadFirstLineReport keyword =
693+ Report.Report "TOO MUCH INDENTATION" region [] $
694+ Code.toSnippet source region Nothing
695+ (
696+ D.reflow $
697+ "This `" ++ keyword ++ "` should not have any spaces before it:"
698+ ,
699+ D.reflow $
700+ "Delete the spaces before `" ++ keyword ++ "` until there are none left!"
701+ )
695702
696− FreshLineAfterDocComment row col ->
697− error "TODO FreshLineAfterDocComment" row col
703+ in
704+ case Code.whatIsNext source row col of
705+ Code.Keyword "module" -> toBadFirstLineReport "module"
706+ Code.Keyword "import" -> toBadFirstLineReport "import"
707+ Code.Keyword "type" -> toBadFirstLineReport "type"
708+ Code.Keyword "port" -> toBadFirstLineReport "port"
709+ _ ->
710+ Report.Report "SYNTAX PROBLEM" region [] $
711+ Code.toSnippet source region Nothing
712+ (
713+ D.reflow $
714+ "I got stuck here:"
715+ ,
716+ D.stack
717+ [ D.reflow $
718+ "I am not sure what is going on, but I recommend starting an Elm\
719+ \ file with the following lines:"
720+ , D.vcat
721+ [ D.fillSep [D.blue "import","Html"]
722+ , ""
723+ , D.fillSep [D.green "main","="]
724+ , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
725+ ]
726+ , D.reflow $
727+ "You should be able to copy those lines directly into your file. Check out\
728+ \ some of the examples on https://elm-lang.org for more help getting started!"
729+ , D.toSimpleNote $
730+ "This can also happen when something is indented too much!"
731+ ]
732+ )
698733
699734 ImportStart row col ->
700735 toImportReport source row col