from StdFunc import const, o
import Data.Either
import Data.Maybe
+import Data.Functor
import Control.Monad
import Control.Applicative
import Data.Func
parseAssStmt :: Parser Token Stmt
parseAssStmt =
- liftM2 AssStmt (parseVarDef <* satTok AssignmentToken) parseExpr
+ AssStmt <$> (parseVarDef <* satTok AssignmentToken) <*> parseExpr
parseIfStmt :: Parser Token Stmt
parseIfStmt = liftM3 IfStmt
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
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
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
<* 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