git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use braces for blocks, instead of the do keyword
commitaa13d6d954d6ccc8889a9428fac693753ab47c93 authorPhil Freeman <paf31@cantab.net> dateSun 22 Dec 2013, 14:04 (13 years ago) parentf745cd9
10 files changed+133−91
examples/passing/Assign.purs+7−5 examples/passing/Console.purs+9−5 examples/passing/Foreach.purs+7−5 examples/passing/IfThenElse.purs+32−22 examples/passing/TypeDecl.purs+7−5 examples/passing/TypeSynonyms.purs+6−4 libraries/jquery/example.purs+6−5 libraries/prelude/prelude.purs+37−25 purescript.cabal+1−1 src/Language/PureScript/Parser/Values.hs+21−14
examples/passing/Assign.purs+7−5
@@ -1,5 +1,7 @@
1−sum = \n -> do
2− var x = 0
3− for i <- 0 until n:
4− x = x + i
5− return x
1+sum = \n -> {
2+ var x = 0;
3+ for (i <- 0 until n) {
4+ x = x + i;
5+ }
6+ return x;
7+ }
examples/passing/Console.purs+9−5
@@ -9,11 +9,15 @@ foreign import (>>=) :: forall a b. IO a -> (a -> IO b) -> IO b
99foreign import putStrLn :: String -> IO {}
1010
1111replicateM_ :: forall a. Number -> IO a -> IO {}
12−replicateM_ = \n -> \x -> do
13− var io = ret {}
14− for i <- 0 until n:
15− io = x *> io
16− return io
12+replicateM_ = \n -> \x ->
13+ {
14+ var io = ret {};
15+ for (i <- 0 until n)
16+ {
17+ io = x *> io;
18+ }
19+ return io;
20+ }
1721
1822main = replicateM_ 10 (putStrLn "Hello World!")
1923
examples/passing/Foreach.purs+7−5
@@ -1,5 +1,7 @@
1−sum = \ns -> do
2− var total = 0
3− foreach n in ns:
4− total = total + n
5− return total
1+sum = \ns -> {
2+ var total = 0;
3+ foreach (n in ns) {
4+ total = total + n;
5+ }
6+ return total;
7+ }
examples/passing/IfThenElse.purs+32−22
@@ -1,24 +1,34 @@
1−testIf = do
2− var x = 0
3− if x == 0:
4− x = x + 1
5− return x
1+testIf =
2+ {
3+ var x = 0;
4+ if (x == 0) {
5+ x = x + 1;
6+ }
7+ return x;
8+ }
69
7−testIfElse = do
8− var x = 0
9− if x == 0:
10− x = x + 1
11− else:
12− x = x - 1
13− return x
10+testIfElse =
11+ {
12+ var x = 0;
13+ if (x == 0) {
14+ x = x + 1;
15+ } else {
16+ x = x - 1;
17+ }
18+ return x;
19+ }
1420
15−testIfElseIf = \x -> do
16− var y = x
17− while y > 1:
18− if y % 3 == 0:
19− y = y / 3
20− else if y % 3 == 1:
21− y = (y - 1) % 3
22− else:
23− y = y * 4 + 1
24− return y
21+testIfElseIf = \x ->
22+ {
23+ var y = x;
24+ while (y > 1) {
25+ if (y % 3 == 0) {
26+ y = y / 3;
27+ } else if (y % 3 == 1) {
28+ y = (y - 1) % 3;
29+ } else {
30+ y = y * 4 + 1;
31+ }
32+ }
33+ return y;
34+ }
examples/passing/TypeDecl.purs+7−5
@@ -5,8 +5,10 @@ k :: String -> Number -> String
55k = \x -> \y -> x
66
77iterate :: forall a. Number -> (a -> a) -> a -> a
8−iterate = \n -> \f -> \a -> do
9− var result = a
10− for i <- 0 until n:
11− result = f result
12− return result
8+iterate = \n -> \f -> \a -> {
9+ var result = a;
10+ for (i <- 0 until n) {
11+ result = f result;
12+ }
13+ return result;
14+ }
examples/passing/TypeSynonyms.purs+6−4
@@ -6,10 +6,12 @@ type Lens a b =
66composeLenses :: forall a b c. Lens a b -> Lens b c -> Lens a c
77composeLenses = \l1 -> \l2 ->
88 { get: \a -> l2.get (l1.get a)
9− , set: \a -> \c -> do
10− var b = l1.get a
11− var b1 = l2.set b c
12− return l1.set a b1
9+ , set: \a -> \c ->
10+ {
11+ var b = l1.get a;
12+ var b1 = l2.set b c;
13+ return l1.set a b1;
14+ }
1315 }
1416
1517type Pair a b = { fst :: a, snd :: b }
libraries/jquery/example.purs+6−5
@@ -1,5 +1,6 @@
1−main = do
2− var div = create "<div>"
3− div = div `appendText` "Hello World!" `css` { color: "#FF0000" }
4− div = div `appendTo` select "body"
5− return { }
1+main = {
2+ var div = create "<div>";
3+ div = div `appendText` "Hello World!" `css` { color: "#FF0000" };
4+ div = div `appendTo` select "body";
5+ return { };
6+ }
libraries/prelude/prelude.purs+37−25
@@ -68,11 +68,13 @@ foldr = \f -> \a -> \bs -> case bs of
6868 [] -> a
6969
7070foldl :: forall a b. (a -> b -> b) -> b -> [a] -> b
71−foldl = \f -> \b -> \as -> do
72− var result = b
73− foreach a in as:
74− result = f a result
75− return result
71+foldl = \f -> \b -> \as -> {
72+ var result = b;
73+ foreach (a in as) {
74+ result = f a result;
75+ }
76+ return result;
77+ }
7678
7779foreign import member "length" length :: forall a. [a] -> Number
7880
@@ -102,11 +104,13 @@ cons :: forall a. a -> [a] -> [a]
102104cons = \a -> concat([a])
103105
104106concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
105−concatMap = \as -> \f -> do
106− var result = []
107− foreach a in as:
108− result = result `concat` f a
109− return result
107+concatMap = \as -> \f -> {
108+ var result = [];
109+ foreach (a in as) {
110+ result = result `concat` f a;
111+ }
112+ return result;
113+ }
110114
111115foreign import filter :: forall a. [a] -> (a -> Boolean) -> [a]
112116
@@ -116,11 +120,13 @@ empty = \as -> case as of
116120 _ -> false
117121
118122range :: Number -> Number -> [Number]
119−range = \lo -> \hi -> do
120− var ns = []
121− for n <- lo until hi:
122− ns = push ns n
123− return ns
123+range = \lo -> \hi -> {
124+ var ns = [];
125+ for (n <- lo until hi) {
126+ ns = push ns n;
127+ }
128+ return ns;
129+ }
124130
125131zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
126132zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
@@ -128,18 +134,24 @@ zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
128134 _ -> []
129135
130136any :: forall a. (a -> Boolean) -> [a] -> Boolean
131−any = \p -> \as -> do
132− for i <- 0 until length as:
133− if p (as !! i):
134− return true
135− return false
137+any = \p -> \as -> {
138+ for (i <- 0 until length as) {
139+ if (p (as !! i)) {
140+ return true;
141+ }
142+ }
143+ return false;
144+ }
136145
137146all :: forall a. (a -> Boolean) -> [a] -> Boolean
138−all = \p -> \as -> do
139− for i <- 0 until length as:
140− if !(p (as !! i)):
141− return false
142− return true
147+all = \p -> \as -> {
148+ for (i <- 0 until length as) {
149+ if (!(p (as !! i))) {
150+ return false;
151+ }
152+ }
153+ return true;
154+ }
143155
144156-- Pairs
145157
purescript.cabal+1−1
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.1.15
2+version: 0.1.16
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
src/Language/PureScript/Parser/Values.hs+21−14
@@ -86,10 +86,15 @@ parseIfThenElse = IfThenElse <$> (P.try (C.reserved "if") *> C.indented *> parse
8686 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
8787
8888parseBlock :: P.Parsec String ParseState Value
89−parseBlock = Block <$> (P.try (C.reserved "do") *> parseManyStatements)
89+parseBlock = Block <$> parseManyStatements
9090
9191parseManyStatements :: P.Parsec String ParseState [Statement]
92−parseManyStatements = C.indented *> C.mark (P.many (C.same *> C.mark parseStatement)) P.<?> "block"
92+parseManyStatements = (do
93+ C.lexeme $ P.char '{'
94+ C.indented
95+ sts <- C.mark (P.many (C.same *> C.mark parseStatement))
96+ C.lexeme (P.char '}')
97+ return sts) P.<?> "block"
9398
9499parseValueAtom :: P.Parsec String ParseState Value
95100parseValueAtom = C.indented *> P.choice
@@ -97,7 +102,7 @@ parseValueAtom = C.indented *> P.choice
97102 , P.try parseStringLiteral
98103 , P.try parseBooleanLiteral
99104 , parseArrayLiteral
100− , parseObjectLiteral
105+ , P.try parseObjectLiteral
101106 , parseAbs
102107 , P.try parseConstructor
103108 , P.try parseVar
@@ -143,6 +148,7 @@ parseVariableIntroduction = do
143148 name <- C.indented *> C.parseIdent
144149 C.lexeme $ C.indented *> P.char '='
145150 value <- parseValue
151+ C.indented *> C.semi
146152 return $ VariableIntroduction name value
147153
148154parseAssignment :: P.Parsec String ParseState Statement
@@ -150,21 +156,22 @@ parseAssignment = do
150156 tgt <- C.parseIdent
151157 C.lexeme $ C.indented *> P.char '='
152158 value <- parseValue
159+ C.indented *> C.semi
153160 return $ Assignment tgt value
154161
155162parseWhile :: P.Parsec String ParseState Statement
156−parseWhile = While <$> (C.reserved "while" *> C.indented *> parseValue <* C.indented <* C.colon)
157− <*> parseManyStatements
163+parseWhile = While <$> (C.reserved "while" *> C.indented *> C.parens parseValue)
164+ <*> (C.indented *> parseManyStatements)
158165
159166parseFor :: P.Parsec String ParseState Statement
160−parseFor = For <$> (C.reserved "for" *> C.indented *> C.parseIdent)
167+parseFor = For <$> (C.reserved "for" *> C.indented *> C.lexeme (P.char '(') *> C.indented *> C.parseIdent)
161168 <*> (C.indented *> C.lexeme (P.string "<-") *> parseValue)
162− <*> (C.indented *> C.reserved "until" *> parseValue <* C.indented <* C.colon)
169+ <*> (C.indented *> C.reserved "until" *> parseValue <* C.indented <* C.lexeme (P.char ')'))
163170 <*> parseManyStatements
164171
165172parseForEach :: P.Parsec String ParseState Statement
166−parseForEach = ForEach <$> (C.reserved "foreach" *> C.indented *> C.parseIdent)
167− <*> (C.indented *> C.reserved "in" *> parseValue <* C.indented <* C.colon)
173+parseForEach = ForEach <$> (C.reserved "foreach" *> C.indented *> C.lexeme (P.char '(') *> C.indented *> C.parseIdent)
174+ <*> (C.indented *> C.reserved "in" *> parseValue <* C.lexeme (P.char ')'))
168175 <*> parseManyStatements
169176
170177parseIf :: P.Parsec String ParseState Statement
@@ -172,16 +179,16 @@ parseIf = If <$> parseIfStatement
172179
173180parseIfStatement :: P.Parsec String ParseState IfStatement
174181parseIfStatement =
175− IfStatement <$> (C.reserved "if" *> C.indented *> parseValue <* C.indented <* C.colon)
182+ IfStatement <$> (C.reserved "if" *> C.indented *> C.parens parseValue)
176183 <*> parseManyStatements
177− <*> P.optionMaybe (C.same *> parseElseStatement)
184+ <*> P.optionMaybe parseElseStatement
178185
179186parseElseStatement :: P.Parsec String ParseState ElseStatement
180−parseElseStatement = C.reserved "else" >> (ElseIf <$> (C.indented *> parseIfStatement)
181− <|> Else <$> (C.indented *> C.colon *> parseManyStatements))
187+parseElseStatement = C.reserved "else" >> (ElseIf <$> parseIfStatement
188+ <|> Else <$> parseManyStatements)
182189
183190parseReturn :: P.Parsec String ParseState Statement
184−parseReturn = Return <$> (C.reserved "return" *> parseValue)
191+parseReturn = Return <$> (C.reserved "return" *> parseValue <* C.indented <* C.semi)
185192
186193parseStatement :: P.Parsec String ParseState Statement
187194parseStatement = P.choice (map P.try