git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use ! for array indexing to avoid ambiguous syntax
b261a39Phil Freeman
examples/failing/Arrays.psnew file+1
@@ -0,0 +1 @@
1+test = \arr -> arr ! 0 ! 0
examples/passing/Arrays.ps+2
@@ -11,3 +11,5 @@ data Tree = One Number | Some [Tree]
11test3 = \tree, sum -> case tree of
11test3 = \tree, sum -> case tree of
12 One n -> n
12 One n -> n
13 Some [n1, n2 : rest] -> test3(n1, sum) * 10 + test3(n2, sum) * 5 + sum(rest)
13 Some [n1, n2 : rest] -> test3(n1, sum) * 10 + test3(n2, sum) * 5 + sum(rest)
14+
15+test4 = \arr -> arr ! 0 + arr ! 1
libraries/prelude/prelude.ps+2−2
@@ -130,14 +130,14 @@ zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
130any :: forall a. (a -> Boolean) -> [a] -> Boolean
130any :: forall a. (a -> Boolean) -> [a] -> Boolean
131any = \p -> \as -> do
131any = \p -> \as -> do
132 for i <- 0 until length as:
132 for i <- 0 until length as:
133− if p as[i]:
133+ if p (as ! i):
134 return true
134 return true
135 return false
135 return false
136
136
137all :: forall a. (a -> Boolean) -> [a] -> Boolean
137all :: forall a. (a -> Boolean) -> [a] -> Boolean
138all = \p -> \as -> do
138all = \p -> \as -> do
139 for i <- 0 until length as:
139 for i <- 0 until length as:
140− if !(p as[i]):
140+ if !(p (as ! i)):
141 return false
141 return false
142 return true
142 return true
143
143
src/Language/PureScript/Parser/Common.hs+1−1
@@ -74,7 +74,7 @@ reservedNames = [ "case"
74
74
75reservedOpNames :: [String]
75reservedOpNames :: [String]
76reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
76reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
77− , "==", "!=", "&", "^", "|", "&&", "||", "->" ]
77+ , "==", "!=", "&", "^", "|", "&&", "||", "->", "!" ]
78
78
79identStart :: P.Parsec String u Char
79identStart :: P.Parsec String u Char
80identStart = P.lower <|> P.oneOf "_$"
80identStart = P.lower <|> P.oneOf "_$"
src/Language/PureScript/Parser/Values.hs+1−1
@@ -125,7 +125,6 @@ parseValue = do
125 where
125 where
126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
128− , P.try $ Indexer <$> (C.indented *> C.squares parseValue)
129 , P.try $ flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
128 , P.try $ flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
130 postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
129 postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
131 , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
130 , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
@@ -137,6 +136,7 @@ parseValue = do
137 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return id ]
136 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return id ]
138 ] ++ customOperatorTable user ++
137 ] ++ customOperatorTable user ++
139 [ [ Infix (C.lexeme (P.try (C.indented *> C.parseIdentInfix P.<?> "operator") >>= \ident -> return $ \t1 t2 -> App (App (Var ident) [t1]) [t2])) AssocLeft ]
138 [ [ Infix (C.lexeme (P.try (C.indented *> C.parseIdentInfix P.<?> "operator") >>= \ident -> return $ \t1 t2 -> App (App (Var ident) [t1]) [t2])) AssocLeft ]
139+ , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (flip Indexer)) AssocRight ]
140 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
140 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
141 , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]
141 , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]
142 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<") >> return (Binary LessThan)) AssocRight
142 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<") >> return (Binary LessThan)) AssocRight
src/Language/PureScript/Pretty/Values.hs+3−3
@@ -59,10 +59,10 @@ accessor = Pattern $ A.Kleisli match
59 match (Accessor prop val) = Just (prop, val)
59 match (Accessor prop val) = Just (prop, val)
60 match _ = Nothing
60 match _ = Nothing
61
61
62−indexer :: Pattern Value (String, Value)
62+indexer :: Pattern Value (Value, Value)
63indexer = Pattern $ A.Kleisli match
63indexer = Pattern $ A.Kleisli match
64 where
64 where
65− match (Indexer index val) = Just (prettyPrintValue index, val)
65+ match (Indexer index val) = Just (index, val)
66 match _ = Nothing
66 match _ = Nothing
67
67
68objectUpdate :: Pattern Value ([String], Value)
68objectUpdate :: Pattern Value ([String], Value)
@@ -109,11 +109,11 @@ prettyPrintValue = fromMaybe (error "Incomplete pattern") . pattern matchValue
109 operators :: OperatorTable Value String
109 operators :: OperatorTable Value String
110 operators =
110 operators =
111 OperatorTable [ [ Wrap accessor $ \prop val -> val ++ "." ++ prop ]
111 OperatorTable [ [ Wrap accessor $ \prop val -> val ++ "." ++ prop ]
112− , [ Wrap indexer $ \index val -> val ++ "[" ++ index ++ "]" ]
113 , [ Wrap objectUpdate $ \ps val -> val ++ "{ " ++ intercalate ", " ps ++ " }" ]
112 , [ Wrap objectUpdate $ \ps val -> val ++ "{ " ++ intercalate ", " ps ++ " }" ]
114 , [ Wrap app $ \args val -> val ++ "(" ++ args ++ ")" ]
113 , [ Wrap app $ \args val -> val ++ "(" ++ args ++ ")" ]
115 , [ Split lam $ \args val -> "\\" ++ intercalate ", " args ++ " -> " ++ prettyPrintValue val ]
114 , [ Split lam $ \args val -> "\\" ++ intercalate ", " args ++ " -> " ++ prettyPrintValue val ]
116 , [ Wrap ifThenElse $ \(th, el) cond -> cond ++ " ? " ++ prettyPrintValue th ++ " : " ++ prettyPrintValue el ]
115 , [ Wrap ifThenElse $ \(th, el) cond -> cond ++ " ? " ++ prettyPrintValue th ++ " : " ++ prettyPrintValue el ]
116+ , [ AssocR indexer (\index val -> val ++ " ! " ++ index) ]
117 , [ binary LessThan "<" ]
117 , [ binary LessThan "<" ]
118 , [ binary LessThanOrEqualTo "<=" ]
118 , [ binary LessThanOrEqualTo "<=" ]
119 , [ binary GreaterThan ">" ]
119 , [ binary GreaterThan ">" ]