on master help sign in
Got rid of NextDecl concept, subsumed by BadSpace theories
commit294ee0705cec7fecd16a5ed4bb155b7ab981b78d authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 15 Dec 2016, 21:10 (10 years ago) parent60ac31b
4 files changed+32−45
src/Parse/Helpers.hs+3−3 src/Parse/Module.hs+9−10 src/Parse/Parse.hs+1−2 src/Reporting/Error/Syntax.hs+19−30
src/Parse/Helpers.hs+3−3
@@ -216,8 +216,8 @@ checkAligned (SPos (R.Position _ col)) =
216216 else deadend [E.BadSpace]
217217
218218
219−checkFreshLine :: E.NextDecl -> SPos -> Parser ()
220−checkFreshLine nextDecl (SPos (R.Position _ col)) =
219+checkFreshLine :: SPos -> Parser ()
220+checkFreshLine (SPos (R.Position _ col)) =
221221 if col == 1
222222 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
1919header :: Parser (Module.Header [Module.UserImport])
2020header =
2121 do start <- getPosition
22− freshLine E.ModuleDecl
22+ freshLine
2323 end <- getPosition
2424 oneOf
2525 [ fullHeader end
@@ -126,12 +126,12 @@ setting =
126126maybeDocComment :: Parser (A.Located (Maybe Text))
127127maybeDocComment =
128128 do oldEnd <- getPosition
129− freshLine E.DocCommentDecl
129+ freshLine
130130 newStart <- getPosition
131131 oneOf
132132 [ do doc <- docComment
133133 end <- getPosition
134− freshLine E.ImportDecl
134+ freshLine
135135 return (A.at newStart end (Just doc))
136136 , return (A.at oldEnd newStart Nothing)
137137 ]
@@ -152,7 +152,7 @@ chompImports imports =
152152 end <- getPosition
153153 pos <- whitespace
154154 oneOf
155− [ do checkFreshLine E.ImportDecl pos
155+ [ do checkFreshLine pos
156156 let userImport = method start end name Nothing Var.closedListing
157157 popContext ()
158158 chompImports (userImport:imports)
@@ -174,7 +174,7 @@ chompAs start name imports =
174174 end <- getPosition
175175 pos <- whitespace
176176 oneOf
177− [ do checkFreshLine E.ImportDecl pos
177+ [ do checkFreshLine pos
178178 let userImport = method start end name (Just alias) Var.closedListing
179179 popContext ()
180180 chompImports (userImport:imports)
@@ -189,7 +189,7 @@ chompExposing start name maybeAlias imports =
189189 spaces
190190 exposed <- listing listingValue
191191 end <- getPosition
192− freshLine E.ImportDecl
192+ freshLine
193193 let userImport = method start end name maybeAlias exposed
194194 popContext ()
195195 chompImports (userImport:imports)
@@ -255,8 +255,7 @@ listingValue =
255255-- FRESH LINES
256256
257257
258−freshLine :: E.NextDecl -> Parser ()
259−freshLine nextDecl =
260− do pos <- whitespace
261− checkFreshLine nextDecl pos
258+freshLine :: Parser ()
259+freshLine =
260+ checkFreshLine =<< whitespace
262261
src/Parse/Parse.hs+1−2
@@ -11,7 +11,6 @@ import Parse.Helpers
1111import qualified Parse.Module as Parse (header)
1212import qualified Parse.Declaration as Parse (declaration)
1313import qualified Reporting.Annotation as A
14−import qualified Reporting.Error.Syntax as E
1514import qualified Reporting.Result as Result
1615import qualified Validate
1716
@@ -45,7 +44,7 @@ chompDeclarations :: [Decl.Source] -> Parser [Decl.Source]
4544chompDeclarations decls =
4645 do (decl, _, pos) <- Parse.declaration
4746 oneOf
48− [ do checkFreshLine E.OtherDecl pos
47+ [ do checkFreshLine pos
4948 chompDeclarations (decl:decls)
5049 , return (reverse (decl:decls))
5150 ]
src/Reporting/Error/Syntax.hs+19−30
@@ -5,7 +5,7 @@ module Reporting.Error.Syntax
55 , ParseError(..)
66 , Problem(..), Theory(..)
77 , ContextStack, Context(..)
8− , BadOp(..), Next(..), NextDecl(..)
8+ , BadOp(..), Next(..)
99 , toReport
1010 )
1111 where
@@ -91,7 +91,6 @@ data Theory
9191 | InfixOp
9292 | Digit
9393 | EndOfFile
94− | FreshLine NextDecl
9594 | BadSpace
9695 deriving (Eq, Ord)
9796
@@ -109,10 +108,6 @@ data Next
109108 deriving (Eq, Ord)
110109
111110
112−data NextDecl = ModuleDecl | DocCommentDecl | ImportDecl | OtherDecl
113− deriving (Eq, Ord)
114−
115−
116111type ContextStack = [(Context, R.Position)]
117112
118113
@@ -537,9 +532,9 @@ problemToReport subRegion problem =
537532 BadOp op stack ->
538533 case op of
539534 HasType ->
540− badOp subRegion stack "the \"has type\" operator" "(:)"
535+ badOp subRegion stack "A" "\"has type\" operator"
541536 "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?"
543538
544539 Equals ->
545540 badEquals subRegion stack
@@ -547,7 +542,7 @@ problemToReport subRegion problem =
547542 Arrow ->
548543 if isCaseRelated stack then
549544 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."
551546 ( reflowParagraph $
552547 "All branches in a `case` must be indented the exact\
553548 \ same amount, so the patterns are vertically\
@@ -555,18 +550,18 @@ problemToReport subRegion problem =
555550 )
556551
557552 else
558− badOp subRegion stack "an arrow" "(->)"
553+ badOp subRegion stack "An" "arrow"
559554 "cases expressions and anonymous functions"
560555 "Maybe you want > or >= instead?"
561556
562557 Pipe ->
563− badOp subRegion stack "a vertical bar" "(|)"
558+ badOp subRegion stack "A" "vertical bar"
564559 "type declarations"
565560 "Maybe you want || instead?"
566561
567562 Dot ->
568563 parseReport
569− "I was not expecting a dot (.) here."
564+ "I was not expecting this dot."
570565 ( reflowParagraph $
571566 "Dots are for record access and decimal points, so\
572567 \ they cannot float around on their own. Maybe\
@@ -619,14 +614,16 @@ addPeriod msg =
619614
620615
621616badOp :: Maybe R.Region -> ContextStack -> Text -> Text -> Text -> Text -> Report.Report
622−badOp subRegion stack opName op setting hint =
623− makeParseReport subRegion ("I was not expecting " <> opName <> " here.") $
624− Help.stack
625− [ reflowParagraph $
626− "A " <> op <> " should only appear in " <> setting
627− <> contextToText "" ", but I think I am parsing " stack <> "."
628− , reflowParagraph hint
629− ]
617+badOp subRegion stack article opName setting hint =
618+ let
619+ pre =
620+ "I was not expecting this " <> opName
621+ <> contextToText "" " while parsing " stack <> "."
622+ in
623+ makeParseReport subRegion pre $
624+ reflowParagraph $
625+ article <> " " <> opName <> " should only appear in "
626+ <> setting <> ". " <> hint
630627
631628
632629badEquals :: Maybe R.Region -> ContextStack -> Report.Report
@@ -644,14 +641,14 @@ badEqualsHelp stack =
644641 case stack of
645642 [] ->
646643 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?"
648645
649646 (ExprRecord, _) : _ ->
650647 reflowParagraph $
651648 "Records look like { x = 3, y = 4 } with the equals sign right\
652649 \ after the field name. Maybe you forgot a comma?"
653650
654− (Definition name, _) : rest ->
651+ (Definition _, _) : rest ->
655652 reflowParagraph $
656653 "Maybe this is supposed to be a separate definition? If so, it\
657654 \ is indented too far. "
@@ -769,14 +766,6 @@ theoryToText context theory =
769766 BadSpace ->
770767 badSpace context
771768
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−
780769 Expecting next ->
781770 case next of
782771 Decl -> "a declaration, like `x = 5` or `type alias Model = { ... }`"