projects
/
kaleidoscope-hs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tidy up the parsing a bit
[kaleidoscope-hs.git]
/
AST.hs
diff --git
a/AST.hs
b/AST.hs
index 1e505af4f47116e401e2523f10c90ac1c466c360..ae18a52347ce91c37336a06f891bae690ba691ec 100644
(file)
--- 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
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
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
(skipSpaces >> char ',' >> skipSpaces)
return (Call func params)
parseIf = do
- lift $ skipSpaces >> string "if" >> skipSpaces
+ spaced $ string "if"
cond <- readPrec
cond <- readPrec
- lift $ skipSpaces >> string "then" >> skipSpaces
+ spaced $ string "then"
thenE <- readPrec
thenE <- readPrec
- lift $ skipSpaces >> string "else" >> skipSpaces
+ spaced $ string "else"
elseE <- readPrec
return (If cond thenE elseE)
elseE <- readPrec
return (If cond thenE elseE)
+ spaced f = lift $ skipSpaces >> f >> skipSpaces
data Prototype = Prototype String [String]
deriving Show
data Prototype = Prototype String [String]
deriving Show