@@ -20,7 +20,8 @@
20{-# LANGUAGE Rank2Types, FlexibleContexts #-}
20{-# LANGUAGE Rank2Types, FlexibleContexts #-}
22module Language.PureScript.Sugar.Operators (
22module Language.PureScript.Sugar.Operators (
23− rebracket
23+ rebracket,
26import Language.PureScript.Names
27import Language.PureScript.Names
@@ -42,6 +43,8 @@ import qualified Text.Parsec as P
42import qualified Text.Parsec.Pos as P
43import qualified Text.Parsec.Pos as P
43import qualified Text.Parsec.Expr as P
44import qualified Text.Parsec.Expr as P
46+import qualified Language.PureScript.Constants as C
46-- Remove explicit parentheses and reorder binary operator applications
49-- Remove explicit parentheses and reorder binary operator applications
@@ -52,6 +55,14 @@ rebracket ms = do
52 let opTable = customOperatorTable fixities
55 let opTable = customOperatorTable fixities
53 mapM (rebracketModule opTable) ms
56 mapM (rebracketModule opTable) ms
58+removeSignedLiterals :: (D.Data d) => d -> d
59+removeSignedLiterals = G.everywhere (G.mkT go)
61+ go (UnaryMinus (NumericLiteral (Left n))) = NumericLiteral (Left $ negate n)
62+ go (UnaryMinus (NumericLiteral (Right n))) = NumericLiteral (Right $ negate n)
63+ go (UnaryMinus val) = App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.negate))) val
55rebracketModule :: [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Module -> Either String Module
66rebracketModule :: [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Module -> Either String Module
56rebracketModule opTable (Module mn ds exts) = Module mn <$> (removeParens <$> G.everywhereM' (G.mkM (matchOperators opTable)) ds) <*> pure exts
67rebracketModule opTable (Module mn ds exts) = Module mn <$> (removeParens <$> G.everywhereM' (G.mkM (matchOperators opTable)) ds) <*> pure exts