git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Operator sections
commit2099d51c8e274b34dd4436e05518ed307d0d2184 authorGary Burgess <gary.burgess@gmail.com> dateSat 7 Feb 2015, 23:10 (12 years ago) parent3157b33
4 files changed+29−2
src/Language/PureScript/AST/Declarations.hs+5 src/Language/PureScript/Parser/Declarations.hs+7 src/Language/PureScript/Sugar.hs+4−1 src/Language/PureScript/Sugar/Operators.hs+13−1
src/Language/PureScript/AST/Declarations.hs+5
@@ -312,6 +312,11 @@ data Expr
312312 --
313313 | Parens Expr
314314 -- |
315+ -- Operator section. This will be removed during desugaring and replaced with a partially applied
316+ -- operator or lambda to flip the arguments.
317+ --
318+ | OperatorSection (Qualified Ident) (Either Expr Expr)
319+ -- |
315320 -- An array literal
316321 --
317322 | ArrayLiteral [Expr]
src/Language/PureScript/Parser/Declarations.hs+7
@@ -353,8 +353,15 @@ parseValueAtom = P.choice
353353 , parseIfThenElse
354354 , parseDo
355355 , parseLet
356+ , P.try parseOperatorSection
356357 , Parens <$> parens parseValue ]
357358
359+parseOperatorSection :: TokenParser Expr
360+parseOperatorSection = parens $ left <|> right
361+ where
362+ right = OperatorSection <$> parseIdentInfix <* indented <*> (Right <$> parseValueAtom)
363+ left = flip OperatorSection <$> (Left <$> parseValueAtom) <* indented <*> parseIdentInfix
364+
358365parsePropertyUpdate :: TokenParser (String, Maybe Expr)
359366parsePropertyUpdate = do
360367 name <- lname <|> stringLiteral
src/Language/PureScript/Sugar.hs+4−1
@@ -37,7 +37,9 @@ import Language.PureScript.Sugar.TypeDeclarations as S
3737--
3838-- * Remove signed literals in favour of `negate` applications
3939--
40−-- * Desguar object literals with wildcards into lambdas
40+-- * Desugar object literals with wildcards into lambdas
41+--
42+-- * Desugar operator sections
4143--
4244-- * Desugar do-notation using the @Prelude.Monad@ type class
4345--
@@ -56,6 +58,7 @@ import Language.PureScript.Sugar.TypeDeclarations as S
5658desugar :: [Module] -> SupplyT (Either ErrorStack) [Module]
5759desugar = map removeSignedLiterals
5860 >>> map desugarObjectConstructors
61+ >>> map desugarOperatorSections
5962 >>> mapM desugarDoModule
6063 >=> desugarCasesModule
6164 >=> lift . (desugarTypeDeclarationsModule
src/Language/PureScript/Sugar/Operators.hs+13−1
@@ -21,7 +21,8 @@
2121
2222module Language.PureScript.Sugar.Operators (
2323 rebracket,
24− removeSignedLiterals
24+ removeSignedLiterals,
25+ desugarOperatorSections
2526) where
2627
2728import Language.PureScript.Names
@@ -148,3 +149,14 @@ matchOp op = do
148149 ident <- parseOp
149150 guard $ ident == op
150151
152+desugarOperatorSections :: Module -> Module
153+desugarOperatorSections (Module mn ds exts) = Module mn (map goDecl ds) exts
154+ where
155+
156+ goDecl :: Declaration -> Declaration
157+ (goDecl, _, _) = everywhereOnValues id goExpr id
158+
159+ goExpr :: Expr -> Expr
160+ goExpr (OperatorSection op (Left val)) = App (Var op) val
161+ goExpr (OperatorSection op (Right val)) = Abs (Left $ Ident "_lhs") $ App (App (Var op) (Var (Qualified Nothing (Ident "_lhs")))) val
162+ goExpr other = other