AST testing
This commit is contained in:
@@ -574,20 +574,15 @@ begin
|
||||
end
|
||||
else if SameText(head.Token.Text, 'def') then
|
||||
begin
|
||||
// Validate argument count for 'def' special form.
|
||||
// Identifier check removed to support macros (e.g. def ~x 1)
|
||||
if not (Length(tailNodes) in [1, 2]) then
|
||||
raise Exception.CreateFmt(
|
||||
'Syntax Error: ''def'' requires an identifier and an optional initializer (1 or 2 arguments), but got %d.',
|
||||
[Length(tailNodes)]);
|
||||
|
||||
if tailTokens[0].Kind <> tkIdentifier then
|
||||
raise Exception.Create('Syntax Error: Expected an identifier for def statement.');
|
||||
raise Exception.CreateFmt('Syntax Error: ''def'' requires a target and an optional initializer.', []);
|
||||
|
||||
initializer := nil;
|
||||
if Length(tailNodes) = 2 then
|
||||
initializer := tailNodes[1];
|
||||
|
||||
Result := TAst.VarDecl(IIdentifierNode(tailNodes[0]), initializer);
|
||||
Result := TAst.VarDecl(tailNodes[0], initializer);
|
||||
end
|
||||
else if SameText(head.Token.Text, 'defmacro') then
|
||||
begin
|
||||
@@ -606,11 +601,11 @@ begin
|
||||
end
|
||||
else if SameText(head.Token.Text, 'assign') then
|
||||
begin
|
||||
// Identifier check removed
|
||||
if Length(tailNodes) <> 2 then
|
||||
raise Exception.Create('Syntax Error: ''assign'' requires exactly 2 arguments (identifier and value).');
|
||||
if tailTokens[0].Kind <> tkIdentifier then
|
||||
raise Exception.Create('Syntax Error: Expected an identifier for assignment.');
|
||||
Result := TAst.Assign(IIdentifierNode(tailNodes[0]), tailNodes[1]);
|
||||
raise Exception.Create('Syntax Error: ''assign'' requires exactly 2 arguments (target and value).');
|
||||
|
||||
Result := TAst.Assign(tailNodes[0], tailNodes[1]);
|
||||
end
|
||||
else if SameText(head.Token.Text, 'fn') then
|
||||
begin
|
||||
@@ -988,7 +983,7 @@ end;
|
||||
procedure TPrettyPrintVisitor.VisitVariableDeclaration(const Node: IVariableDeclarationNode);
|
||||
begin
|
||||
Append('(def ');
|
||||
Node.Identifier.Accept(Self);
|
||||
Node.Target.Accept(Self);
|
||||
if Assigned(Node.Initializer) then
|
||||
begin
|
||||
Append(' ');
|
||||
@@ -1000,7 +995,7 @@ end;
|
||||
procedure TPrettyPrintVisitor.VisitAssignment(const Node: IAssignmentNode);
|
||||
begin
|
||||
Append('(assign ');
|
||||
Node.Identifier.Accept(Self);
|
||||
Node.Target.Accept(Self);
|
||||
Append(' ');
|
||||
Node.Value.Accept(Self);
|
||||
Append(')');
|
||||
|
||||
Reference in New Issue
Block a user