RECUR keyword added
This commit is contained in:
@@ -41,6 +41,7 @@ type
|
||||
function JsonToTernaryExprNode(const AObj: TJSONObject): ITernaryExpressionNode;
|
||||
function JsonToLambdaExprNode(const AObj: TJSONObject): ILambdaExpressionNode;
|
||||
function JsonToFunctionCallNode(const AObj: TJSONObject): IFunctionCallNode;
|
||||
function JsonToRecurNode(const AObj: TJSONObject): IRecurNode;
|
||||
function JsonToBlockNode(const AObj: TJSONObject): IBlockExpressionNode;
|
||||
function JsonToVarDeclNode(const AObj: TJSONObject): IVariableDeclarationNode;
|
||||
function JsonToAssignmentNode(const AObj: TJSONObject): IAssignmentNode;
|
||||
@@ -59,6 +60,7 @@ type
|
||||
function VisitTernaryExpression(const Node: ITernaryExpressionNode): TDataValue;
|
||||
function VisitLambdaExpression(const Node: ILambdaExpressionNode): TDataValue;
|
||||
function VisitFunctionCall(const Node: IFunctionCallNode): TDataValue;
|
||||
function VisitRecurNode(const Node: IRecurNode): TDataValue;
|
||||
function VisitBlockExpression(const Node: IBlockExpressionNode): TDataValue;
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): TDataValue;
|
||||
function VisitAssignment(const Node: IAssignmentNode): TDataValue;
|
||||
@@ -321,6 +323,32 @@ begin
|
||||
Result := TDataValue.Void;
|
||||
end;
|
||||
|
||||
function TJsonAstConverter.VisitRecurNode(const Node: IRecurNode): TDataValue;
|
||||
var
|
||||
obj: TJSONObject;
|
||||
argsArray: TJSONArray;
|
||||
tempArgs: TArray<TJSONObject>;
|
||||
arg: IAstNode;
|
||||
i: Integer;
|
||||
begin
|
||||
for arg in Node.Arguments do
|
||||
arg.Accept(Self);
|
||||
|
||||
SetLength(tempArgs, Length(Node.Arguments));
|
||||
for i := High(tempArgs) downto 0 do
|
||||
tempArgs[i] := FJsonObjectStack.Pop;
|
||||
|
||||
argsArray := TJSONArray.Create;
|
||||
for i := 0 to High(tempArgs) do
|
||||
argsArray.Add(tempArgs[i]);
|
||||
|
||||
obj := TJSONObject.Create;
|
||||
obj.AddPair('NodeType', TJSONString.Create('Recur'));
|
||||
obj.AddPair('Arguments', argsArray);
|
||||
FJsonObjectStack.Push(obj);
|
||||
Result := TDataValue.Void;
|
||||
end;
|
||||
|
||||
function TJsonAstConverter.VisitBlockExpression(const Node: IBlockExpressionNode): TDataValue;
|
||||
var
|
||||
obj: TJSONObject;
|
||||
@@ -604,6 +632,20 @@ begin
|
||||
Result := TAst.FunctionCall(callee, args);
|
||||
end;
|
||||
|
||||
function TJsonAstConverter.JsonToRecurNode(const AObj: TJSONObject): IRecurNode;
|
||||
var
|
||||
args: TArray<IAstNode>;
|
||||
argsArray: TJSONArray;
|
||||
i: Integer;
|
||||
begin
|
||||
argsArray := AObj.GetValue<TJSONArray>('Arguments');
|
||||
SetLength(args, argsArray.Count);
|
||||
for i := 0 to argsArray.Count - 1 do
|
||||
args[i] := JsonToNode(argsArray.Items[i]);
|
||||
|
||||
Result := TAst.Recur(args);
|
||||
end;
|
||||
|
||||
function TJsonAstConverter.JsonToBlockNode(const AObj: TJSONObject): IBlockExpressionNode;
|
||||
var
|
||||
expressions: TArray<IAstNode>;
|
||||
@@ -702,6 +744,8 @@ begin
|
||||
Result := JsonToLambdaExprNode(obj)
|
||||
else if nodeType = 'FunctionCall' then
|
||||
Result := JsonToFunctionCallNode(obj)
|
||||
else if nodeType = 'Recur' then
|
||||
Result := JsonToRecurNode(obj)
|
||||
else if nodeType = 'Block' then
|
||||
Result := JsonToBlockNode(obj)
|
||||
else if nodeType = 'VarDecl' then
|
||||
|
||||
Reference in New Issue
Block a user