on master help sign in
Nicer messages on specific parse failures
commit61b5d8fbfa0a4749fcc71d46514ab03073a67667 authorEvan Czaplicki <info@elm-lang.org> dateTue 13 Aug 2013, 23:11 (13 years ago) parentab83c78
2 files changed+10−4
compiler/Parse/Binop.hs+4−4 compiler/Parse/Helpers.hs+6
compiler/Parse/Binop.hs+4−4
@@ -80,21 +80,21 @@ splitLevel table n e eops =
8080joinL :: [LExpr t v] -> [String] -> IParser (LExpr t v)
8181joinL [e] [] = return e
8282joinL (a:b:es) (op:ops) = joinL (merge a b (Binop op a b) : es) ops
83−joinL _ _ = fail "Ill-formed binary expression. Report a compiler bug."
83+joinL _ _ = failure "Ill-formed binary expression. Report a compiler bug."
8484
8585joinR :: [LExpr t v] -> [String] -> IParser (LExpr t v)
8686joinR [e] [] = return e
8787joinR (a:b:es) (op:ops) = do e <- joinR (b:es) ops
8888 return (merge a e (Binop op a e))
89−joinR _ _ = fail "Ill-formed binary expression. Report a compiler bug."
89+joinR _ _ = failure "Ill-formed binary expression. Report a compiler bug."
9090
9191getAssoc :: OpTable -> Int -> [(String,LExpr t v)] -> IParser Assoc
9292getAssoc table n eops
9393 | all (==L) assocs = return L
9494 | all (==R) assocs = return R
9595 | all (==N) assocs = case assocs of [_] -> return N
96− _ -> fail (msg "precedence")
97− | otherwise = fail (msg "associativity")
96+ _ -> failure (msg "precedence")
97+ | otherwise = failure (msg "associativity")
9898 where levelOps = filter (hasLevel table n) eops
9999 assocs = map (opAssoc table . fst) levelOps
100100 msg problem =
compiler/Parse/Helpers.hs+6
@@ -116,6 +116,12 @@ constrainedSpacePrefix p constraint =
116116 indented
117117 p
118118
119+failure msg = do
120+ inp <- getInput
121+ setInput ('x':inp)
122+ anyToken
123+ fail msg
124+
119125followedBy a b = do x <- a ; b ; return x
120126
121127betwixt a b c = do char a ; out <- c