🎃 Function application
This commit is contained in:
1
a3/a3-handout/.gitignore
vendored
Normal file
1
a3/a3-handout/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dist-newstyle
|
@ -75,6 +75,17 @@ pAtom =
|
|||||||
lString "(" *> pExp <* lString ")"
|
lString "(" *> pExp <* lString ")"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
pFExp :: Parser Exp
|
||||||
|
pFExp = pAtom >>= chain
|
||||||
|
where
|
||||||
|
chain x =
|
||||||
|
choice
|
||||||
|
[ do
|
||||||
|
y <- pAtom
|
||||||
|
chain $ Apply x y,
|
||||||
|
pure x
|
||||||
|
]
|
||||||
|
|
||||||
pLExp :: Parser Exp
|
pLExp :: Parser Exp
|
||||||
pLExp =
|
pLExp =
|
||||||
choice
|
choice
|
||||||
@ -82,7 +93,7 @@ pLExp =
|
|||||||
<$> (lKeyword "if" *> pExp)
|
<$> (lKeyword "if" *> pExp)
|
||||||
<*> (lKeyword "then" *> pExp)
|
<*> (lKeyword "then" *> pExp)
|
||||||
<*> (lKeyword "else" *> pExp),
|
<*> (lKeyword "else" *> pExp),
|
||||||
pAtom
|
pFExp
|
||||||
]
|
]
|
||||||
|
|
||||||
pExp1 :: Parser Exp
|
pExp1 :: Parser Exp
|
||||||
|
@ -64,5 +64,11 @@ tests =
|
|||||||
"Lexing edge cases"
|
"Lexing edge cases"
|
||||||
[ parserTest "2 " $ CstInt 2,
|
[ parserTest "2 " $ CstInt 2,
|
||||||
parserTest " 2" $ CstInt 2
|
parserTest " 2" $ CstInt 2
|
||||||
|
],
|
||||||
|
testGroup
|
||||||
|
"FExp"
|
||||||
|
[ parserTest "x y" $ Apply (Var "x") (Var "y"),
|
||||||
|
parserTest "x y z" $ Apply (Apply (Var "x") (Var "y")) (Var "z"),
|
||||||
|
parserTest "x (y z)" $ Apply (Var "x") (Apply (Var "y") (Var "z"))
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user