on master help sign in
WIP: Better error messages for parsing operators
commit0aa98b45bf93ef08f0ab2e78f1d904332a6397ad authorAhmad Salim Al-Sibahi <asal@itu.dk> dateSun 22 Feb 2015, 19:29 (12 years ago) parentbbf672a
2 files changed+10−2
src/Idris/ParseHelpers.hs+1−1 src/Idris/ParseOps.hs+9−1
src/Idris/ParseHelpers.hs+1−1
@@ -326,7 +326,7 @@ operatorLetter = oneOf opChars
326326-- | Parses an operator
327327operator :: MonadicParsing m => m String
328328operator = do op <- token . some $ operatorLetter
329− when (op `elem` [":", "=>", "->", "<-", "=", "?=", "|"]) $
329+ when (op `elem` [":", "=>", "->", "<-", "=", "?=", "|", "**", "==>", "\\", ",", "--", "|||"]) $
330330 fail $ op ++ " is not a valid operator"
331331 return op
332332
src/Idris/ParseOps.hs+9−1
@@ -37,7 +37,8 @@ table fixes
3737 toTable (reverse fixes) ++
3838 [[backtick],
3939 [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]]
4142 where
4243 flatten :: PTerm -> PTerm -- flatten application
4344 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
@@ -80,6 +81,13 @@ backtick = Infix (do indentPropHolds gtProp
8081 fc <- getFC
8182 return (\x y -> PApp fc (PRef fc n) [pexp x, pexp y])) AssocNone
8283
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+
8391{- | Parses an operator in function position i.e. enclosed by `()', with an
8492 optional namespace
8593