From: pimjager Date: Fri, 11 Mar 2016 15:38:39 +0000 (+0100) Subject: Rewrote some LiftM's to <$> and <*> for clarity X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=80bcdf651a056b8993e042b57b4295550e8566bb;p=cc1516.git Rewrote some LiftM's to <$> and <*> for clarity --- diff --git a/AST.dcl b/AST.dcl index 340aec6..e0687c3 100644 --- a/AST.dcl +++ b/AST.dcl @@ -30,6 +30,7 @@ from StdOverloaded import class toString :: Op1 = UnNegation | UnMinus :: Op2 = BiPlus | BiMinus | BiTimes | BiDivide | BiMod | BiEquals | BiLesser | BiGreater | BiLesserEq | BiGreaterEq | BiUnEqual | BiAnd | BiOr | BiCons + :: FunDecl = FunDecl String [String] (Maybe FunType) [VarDecl] [Stmt] :: FunType = FunType [Type] (Maybe Type) :: FunCall = FunCall String [Expr] diff --git a/parse.icl b/parse.icl index 24b860b..dfb0708 100644 --- a/parse.icl +++ b/parse.icl @@ -6,6 +6,7 @@ import StdList from StdFunc import const, o import Data.Either import Data.Maybe +import Data.Functor import Control.Monad import Control.Applicative import Data.Func @@ -46,7 +47,7 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> parseAssStmt :: Parser Token Stmt parseAssStmt = - liftM2 AssStmt (parseVarDef <* satTok AssignmentToken) parseExpr + AssStmt <$> (parseVarDef <* satTok AssignmentToken) <*> parseExpr parseIfStmt :: Parser Token Stmt parseIfStmt = liftM3 IfStmt @@ -57,26 +58,25 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> parseWhileStmt :: Parser Token Stmt parseWhileStmt = satTok WhileToken *> - liftM2 WhileStmt (parseBBraces parseExpr) parseBlock + (WhileStmt <$> (parseBBraces parseExpr) <*> parseBlock) parseBlock :: Parser Token [Stmt] parseBlock = parseBCBraces (many parseStmt) parseOneLine :: Parser Token [Stmt] //first pure makes singleton list from the statement - parseOneLine = liftM pure parseStmt + parseOneLine = pure <$> parseStmt parseFunType :: Parser Token FunType parseFunType = satTok DoubleColonToken *> - (parseInOutType <|> (liftM (FunType []) parseVoidOrType)) + (parseInOutType <|> ((FunType []) <$> parseVoidOrType)) where parseInOutType :: Parser Token FunType - parseInOutType = liftM2 FunType - (some parseType <* satTok ArrowToken) parseVoidOrType + parseInOutType = FunType <$> (some parseType <* satTok ArrowToken) <*> parseVoidOrType parseVoidOrType :: Parser Token (Maybe Type) parseVoidOrType = (satTok VoidToken *> pure Nothing) <|> - (liftM Just parseType) <|> pure Nothing + (Just <$> parseType) <|> pure Nothing parseVarDecl :: Parser Token VarDecl parseVarDecl = liftM3 VarDecl @@ -89,9 +89,9 @@ parseType = trans1 IntTypeToken IntType <|> trans1 CharTypeToken CharType <|> trans1 BoolTypeToken BoolType <|> - (liftM ListType (parseBSqBraces parseType)) <|> - (liftM TupleType (parseTuple parseType)) <|> - (liftM IdType parseIdent) + (ListType <$> (parseBSqBraces parseType)) <|> + (TupleType <$> (parseTuple parseType)) <|> + (IdType <$> parseIdent) parseExpr :: Parser Token Expr parseExpr = //Operators in order of binding strength @@ -122,20 +122,19 @@ parseExpr = //Operators in order of binding strength parseBasicExpr :: Parser Token Expr parseBasicExpr = - (liftM TupleExpr (parseTuple parseExpr)) <|> - (liftM FunExpr parseFunCall) <|> + (TupleExpr <$> (parseTuple parseExpr)) <|> + (FunExpr <$> parseFunCall) <|> parseBBraces parseExpr <|> trans1 EmptyListToken EmptyListExpr <|> trans1 TrueToken (BoolExpr True) <|> trans1 FalseToken (BoolExpr False) <|> trans2 (NumberToken zero) (\(NumberToken i)->IntExpr i) <|> trans2 (CharToken zero) (\(CharToken c)->CharExpr c) <|> - (liftM2 Op1Expr parseOp1 parseExpr) <|> - (liftM VarExpr parseVarDef) + (Op1Expr <$> parseOp1 <*> parseExpr) <|> + (VarExpr <$> parseVarDef) parseFunCall :: Parser Token FunCall -parseFunCall = liftM2 FunCall - parseIdent (parseBBraces $ parseSepList CommaToken parseExpr) +parseFunCall = FunCall <$> parseIdent <*> (parseBBraces $ parseSepList CommaToken parseExpr) parseVarDef :: Parser Token VarDef parseVarDef = liftM2 VarDef @@ -164,7 +163,7 @@ parseTuple p = satTok BraceOpenToken *> <* satTok BraceCloseToken trans2 :: TokenValue (TokenValue -> a) -> Parser Token a -trans2 t f = liftM (\(_,token)->f token) $ satTok t +trans2 t f = (\(_,token)->f token) <$> satTok t trans1 :: TokenValue a -> Parser Token a trans1 t r = trans2 t $ const r diff --git a/spl.prj b/spl.prj index 1f2a0a9..b0e9413 100644 --- a/spl.prj +++ b/spl.prj @@ -618,7 +618,7 @@ OtherModules Fusion: False Module Name: System.OS - Dir: {Application}/lib/clean-platform/OS-Linux-64 + Dir: {Application}/lib/clean-platform/OS-Mac Compiler NeverMemoryProfile: False NeverTimeProfile: False