Fixed parser error in fn def

This commit is contained in:
Michael Schimmel
2025-09-29 11:41:01 +02:00
parent e1a46da6f8
commit 823ea0e8f1
+8 -1
View File
@@ -348,7 +348,14 @@ begin
Result := TAst.Assign(IIdentifierNode(tailNodes[0]), tailNodes[1]);
end
else if SameText(head.Token.Text, 'fn') then
Result := TAst.LambdaExpr(elements[High(tailNodes)].Params, tailNodes[1])
begin
// Corrected handling for lambda expressions
if Length(tailNodes) <> 2 then
raise Exception.Create('Syntax Error: ''fn'' requires a parameter list and a body.');
if elements[1].Node <> nil then
raise Exception.Create('Syntax Error: Expected a parameter list [...] after ''fn''.');
Result := TAst.LambdaExpr(elements[1].Params, tailNodes[1]);
end
else if SameText(head.Token.Text, 'do') then
Result := TAst.Block(tailNodes)
else if SameText(head.Token.Text, 'recur') then