git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #804 from sztupi/fix-paren-expressions

Parentheses lost when different operators of same precedence in expression

commite29cdb0a7c7bf2923b5f1499e6940fc54178bac3 authorPhil Freeman <paf31@cantab.net> dateFri 9 Jan 2015, 16:06 (12 years ago) parent02442e33fec315
2 files changed+30−9
examples/passing/OperatorAssociativity.purs+25−4 src/Language/PureScript/Pretty/JS.hs+5−5
examples/passing/OperatorAssociativity.purs+25−4
@@ -1,15 +1,36 @@
11module Main where
22
33import Control.Monad.Eff
4+import Debug.Trace
5+
6+foreign import data Assert :: !
7+
8+foreign import assert
9+ "function assert(x) { return function (desc) {\
10+ \ return function () {\
11+ \ if (!x) throw new Error('assertion (' + desc + ') failed');\
12+ \ return {};\
13+ \ };\
14+ \};};" :: forall e. Boolean -> String -> Eff (assert :: Assert | e) Unit
415
516bug :: Number -> Number -> Number
617bug a b = 0 - (a - b)
718
8−foreign import explode
19+foreign import explode
920 "function explode() {\
1021 \ throw new Error('Assertion failed!');\
1122 \}":: forall eff a. Eff eff a
1223
13−main = case bug 0 2 of
14− 2 -> Debug.Trace.trace "Done!"
15− _ -> explode
24+main = do
25+ assert (bug 0 2 == 2) "bug 0 2 == 2"
26+ assert (0 - (0 - 2) == 2) "0 - (0 - 2) == 2"
27+ assert (0 - (0 + 2) == -2) "0 - (0 + 2) == -2"
28+
29+ assert (6 / (3 * 2) == 1) "6 / (3 * 2) == 1"
30+ assert ((6 / 3) * 2 == 4) "(6 / 3) * 2 == 4"
31+
32+ assert (6 % (2 * 2) == 2) "6 % (2 * 2) == 2"
33+ assert ((6 % 2) * 2 == 0) "(6 % 2) * 2 == 0"
34+
35+ assert (4 % (9 / 3) == 1) "4 % (9 / 3) == 1"
36+ assert ((4 % 9) / 2 == 2) "(4 % 9) / 2 == 2"
src/Language/PureScript/Pretty/JS.hs+5−5
@@ -273,11 +273,11 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
273273 , [ unary BitwiseNot "~" ]
274274 , [ unary Negate "-" ]
275275 , [ unary Positive "+" ]
276− , [ binary Multiply "*" ]
277− , [ binary Divide "/" ]
278− , [ binary Modulus "%" ]
279− , [ binary Add "+" ]
280− , [ binary Subtract "-" ]
276+ , [ binary Multiply "*"
277+ , binary Divide "/"
278+ , binary Modulus "%" ]
279+ , [ binary Add "+"
280+ , binary Subtract "-" ]
281281 , [ binary ShiftLeft "<<" ]
282282 , [ binary ShiftRight ">>" ]
283283 , [ binary ZeroFillShiftRight ">>>" ]