git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use ! for array indexing to avoid ambiguous syntax
commitb261a397baabedcaa2f7fc90309ac371b08799a5 authorPhil Freeman <paf31@cantab.net> dateThu 7 Nov 2013, 08:10 (13 years ago) parentcc21630
6 files changed+10−7
examples/failing/Arrays.ps+1 examples/passing/Arrays.ps+2 libraries/prelude/prelude.ps+2−2 src/Language/PureScript/Parser/Common.hs+1−1 src/Language/PureScript/Parser/Values.hs+1−1 src/Language/PureScript/Pretty/Values.hs+3−3
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]
1111test3 = \tree, sum -> case tree of
1212 One n -> n
1313 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
130130any :: forall a. (a -> Boolean) -> [a] -> Boolean
131131any = \p -> \as -> do
132132 for i <- 0 until length as:
133− if p as[i]:
133+ if p (as ! i):
134134 return true
135135 return false
136136
137137all :: forall a. (a -> Boolean) -> [a] -> Boolean
138138all = \p -> \as -> do
139139 for i <- 0 until length as:
140− if !(p as[i]):
140+ if !(p (as ! i)):
141141 return false
142142 return true
143143
src/Language/PureScript/Parser/Common.hs+1−1
@@ -74,7 +74,7 @@ reservedNames = [ "case"
7474
7575reservedOpNames :: [String]
7676reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
77− , "==", "!=", "&", "^", "|", "&&", "||", "->" ]
77+ , "==", "!=", "&", "^", "|", "&&", "||", "->", "!" ]
7878
7979identStart :: P.Parsec String u Char
8080identStart = P.lower <|> P.oneOf "_$"
src/Language/PureScript/Parser/Values.hs+1−1
@@ -125,7 +125,6 @@ parseValue = do
125125 where
126126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
127127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
128− , P.try $ Indexer <$> (C.indented *> C.squares parseValue)
129128 , P.try $ flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
130129 postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
131130 , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
@@ -137,6 +136,7 @@ parseValue = do
137136 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return id ]
138137 ] ++ customOperatorTable user ++
139138 [ [ 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 ]
140140 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
141141 , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]
142142 , [ 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
5959 match (Accessor prop val) = Just (prop, val)
6060 match _ = Nothing
6161
62−indexer :: Pattern Value (String, Value)
62+indexer :: Pattern Value (Value, Value)
6363indexer = Pattern $ A.Kleisli match
6464 where
65− match (Indexer index val) = Just (prettyPrintValue index, val)
65+ match (Indexer index val) = Just (index, val)
6666 match _ = Nothing
6767
6868objectUpdate :: Pattern Value ([String], Value)
@@ -109,11 +109,11 @@ prettyPrintValue = fromMaybe (error "Incomplete pattern") . pattern matchValue
109109 operators :: OperatorTable Value String
110110 operators =
111111 OperatorTable [ [ Wrap accessor $ \prop val -> val ++ "." ++ prop ]
112− , [ Wrap indexer $ \index val -> val ++ "[" ++ index ++ "]" ]
113112 , [ Wrap objectUpdate $ \ps val -> val ++ "{ " ++ intercalate ", " ps ++ " }" ]
114113 , [ Wrap app $ \args val -> val ++ "(" ++ args ++ ")" ]
115114 , [ Split lam $ \args val -> "\\" ++ intercalate ", " args ++ " -> " ++ prettyPrintValue val ]
116115 , [ Wrap ifThenElse $ \(th, el) cond -> cond ++ " ? " ++ prettyPrintValue th ++ " : " ++ prettyPrintValue el ]
116+ , [ AssocR indexer (\index val -> val ++ " ! " ++ index) ]
117117 , [ binary LessThan "<" ]
118118 , [ binary LessThanOrEqualTo "<=" ]
119119 , [ binary GreaterThan ">" ]