Skip to content

Commit

Permalink
[FIX] Func call parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Tipbs committed Jan 14, 2024
1 parent 92e3907 commit 59a6231
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/KopeParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,25 @@ sepByP sep element = (:) <$> (ws *> element) <*> many (ws *> sep *> ws *> elemen
sepByEndP :: Parser a -> Parser b -> Parser [b]
sepByEndP sep element = many (ws *> element <* ws <* sep <* ws)

bodyP :: Parser KopeVal
bodyP = KopeArray <$> (charP '{' *> ws *> declaration <* ws <* charP '}')
bodyP :: Parser [KopeVal]
bodyP = charP '{' *> ws *> declaration <* ws <* charP '}'
where
declaration = sepByEndP (charP ';') kopeExpr

paramsP :: Parser KopeVal
paramsP = KopeArray <$> (ws *> charP '(' *> declaration <* charP ')' <* ws)
paramsP :: Parser [String]
paramsP = ws *> charP '(' *> declaration <* charP ')' <* ws
where
declaration = sepByP (charP ',') (KopeString <$> letterP)
declaration = sepByP (charP ',') letterP

nameP :: Parser KopeVal
nameP = KopeString <$> (stringP "fn" *> ws *> notNull letterP <* ws)
nameP :: Parser String
nameP = stringP "fn" *> ws *> notNull letterP <* ws

kopeFunc :: Parser KopeVal
kopeFunc = Parser $ \input -> do
(input', name) <- nameF input
(input'', params) <- paramsF input'
(input''', body) <- bodyF input''
Just (input''', KopeFunc (funcName name) (funcParams params) (funcBody body))
Just (input''', KopeFunc name params body)
where
Parser nameF = nameP
Parser paramsF = paramsP
Expand Down Expand Up @@ -135,15 +135,15 @@ kopeCond :: Parser KopeVal
kopeCond = KopeArray <$> pair
where
pair =
(\cond body -> [KopeAtom "if", cond, body]) <$>
(\cond body -> [KopeAtom "if", cond, KopeArray body]) <$>
(stringP "if" *> ws *> kopeTest <* ws) <*>
bodyP

kopeLoop :: Parser KopeVal
kopeLoop = KopeArray <$> pair
where
pair =
(\cond body -> [KopeAtom "while", cond, body]) <$>
(\cond body -> [KopeAtom "while", cond, KopeArray body]) <$>
(stringP "while" *> ws *> kopeTest <* ws) <*>
bodyP

Expand Down

0 comments on commit 59a6231

Please sign in to comment.