🖨️ Half a printing function (does not work)
This commit is contained in:
@ -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,
|
||||
|
@ -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")
|
||||
]
|
||||
]
|
||||
|
Reference in New Issue
Block a user