on master help sign in
Nicer messages on specific parse failures
61b5d8fEvan Czaplicki
compiler/Parse/Binop.hs+4−4
@@ -80,21 +80,21 @@ splitLevel table n e eops =
80joinL :: [LExpr t v] -> [String] -> IParser (LExpr t v)
80joinL :: [LExpr t v] -> [String] -> IParser (LExpr t v)
81joinL [e] [] = return e
81joinL [e] [] = return e
82joinL (a:b:es) (op:ops) = joinL (merge a b (Binop op a b) : es) ops
82joinL (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."
84
84
85joinR :: [LExpr t v] -> [String] -> IParser (LExpr t v)
85joinR :: [LExpr t v] -> [String] -> IParser (LExpr t v)
86joinR [e] [] = return e
86joinR [e] [] = return e
87joinR (a:b:es) (op:ops) = do e <- joinR (b:es) ops
87joinR (a:b:es) (op:ops) = do e <- joinR (b:es) ops
88 return (merge a e (Binop op a e))
88 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."
90
90
91getAssoc :: OpTable -> Int -> [(String,LExpr t v)] -> IParser Assoc
91getAssoc :: OpTable -> Int -> [(String,LExpr t v)] -> IParser Assoc
92getAssoc table n eops
92getAssoc table n eops
93 | all (==L) assocs = return L
93 | all (==L) assocs = return L
94 | all (==R) assocs = return R
94 | all (==R) assocs = return R
95 | all (==N) assocs = case assocs of [_] -> return N
95 | all (==N) assocs = case assocs of [_] -> return N
96− _ -> fail (msg "precedence")
96+ _ -> failure (msg "precedence")
97− | otherwise = fail (msg "associativity")
97+ | otherwise = failure (msg "associativity")
98 where levelOps = filter (hasLevel table n) eops
98 where levelOps = filter (hasLevel table n) eops
99 assocs = map (opAssoc table . fst) levelOps
99 assocs = map (opAssoc table . fst) levelOps
100 msg problem =
100 msg problem =
compiler/Parse/Helpers.hs+6
@@ -116,6 +116,12 @@ constrainedSpacePrefix p constraint =
116 indented
116 indented
117 p
117 p
118
118
119+failure msg = do
120+ inp <- getInput
121+ setInput ('x':inp)
122+ anyToken
123+ fail msg
124+
119followedBy a b = do x <- a ; b ; return x
125followedBy a b = do x <- a ; b ; return x
120
126
121betwixt a b c = do char a ; out <- c
127betwixt a b c = do char a ; out <- c