Skip to content

Commit 1b8711d

Browse files
committed
(#801) Fix Expr parser
1 parent 43889e7 commit 1b8711d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/Bot/Expr.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ sepBy element sep = do
6565
args <- many (sep >> element)
6666
return (arg : args)
6767

68+
funcallarg :: Parser Expr
69+
funcallarg = funcall <|> var <|> stringLiteral
70+
6871
funcall :: Parser Expr
6972
funcall = do
7073
_ <- charP '%' >> whitespaces
7174
name <- symbol
7275
_ <- whitespaces >> charP '(' >> whitespaces
7376
args <-
74-
sepBy (funcall <|> var <|> stringLiteral) (whitespaces >> charP ',') <|>
75-
return []
77+
sepBy funcallarg (whitespaces >> charP ',' >> whitespaces) <|> return []
7678
_ <- whitespaces >> charP ')'
7779
return $ FunCallExpr name args
7880

test/Bot/ExprTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ exprsTest =
5252
, TextExpr " baz ()"
5353
]))
5454
, ("%f(%x)", Right ("", [FunCallExpr "f" [VarExpr "x"]]))
55+
, ("%f(%x, %y)", Right ("", [FunCallExpr "f" [VarExpr "x", VarExpr "y"]]))
5556
, ( "\"hello %x world\""
5657
, Right ("", [TextExpr "\"hello ", VarExpr "x", TextExpr " world\""]))
5758
]

0 commit comments

Comments
 (0)