added macro quoting nodes
This commit is contained in:
+99
-2
@@ -41,6 +41,9 @@ type
|
||||
const AParameters: TArray<IIdentifierNode>;
|
||||
const ABody: IAstNode
|
||||
): IMacroDefinitionNode; static;
|
||||
class function Quasiquote(const AExpression: IAstNode): IQuasiquoteNode; static;
|
||||
class function Unquote(const AExpression: IAstNode): IUnquoteNode; static;
|
||||
class function UnquoteSplicing(const AExpression: IAstNode): IUnquoteSplicingNode; static;
|
||||
class function FunctionCall(const ACallee: IAstNode; const AArguments: TArray<IAstNode>): IFunctionCallNode; static;
|
||||
class function Recur(const AArguments: array of IAstNode): IRecurNode; static;
|
||||
class function Block(const AExpressions: array of IAstNode): IBlockExpressionNode; static;
|
||||
@@ -159,6 +162,33 @@ type
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
end;
|
||||
|
||||
TQuasiquoteNode = class(TAstNode, IQuasiquoteNode)
|
||||
private
|
||||
FExpression: IAstNode;
|
||||
function GetExpression: IAstNode;
|
||||
public
|
||||
constructor Create(const AExpression: IAstNode);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
end;
|
||||
|
||||
TUnquoteNode = class(TAstNode, IUnquoteNode)
|
||||
private
|
||||
FExpression: IAstNode;
|
||||
function GetExpression: IAstNode;
|
||||
public
|
||||
constructor Create(const AExpression: IAstNode);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
end;
|
||||
|
||||
TUnquoteSplicingNode = class(TAstNode, IUnquoteSplicingNode)
|
||||
private
|
||||
FExpression: IAstNode;
|
||||
function GetExpression: IAstNode;
|
||||
public
|
||||
constructor Create(const AExpression: IAstNode);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
end;
|
||||
|
||||
TFunctionCallNode = class(TAstNode, IFunctionCallNode)
|
||||
private
|
||||
FCallee: IAstNode;
|
||||
@@ -450,7 +480,6 @@ end;
|
||||
|
||||
constructor TMacroDefinitionNode.Create(const AName: IIdentifierNode; const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||
begin
|
||||
// Added concrete class for macro definitions.
|
||||
inherited Create;
|
||||
FName := AName;
|
||||
FParameters := AParameters;
|
||||
@@ -477,6 +506,60 @@ begin
|
||||
Result := FParameters;
|
||||
end;
|
||||
|
||||
{ TQuasiquoteNode }
|
||||
|
||||
constructor TQuasiquoteNode.Create(const AExpression: IAstNode);
|
||||
begin
|
||||
inherited Create;
|
||||
FExpression := AExpression;
|
||||
end;
|
||||
|
||||
function TQuasiquoteNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitQuasiquote(Self);
|
||||
end;
|
||||
|
||||
function TQuasiquoteNode.GetExpression: IAstNode;
|
||||
begin
|
||||
Result := FExpression;
|
||||
end;
|
||||
|
||||
{ TUnquoteNode }
|
||||
|
||||
constructor TUnquoteNode.Create(const AExpression: IAstNode);
|
||||
begin
|
||||
inherited Create;
|
||||
FExpression := AExpression;
|
||||
end;
|
||||
|
||||
function TUnquoteNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitUnquote(Self);
|
||||
end;
|
||||
|
||||
function TUnquoteNode.GetExpression: IAstNode;
|
||||
begin
|
||||
Result := FExpression;
|
||||
end;
|
||||
|
||||
{ TUnquoteSplicingNode }
|
||||
|
||||
constructor TUnquoteSplicingNode.Create(const AExpression: IAstNode);
|
||||
begin
|
||||
inherited Create;
|
||||
FExpression := AExpression;
|
||||
end;
|
||||
|
||||
function TUnquoteSplicingNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitUnquoteSplicing(Self);
|
||||
end;
|
||||
|
||||
function TUnquoteSplicingNode.GetExpression: IAstNode;
|
||||
begin
|
||||
Result := FExpression;
|
||||
end;
|
||||
|
||||
{ TFunctionCallNode }
|
||||
|
||||
constructor TFunctionCallNode.Create(const ACallee: IAstNode; const AArguments: TArray<IAstNode>);
|
||||
@@ -811,7 +894,6 @@ class function TAst.MacroDef(
|
||||
const ABody: IAstNode
|
||||
): IMacroDefinitionNode;
|
||||
begin
|
||||
// Added factory for macro definitions.
|
||||
Result := TMacroDefinitionNode.Create(AName, AParameters, ABody);
|
||||
end;
|
||||
|
||||
@@ -820,6 +902,11 @@ begin
|
||||
Result := TMemberAccessNode.Create(ABase, AMember);
|
||||
end;
|
||||
|
||||
class function TAst.Quasiquote(const AExpression: IAstNode): IQuasiquoteNode;
|
||||
begin
|
||||
Result := TQuasiquoteNode.Create(AExpression);
|
||||
end;
|
||||
|
||||
class function TAst.Recur(const AArguments: array of IAstNode): IRecurNode;
|
||||
var
|
||||
args: TArray<IAstNode>;
|
||||
@@ -841,6 +928,16 @@ begin
|
||||
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||
end;
|
||||
|
||||
class function TAst.Unquote(const AExpression: IAstNode): IUnquoteNode;
|
||||
begin
|
||||
Result := TUnquoteNode.Create(AExpression);
|
||||
end;
|
||||
|
||||
class function TAst.UnquoteSplicing(const AExpression: IAstNode): IUnquoteSplicingNode;
|
||||
begin
|
||||
Result := TUnquoteSplicingNode.Create(AExpression);
|
||||
end;
|
||||
|
||||
class function TAst.UnaryExpr(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode): IUnaryExpressionNode;
|
||||
begin
|
||||
Result := TUnaryExpressionNode.Create(AOperator, ARight);
|
||||
|
||||
Reference in New Issue
Block a user