on master help sign in
WIP: Better error messages for parsing operators
0aa98b4Ahmad Salim Al-Sibahi
src/Idris/ParseHelpers.hs+1−1
@@ -326,7 +326,7 @@ operatorLetter = oneOf opChars
326-- | Parses an operator
326-- | Parses an operator
327operator :: MonadicParsing m => m String
327operator :: MonadicParsing m => m String
328operator = do op <- token . some $ operatorLetter
328operator = do op <- token . some $ operatorLetter
329− when (op `elem` [":", "=>", "->", "<-", "=", "?=", "|"]) $
329+ when (op `elem` [":", "=>", "->", "<-", "=", "?=", "|", "**", "==>", "\\", ",", "--", "|||"]) $
330 fail $ op ++ " is not a valid operator"
330 fail $ op ++ " is not a valid operator"
331 return op
331 return op
332
332
src/Idris/ParseOps.hs+9−1
@@ -37,7 +37,8 @@ table fixes
37 toTable (reverse fixes) ++
37 toTable (reverse fixes) ++
38 [[backtick],
38 [[backtick],
39 [binary "$" (\fc x y -> flatten $ PApp fc x [pexp y]) AssocRight],
39 [binary "$" (\fc x y -> flatten $ PApp fc x [pexp y]) AssocRight],
40− [binary "=" (\fc x y -> PEq fc Placeholder Placeholder x y) AssocLeft]]
40+ [binary "=" (\fc x y -> PEq fc Placeholder Placeholder x y) AssocLeft],
41+ [nofixityoperator]]
41 where
42 where
42 flatten :: PTerm -> PTerm -- flatten application
43 flatten :: PTerm -> PTerm -- flatten application
43 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
44 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
@@ -80,6 +81,13 @@ backtick = Infix (do indentPropHolds gtProp
80 fc <- getFC
81 fc <- getFC
81 return (\x y -> PApp fc (PRef fc n) [pexp x, pexp y])) AssocNone
82 return (\x y -> PApp fc (PRef fc n) [pexp x, pexp y])) AssocNone
82
83
84+-- | Operator without fixity (throws an error)
85+nofixityoperator :: Operator IdrisParser PTerm
86+nofixityoperator = Infix (do indentPropHolds gtProp
87+ op <- try operator
88+ unexpected $ "Operator without known fixity: " ++ op) AssocNone
89+
90+
83{- | Parses an operator in function position i.e. enclosed by `()', with an
91{- | Parses an operator in function position i.e. enclosed by `()', with an
84 optional namespace
92 optional namespace
85
93