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

View File

@ -82,5 +82,9 @@ tests =
[ parserTest "x ** y" $ Pow (Var "x") (Var "y"), [ parserTest "x ** y" $ Pow (Var "x") (Var "y"),
parserTest "x ** y ** z" $ Pow (Var "x") (Pow (Var "y") (Var "z")), 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")) 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")
] ]
] ]