Skip to content

Commit

Permalink
Make parser properly parse function definitions with 0 parameters (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rockofox committed Dec 7, 2024
1 parent 54346cf commit e1fbd95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ defArg = try structLit <|> var <|> parens listPattern <|> array <|> placeholder
funcDef :: Parser Expr
funcDef = do
name <- identifier <|> gravis <?> "function name"
args <- some defArg <?> "function arguments"
args <- many defArg <?> "function arguments"
symbol "="
FuncDef name args <$> expr <?> "function body"

Expand Down
9 changes: 9 additions & 0 deletions tests/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ parserCompilerFlags = initCompilerFlags{needsMain = False}

spec :: Spec
spec = do
describe "Function definitions" $ do
it "Should parse a simple function" $
parseProgram "add a b = a + b" parserCompilerFlags
`shouldBe` Right
(Program [FuncDef{name = "add", args = [Var "a" anyPosition, Var "b" anyPosition], body = Add (Var "a" anyPosition) (Var "b" anyPosition)}])
it "Should prase a function with 0 parameters" $
parseProgram "thunk = 1" parserCompilerFlags
`shouldBe` Right
(Program [FuncDef{name = "thunk", args = [], body = IntLit 1}])
describe "compareTypes" $ do
it "Should be true for exact matches" $
property $
Expand Down

0 comments on commit e1fbd95

Please sign in to comment.