git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #285
b66d0f5Phil Freeman
examples/passing/Operators.purs+4
@@ -57,6 +57,9 @@ module Operators2 where
57 test14 :: Number -> Number -> Boolean
57 test14 :: Number -> Number -> Boolean
58 test14 a b = a < b
58 test14 a b = a < b
59
59
60+ test15 :: Number -> Number -> Boolean
61+ test15 a b = const false $ a `test14` b
62+
60module Main where
63module Main where
61
64
62import Operators1
65import Operators1
@@ -83,4 +86,5 @@ main =
83 , show (test12 k 1 2)
86 , show (test12 k 1 2)
84 , show (test13 k 1 2)
87 , show (test13 k 1 2)
85 , show (test14 1 2)
88 , show (test14 1 2)
89+ , show (test15 1 2)
86 ]
90 ]
src/Language/PureScript/Sugar/Operators.hs+19−5
@@ -17,7 +17,7 @@
17--
17--
18-----------------------------------------------------------------------------
18-----------------------------------------------------------------------------
19
19
20−{-# LANGUAGE Rank2Types #-}
20+{-# LANGUAGE Rank2Types, FlexibleContexts #-}
21
21
22module Language.PureScript.Sugar.Operators (
22module Language.PureScript.Sugar.Operators (
23 rebracket
23 rebracket
@@ -32,6 +32,7 @@ import Control.Arrow (first)
32import Control.Monad.State
32import Control.Monad.State
33
33
34import Data.Function (on)
34import Data.Function (on)
35+import Data.Functor.Identity
35import Data.List (groupBy, sortBy)
36import Data.List (groupBy, sortBy)
36
37
37import qualified Data.Map as M
38import qualified Data.Map as M
@@ -86,18 +87,31 @@ matchOperators moduleName ops = G.everywhereM' (G.mkM parseChains)
86 extendChain other = [Left other]
87 extendChain other = [Left other]
87 bracketChain :: Chain -> Either String Value
88 bracketChain :: Chain -> Either String Value
88 bracketChain = either (Left . show) Right . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
89 bracketChain = either (Left . show) Right . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
90+ opTable = [P.Infix (P.try (parseTicks >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft]
89− opTable = map (map (\(name, f, a) -> P.Infix (P.try (matchOp moduleName name) >> return f) (toAssoc a))) ops
91+ : map (map (\(name, f, a) -> P.Infix (P.try (matchOp moduleName name) >> return f) (toAssoc a))) ops
90− ++ [[P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft]]
92+ ++ [[ P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft ]]
91
93
92toAssoc :: Associativity -> P.Assoc
94toAssoc :: Associativity -> P.Assoc
93toAssoc Infixl = P.AssocLeft
95toAssoc Infixl = P.AssocLeft
94toAssoc Infixr = P.AssocRight
96toAssoc Infixr = P.AssocRight
95
97
98+token :: (P.Stream s Identity t, Show t) => (t -> Maybe a) -> P.Parsec s u a
99+token = P.token show (const (P.initialPos ""))
100+
96parseValue :: P.Parsec Chain () Value
101parseValue :: P.Parsec Chain () Value
97−parseValue = P.token show (const (P.initialPos "")) (either Just (const Nothing)) P.<?> "expression"
102+parseValue = token (either Just (const Nothing)) P.<?> "expression"
98
103
99parseOp :: P.Parsec Chain () (Qualified Ident)
104parseOp :: P.Parsec Chain () (Qualified Ident)
100−parseOp = P.token show (const (P.initialPos "")) (either (const Nothing) Just) P.<?> "operator"
105+parseOp = token (either (const Nothing) fromOp) P.<?> "operator"
106+ where
107+ fromOp q@(Qualified _ (Op _)) = Just q
108+ fromOp _ = Nothing
109+
110+parseTicks :: P.Parsec Chain () (Qualified Ident)
111+parseTicks = token (either (const Nothing) fromOp) P.<?> "infix function"
112+ where
113+ fromOp q@(Qualified _ (Ident _)) = Just q
114+ fromOp _ = Nothing
101
115
102matchOp :: ModuleName -> Qualified Ident -> P.Parsec Chain () ()
116matchOp :: ModuleName -> Qualified Ident -> P.Parsec Chain () ()
103matchOp moduleName op = do
117matchOp moduleName op = do