on master help sign in
Got rid of NextDecl concept, subsumed by BadSpace theories
294ee07Evan Czaplicki
src/Parse/Helpers.hs+3−3
@@ -216,8 +216,8 @@ checkAligned (SPos (R.Position _ col)) =
216 else deadend [E.BadSpace]
216 else deadend [E.BadSpace]
217
217
218
218
219−checkFreshLine :: E.NextDecl -> SPos -> Parser ()
219+checkFreshLine :: SPos -> Parser ()
220−checkFreshLine nextDecl (SPos (R.Position _ col)) =
220+checkFreshLine (SPos (R.Position _ col)) =
221 if col == 1
221 if col == 1
222 then return ()
222 then return ()
223− else deadend [E.FreshLine nextDecl]
223+ else deadend [E.BadSpace]
src/Parse/Module.hs+9−10
@@ -19,7 +19,7 @@ import qualified Reporting.Region as R
19header :: Parser (Module.Header [Module.UserImport])
19header :: Parser (Module.Header [Module.UserImport])
20header =
20header =
21 do start <- getPosition
21 do start <- getPosition
22− freshLine E.ModuleDecl
22+ freshLine
23 end <- getPosition
23 end <- getPosition
24 oneOf
24 oneOf
25 [ fullHeader end
25 [ fullHeader end
@@ -126,12 +126,12 @@ setting =
126maybeDocComment :: Parser (A.Located (Maybe Text))
126maybeDocComment :: Parser (A.Located (Maybe Text))
127maybeDocComment =
127maybeDocComment =
128 do oldEnd <- getPosition
128 do oldEnd <- getPosition
129− freshLine E.DocCommentDecl
129+ freshLine
130 newStart <- getPosition
130 newStart <- getPosition
131 oneOf
131 oneOf
132 [ do doc <- docComment
132 [ do doc <- docComment
133 end <- getPosition
133 end <- getPosition
134− freshLine E.ImportDecl
134+ freshLine
135 return (A.at newStart end (Just doc))
135 return (A.at newStart end (Just doc))
136 , return (A.at oldEnd newStart Nothing)
136 , return (A.at oldEnd newStart Nothing)
137 ]
137 ]
@@ -152,7 +152,7 @@ chompImports imports =
152 end <- getPosition
152 end <- getPosition
153 pos <- whitespace
153 pos <- whitespace
154 oneOf
154 oneOf
155− [ do checkFreshLine E.ImportDecl pos
155+ [ do checkFreshLine pos
156 let userImport = method start end name Nothing Var.closedListing
156 let userImport = method start end name Nothing Var.closedListing
157 popContext ()
157 popContext ()
158 chompImports (userImport:imports)
158 chompImports (userImport:imports)
@@ -174,7 +174,7 @@ chompAs start name imports =
174 end <- getPosition
174 end <- getPosition
175 pos <- whitespace
175 pos <- whitespace
176 oneOf
176 oneOf
177− [ do checkFreshLine E.ImportDecl pos
177+ [ do checkFreshLine pos
178 let userImport = method start end name (Just alias) Var.closedListing
178 let userImport = method start end name (Just alias) Var.closedListing
179 popContext ()
179 popContext ()
180 chompImports (userImport:imports)
180 chompImports (userImport:imports)
@@ -189,7 +189,7 @@ chompExposing start name maybeAlias imports =
189 spaces
189 spaces
190 exposed <- listing listingValue
190 exposed <- listing listingValue
191 end <- getPosition
191 end <- getPosition
192− freshLine E.ImportDecl
192+ freshLine
193 let userImport = method start end name maybeAlias exposed
193 let userImport = method start end name maybeAlias exposed
194 popContext ()
194 popContext ()
195 chompImports (userImport:imports)
195 chompImports (userImport:imports)
@@ -255,8 +255,7 @@ listingValue =
255-- FRESH LINES
255-- FRESH LINES
256
256
257
257
258−freshLine :: E.NextDecl -> Parser ()
258+freshLine :: Parser ()
259−freshLine nextDecl =
259+freshLine =
260− do pos <- whitespace
261− checkFreshLine nextDecl pos
260+ checkFreshLine =<< whitespace
262
261
src/Parse/Parse.hs+1−2
@@ -11,7 +11,6 @@ import Parse.Helpers
11import qualified Parse.Module as Parse (header)
11import qualified Parse.Module as Parse (header)
12import qualified Parse.Declaration as Parse (declaration)
12import qualified Parse.Declaration as Parse (declaration)
13import qualified Reporting.Annotation as A
13import qualified Reporting.Annotation as A
14−import qualified Reporting.Error.Syntax as E
15import qualified Reporting.Result as Result
14import qualified Reporting.Result as Result
16import qualified Validate
15import qualified Validate
17
16
@@ -45,7 +44,7 @@ chompDeclarations :: [Decl.Source] -> Parser [Decl.Source]
45chompDeclarations decls =
44chompDeclarations decls =
46 do (decl, _, pos) <- Parse.declaration
45 do (decl, _, pos) <- Parse.declaration
47 oneOf
46 oneOf
48− [ do checkFreshLine E.OtherDecl pos
47+ [ do checkFreshLine pos
49 chompDeclarations (decl:decls)
48 chompDeclarations (decl:decls)
50 , return (reverse (decl:decls))
49 , return (reverse (decl:decls))
51 ]
50 ]
src/Reporting/Error/Syntax.hs+19−30
@@ -5,7 +5,7 @@ module Reporting.Error.Syntax
5 , ParseError(..)
5 , ParseError(..)
6 , Problem(..), Theory(..)
6 , Problem(..), Theory(..)
7 , ContextStack, Context(..)
7 , ContextStack, Context(..)
8− , BadOp(..), Next(..), NextDecl(..)
8+ , BadOp(..), Next(..)
9 , toReport
9 , toReport
10 )
10 )
11 where
11 where
@@ -91,7 +91,6 @@ data Theory
91 | InfixOp
91 | InfixOp
92 | Digit
92 | Digit
93 | EndOfFile
93 | EndOfFile
94− | FreshLine NextDecl
95 | BadSpace
94 | BadSpace
96 deriving (Eq, Ord)
95 deriving (Eq, Ord)
97
96
@@ -109,10 +108,6 @@ data Next
109 deriving (Eq, Ord)
108 deriving (Eq, Ord)
110
109
111
110
112−data NextDecl = ModuleDecl | DocCommentDecl | ImportDecl | OtherDecl
113− deriving (Eq, Ord)
114−
115−
116type ContextStack = [(Context, R.Position)]
111type ContextStack = [(Context, R.Position)]
117
112
118
113
@@ -537,9 +532,9 @@ problemToReport subRegion problem =
537 BadOp op stack ->
532 BadOp op stack ->
538 case op of
533 case op of
539 HasType ->
534 HasType ->
540− badOp subRegion stack "the \"has type\" operator" "(:)"
535+ badOp subRegion stack "A" "\"has type\" operator"
541 "type annotations and record types"
536 "type annotations and record types"
542− "Maybe you want :: instead? Or maybe your indentation is a bit off?"
537+ "Maybe you want :: instead? Or maybe something is indented too much?"
543
538
544 Equals ->
539 Equals ->
545 badEquals subRegion stack
540 badEquals subRegion stack
@@ -547,7 +542,7 @@ problemToReport subRegion problem =
547 Arrow ->
542 Arrow ->
548 if isCaseRelated stack then
543 if isCaseRelated stack then
549 parseReport
544 parseReport
550− "I ran into a stray arrow (->) while parsing this `case` expression."
545+ "I ran into a stray arrow while parsing this `case` expression."
551 ( reflowParagraph $
546 ( reflowParagraph $
552 "All branches in a `case` must be indented the exact\
547 "All branches in a `case` must be indented the exact\
553 \ same amount, so the patterns are vertically\
548 \ same amount, so the patterns are vertically\
@@ -555,18 +550,18 @@ problemToReport subRegion problem =
555 )
550 )
556
551
557 else
552 else
558− badOp subRegion stack "an arrow" "(->)"
553+ badOp subRegion stack "An" "arrow"
559 "cases expressions and anonymous functions"
554 "cases expressions and anonymous functions"
560 "Maybe you want > or >= instead?"
555 "Maybe you want > or >= instead?"
561
556
562 Pipe ->
557 Pipe ->
563− badOp subRegion stack "a vertical bar" "(|)"
558+ badOp subRegion stack "A" "vertical bar"
564 "type declarations"
559 "type declarations"
565 "Maybe you want || instead?"
560 "Maybe you want || instead?"
566
561
567 Dot ->
562 Dot ->
568 parseReport
563 parseReport
569− "I was not expecting a dot (.) here."
564+ "I was not expecting this dot."
570 ( reflowParagraph $
565 ( reflowParagraph $
571 "Dots are for record access and decimal points, so\
566 "Dots are for record access and decimal points, so\
572 \ they cannot float around on their own. Maybe\
567 \ they cannot float around on their own. Maybe\
@@ -619,14 +614,16 @@ addPeriod msg =
619
614
620
615
621badOp :: Maybe R.Region -> ContextStack -> Text -> Text -> Text -> Text -> Report.Report
616badOp :: Maybe R.Region -> ContextStack -> Text -> Text -> Text -> Text -> Report.Report
622−badOp subRegion stack opName op setting hint =
617+badOp subRegion stack article opName setting hint =
618+ let
619+ pre =
623− makeParseReport subRegion ("I was not expecting " <> opName <> " here.") $
620+ "I was not expecting this " <> opName
624− Help.stack
621+ <> contextToText "" " while parsing " stack <> "."
622+ in
623+ makeParseReport subRegion pre $
625− [ reflowParagraph $
624+ reflowParagraph $
626− "A " <> op <> " should only appear in " <> setting
625+ article <> " " <> opName <> " should only appear in "
627− <> contextToText "" ", but I think I am parsing " stack <> "."
626+ <> setting <> ". " <> hint
628− , reflowParagraph hint
629− ]
630
627
631
628
632badEquals :: Maybe R.Region -> ContextStack -> Report.Report
629badEquals :: Maybe R.Region -> ContextStack -> Report.Report
@@ -644,14 +641,14 @@ badEqualsHelp stack =
644 case stack of
641 case stack of
645 [] ->
642 [] ->
646 reflowParagraph $
643 reflowParagraph $
647− "Maybe you want == instead? Or maybe your indentation is a bit off?"
644+ "Maybe you want == instead? Or maybe something is indented too much?"
648
645
649 (ExprRecord, _) : _ ->
646 (ExprRecord, _) : _ ->
650 reflowParagraph $
647 reflowParagraph $
651 "Records look like { x = 3, y = 4 } with the equals sign right\
648 "Records look like { x = 3, y = 4 } with the equals sign right\
652 \ after the field name. Maybe you forgot a comma?"
649 \ after the field name. Maybe you forgot a comma?"
653
650
654− (Definition name, _) : rest ->
651+ (Definition _, _) : rest ->
655 reflowParagraph $
652 reflowParagraph $
656 "Maybe this is supposed to be a separate definition? If so, it\
653 "Maybe this is supposed to be a separate definition? If so, it\
657 \ is indented too far. "
654 \ is indented too far. "
@@ -769,14 +766,6 @@ theoryToText context theory =
769 BadSpace ->
766 BadSpace ->
770 badSpace context
767 badSpace context
771
768
772− FreshLine nextDecl ->
773− "a fresh line (without any leading spaces) for " <>
774− case nextDecl of
775− ModuleDecl -> "something like `module Main exposing (..)`"
776− DocCommentDecl -> "something like `import Html exposing (text)`"
777− ImportDecl -> "an `import` or a declarations"
778− OtherDecl -> "a top-level declaration, like `view model = div [] [...]`"
779−
780 Expecting next ->
769 Expecting next ->
781 case next of
770 case next of
782 Decl -> "a declaration, like `x = 5` or `type alias Model = { ... }`"
771 Decl -> "a declaration, like `x = 5` or `type alias Model = { ... }`"