@@ -30,13 +30,22 @@ import qualified Text.Megaparsec.Expr as P
30-- using pre-build and user-defined operator/fixity declarations
30-- using pre-build and user-defined operator/fixity declarations
31table :: [FixDecl] -> [[P.Operator IdrisParser PTerm]]
31table :: [FixDecl] -> [[P.Operator IdrisParser PTerm]]
32table fixes
32table fixes
33− = [[prefix "-" (\fc x -> PApp fc (PRef fc [fc] (sUN "negate")) [pexp x])]] ++
33+ = [[prefix "-" negateExpr]] ++
34 toTable (reverse fixes) ++
34 toTable (reverse fixes) ++
35 [[noFixityBacktickOperator],
35 [[noFixityBacktickOperator],
36 [binary "$" P.InfixR $ \fc _ x y -> flatten $ PApp fc x [pexp y]],
36 [binary "$" P.InfixR $ \fc _ x y -> flatten $ PApp fc x [pexp y]],
37 [binary "=" P.InfixL $ \fc _ x y -> PApp fc (PRef fc [fc] eqTy) [pexp x, pexp y]],
37 [binary "=" P.InfixL $ \fc _ x y -> PApp fc (PRef fc [fc] eqTy) [pexp x, pexp y]],
38 [noFixityOperator]]
38 [noFixityOperator]]
41+ negateExpr :: FC -> PTerm -> PTerm
42+ negateExpr _ (PConstant fc (I int)) = PConstant fc $ I $ negate int
43+ negateExpr _ (PConstant fc (BI bigInt)) = PConstant fc $ BI $ negate bigInt
44+ negateExpr _ (PConstant fc (Fl dbl)) = PConstant fc $ Fl $ negate dbl
45+ negateExpr _ (PConstSugar fc term) = negateExpr fc term
46+ negateExpr fc (PAlternative ns tp terms) = PAlternative ns tp $ map (negateExpr fc) terms
47+ negateExpr fc x = PApp fc (PRef fc [fc] (sUN "negate")) [pexp x]
40 flatten :: PTerm -> PTerm -- flatten application
49 flatten :: PTerm -> PTerm -- flatten application
41 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
50 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
42 flatten t = t
51 flatten t = t