From 0d4ed473c520786af90ab70dac51451ea2b8b941 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 5 Jun 2019 22:12:52 +0100 Subject: [PATCH] Tidy up the parsing a bit The Text.ParserCombinators.ReadPrec/Text.ParserCominators.ReadP split adds a bit of lifting cruft, so lets try to sweep that away. --- AST.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/AST.hs b/AST.hs index 1e505af..ae18a52 100644 --- a/AST.hs +++ b/AST.hs @@ -30,10 +30,7 @@ instance Read Expr where parseVar = Var <$> lift (munch1 isAlpha) parseBinOp s prc op = prec prc $ do a <- step readPrec - lift $ do - skipSpaces - string s - skipSpaces + spaced $ string s b <- readPrec return (BinOp op a b) parseCall = do @@ -43,13 +40,14 @@ instance Read Expr where (skipSpaces >> char ',' >> skipSpaces) return (Call func params) parseIf = do - lift $ skipSpaces >> string "if" >> skipSpaces + spaced $ string "if" cond <- readPrec - lift $ skipSpaces >> string "then" >> skipSpaces + spaced $ string "then" thenE <- readPrec - lift $ skipSpaces >> string "else" >> skipSpaces + spaced $ string "else" elseE <- readPrec return (If cond thenE elseE) + spaced f = lift $ skipSpaces >> f >> skipSpaces data Prototype = Prototype String [String] deriving Show -- 2.30.2