X-Git-Url: http://git.lukelau.me/?p=timetravel.git;a=blobdiff_plain;f=AST.hs;fp=AST.hs;h=4aac7689685a883b0be2db62f32a9163423fedad;hp=cf1fc409c70e16b5754a9f4d1d2274ca51e8f92f;hb=00b953eca8f8cdb1e39cf37c14c3705af3fc1afe;hpb=9a09a1be54afb5e15dfea8a8676bd6e1941b37ec diff --git a/AST.hs b/AST.hs index cf1fc40..4aac768 100644 --- a/AST.hs +++ b/AST.hs @@ -40,7 +40,7 @@ instance Show Expr where instance Read Expr where readPrec = lift pExpr where - pExpr = pVar +++ pLit +++ pBinOp + pExpr = (pLit <++ pVar) +++ pBinOp pBrackets = between (char '(') (char ')') pVar = Var <$> munch1 isLetter @@ -50,11 +50,11 @@ instance Read Expr where pBinOp = do -- TODO: figure out how to just use pExpr without getting -- stuck recursively - e1 <- pVar +++ pLit +++ pBrackets pBinOp + e1 <- (pLit <++ pVar) +++ pBrackets pBinOp skipSpaces op <- pOp skipSpaces - e2 <- pVar +++ pLit +++ pBrackets pBinOp + e2 <- (pLit <++ pVar) +++ pBrackets pBinOp return (op e1 e2) pOp = choice @@ -80,5 +80,5 @@ data Statement = Assign String Expr | Seq Statement Statement | Try Statement Statement | Pass - deriving (Eq, Show) + deriving (Eq, Show, Read)