on master help sign in
Fill in fresh line error / have it handle more cases
6e01ea5Evan Czaplicki
compiler/src/Parse/Module.hs+7−7
@@ -54,7 +54,7 @@ fromByteString pkg source =
54
54
55normal :: Parser E.Module (Either E.Error Src.Module)
55normal :: Parser E.Module (Either E.Error Src.Module)
56normal =
56normal =
57− do freshLine E.FreshLineModuleStart
57+ do freshLine E.FreshLine
58 header <- chompHeader
58 header <- chompHeader
59 comment <- chompModuleDocComment
59 comment <- chompModuleDocComment
60 imports <- chompImports []
60 imports <- chompImports []
@@ -65,7 +65,7 @@ normal =
65
65
66core :: Parser E.Module (Either E.Error Src.Module)
66core :: Parser E.Module (Either E.Error Src.Module)
67core =
67core =
68− do freshLine E.FreshLineModuleStart
68+ do freshLine E.FreshLine
69 header <- chompHeader
69 header <- chompHeader
70 comment <- chompModuleDocComment
70 comment <- chompModuleDocComment
71 imports <- chompImports []
71 imports <- chompImports []
@@ -77,7 +77,7 @@ core =
77
77
78platform :: Parser E.Module (Either E.Error Src.Module)
78platform :: Parser E.Module (Either E.Error Src.Module)
79platform =
79platform =
80− do freshLine E.FreshLineModuleStart
80+ do freshLine E.FreshLine
81 header <- chompHeader
81 header <- chompHeader
82 comment <- chompModuleDocComment
82 comment <- chompModuleDocComment
83 imports <- chompImports []
83 imports <- chompImports []
@@ -194,7 +194,7 @@ chompModuleDocComment =
194 [
194 [
195 do docComment <- Space.docComment E.ImportStart E.ModuleSpace
195 do docComment <- Space.docComment E.ImportStart E.ModuleSpace
196 Space.chomp E.ModuleSpace
196 Space.chomp E.ModuleSpace
197− Space.checkFreshLine E.FreshLineAfterDocComment
197+ Space.checkFreshLine E.FreshLine
198 return (Just docComment)
198 return (Just docComment)
199 ]
199 ]
200 Nothing
200 Nothing
@@ -228,7 +228,7 @@ chompHeader =
228 Keyword.exposing_ E.ModuleProblem
228 Keyword.exposing_ E.ModuleProblem
229 Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
229 Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
230 exports <- addLocation (specialize E.ModuleExposing exposing)
230 exports <- addLocation (specialize E.ModuleExposing exposing)
231− freshLine E.FreshLineAfterModuleLine
231+ freshLine E.FreshLine
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 (..)
@@ -242,7 +242,7 @@ chompHeader =
242 Keyword.exposing_ E.PortModuleProblem
242 Keyword.exposing_ E.PortModuleProblem
243 Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
243 Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
244 exports <- addLocation (specialize E.PortModuleExposing exposing)
244 exports <- addLocation (specialize E.PortModuleExposing exposing)
245− freshLine E.FreshLineAfterModuleLine
245+ freshLine E.FreshLine
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 (..)
@@ -260,7 +260,7 @@ chompHeader =
260 Keyword.exposing_ E.Effect
260 Keyword.exposing_ E.Effect
261 Space.chompAndCheckIndent E.ModuleSpace E.Effect
261 Space.chompAndCheckIndent E.ModuleSpace E.Effect
262 exports <- addLocation (specialize (const E.Effect) exposing)
262 exports <- addLocation (specialize (const E.Effect) exposing)
263− freshLine E.FreshLineAfterModuleLine
263+ freshLine E.FreshLine
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 ]
266 -- default header
266 -- default header
compiler/src/Reporting/Error/Syntax.hs+44−9
@@ -89,9 +89,7 @@ data Module
89 --
89 --
90 | Effect Row Col
90 | Effect Row Col
91 --
91 --
92− | FreshLineModuleStart Row Col
92+ | FreshLine Row Col
93− | FreshLineAfterModuleLine Row Col
94− | FreshLineAfterDocComment Row Col
95 --
93 --
96 | ImportStart Row Col
94 | ImportStart Row Col
97 | ImportName Row Col
95 | ImportName Row Col
@@ -687,14 +685,51 @@ toParseErrorReport source modul =
687 \ define certain effects, avoiding building them into the compiler."
685 \ define certain effects, avoiding building them into the compiler."
688 )
686 )
689
687
690− FreshLineModuleStart row col ->
688+ FreshLine row col ->
691− error "TODO FreshLineModuleStart" row col
689+ let
690+ region = toRegion row col
692
691
693− FreshLineAfterModuleLine row col ->
692+ toBadFirstLineReport keyword =
694− error "TODO FreshLineAfterModuleLine" row col
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+ )
695
702
696− FreshLineAfterDocComment row col ->
703+ in
697− error "TODO FreshLineAfterDocComment" row col
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+ )
698
733
699 ImportStart row col ->
734 ImportStart row col ->
700 toImportReport source row col
735 toImportReport source row col