🖨️ Half a printing function (does not work)

This commit is contained in:
2024-09-26 16:55:57 +02:00
parent dd66ba3d7b
commit b399cbec6e
2 changed files with 16 additions and 2 deletions

View File

@ -49,6 +49,10 @@ lVName = lexeme $ try $ do
then fail "Unexpected keyword"
else pure v
lStringLit :: Parser String
lStringLit =
lexeme $ read <$> some (satisfy isAlpha) <* notFollowedBy (satisfy isAlphaNum)
lInteger :: Parser Integer
lInteger =
lexeme $ read <$> some (satisfy isDigit) <* notFollowedBy (satisfy isAlphaNum)
@ -66,6 +70,10 @@ lBool =
const False <$> lKeyword "false"
]
pStringLit :: Parser String
pStringLit =
lString "\"" *> lStringLit <* lString "\""
pAtom :: Parser Exp
pAtom =
choice
@ -93,6 +101,9 @@ pLExp =
<$> (lKeyword "if" *> pExp)
<*> (lKeyword "then" *> pExp)
<*> (lKeyword "else" *> pExp),
Print
<$> (lKeyword "print" *> pStringLit)
<*> pExp,
pFExp
]
@ -101,8 +112,7 @@ pPExp = pLExp >>= chain
where
chain x =
choice
[
do
[ do
lString "**"
y <- pPExp
chain $ Pow x y,

View File

@ -82,5 +82,9 @@ tests =
[ parserTest "x ** y" $ Pow (Var "x") (Var "y"),
parserTest "x ** y ** z" $ Pow (Var "x") (Pow (Var "y") (Var "z")),
parserTest "x + y ** z * x" $ Add (Var "x") (Mul (Pow (Var "y") (Var "z")) (Var "x"))
],
testGroup
"Print"
[ parserTest "print \"test\" y" $ Print "test" (Var "y")
]
]