Ast editor custom draw
This commit is contained in:
@@ -9,65 +9,79 @@ uses
|
||||
Myc.Data.Value,
|
||||
Myc.Ast.Nodes,
|
||||
Myc.Ast.Visitor,
|
||||
Myc.Fmx.AstEditor.Workspace,
|
||||
Myc.Fmx.AstEditor.Node,
|
||||
Myc.Fmx.AstEditor.Handlers;
|
||||
Myc.Fmx.AstEditor.Render, // Virtual Engine
|
||||
Myc.Fmx.AstEditor.Node, // View Nodes
|
||||
Myc.Fmx.AstEditor.Handlers, // Handlers
|
||||
Myc.Fmx.AstEditor.Workspace; // Host
|
||||
|
||||
type
|
||||
// Inherits from the generic TAstVisitor<TAstViewNode>
|
||||
// Implementation of the Factory/Visitor for the Virtual Tree
|
||||
TAstVisualizer = class(TAstVisitor<TAstViewNode>, IAstVisualizer)
|
||||
private
|
||||
FExprDepth: Integer;
|
||||
FParentControl: TControl;
|
||||
FWorkspace: TWorkspace; // Changed from TAstWorkspace to TWorkspace
|
||||
FParentNode: TVisualNode; // Changed from TControl
|
||||
FWorkspace: TWorkspace;
|
||||
|
||||
function CallAccept(const Node: IAstNode): TAstViewNode;
|
||||
|
||||
// IAstVisualizer Implementation
|
||||
function GetExprDepth: Integer;
|
||||
function GetParentControl: TControl;
|
||||
function GetWorkspace: TWorkspace; // Changed signature
|
||||
procedure SetExprDepth(const Value: Integer);
|
||||
procedure SetParentControl(const Value: TControl);
|
||||
function GetParentNode: TVisualNode;
|
||||
function GetWorkspace: TWorkspace;
|
||||
|
||||
protected
|
||||
// Visitor implementations for each AST node type.
|
||||
// --- Visitor Implementations ---
|
||||
function VisitConstant(const Node: IConstantNode): TAstViewNode; override;
|
||||
function VisitIdentifier(const Node: IIdentifierNode): TAstViewNode; override;
|
||||
function VisitKeyword(const Node: IKeywordNode): TAstViewNode; override;
|
||||
|
||||
// --- List Visitors (NEW) ---
|
||||
// Lists
|
||||
function VisitParameterList(const Node: IParameterList): TAstViewNode; override;
|
||||
function VisitArgumentList(const Node: IArgumentList): TAstViewNode; override;
|
||||
function VisitExpressionList(const Node: IExpressionList): TAstViewNode; override;
|
||||
function VisitRecordFieldList(const Node: IRecordFieldList): TAstViewNode; override;
|
||||
function VisitRecordField(const Node: IRecordFieldNode): TAstViewNode; override;
|
||||
|
||||
// Control Flow
|
||||
function VisitIfExpression(const Node: IIfExpressionNode): TAstViewNode; override;
|
||||
function VisitTernaryExpression(const Node: ITernaryExpressionNode): TAstViewNode; override;
|
||||
function VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstViewNode; override;
|
||||
function VisitFunctionCall(const Node: IFunctionCallNode): TAstViewNode; override;
|
||||
function VisitMacroExpansionNode(const Node: IMacroExpansionNode): TAstViewNode; override;
|
||||
function VisitBlockExpression(const Node: IBlockExpressionNode): TAstViewNode; override;
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstViewNode; override;
|
||||
function VisitAssignment(const Node: IAssignmentNode): TAstViewNode; override;
|
||||
function VisitMacroDefinition(const Node: IMacroDefinitionNode): TAstViewNode; override;
|
||||
function VisitQuasiquote(const Node: IQuasiquoteNode): TAstViewNode; override;
|
||||
function VisitUnquote(const Node: IUnquoteNode): TAstViewNode; override;
|
||||
function VisitUnquoteSplicing(const Node: IUnquoteSplicingNode): TAstViewNode; override;
|
||||
function VisitIndexer(const Node: IIndexerNode): TAstViewNode; override;
|
||||
function VisitMemberAccess(const Node: IMemberAccessNode): TAstViewNode; override;
|
||||
function VisitRecordLiteral(const Node: IRecordLiteralNode): TAstViewNode; override;
|
||||
function VisitCreateSeries(const Node: ICreateSeriesNode): TAstViewNode; override;
|
||||
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstViewNode; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): TAstViewNode; override;
|
||||
function VisitRecurNode(const Node: IRecurNode): TAstViewNode; override;
|
||||
function VisitNop(const Node: INopNode): TAstViewNode; override;
|
||||
|
||||
// Functions
|
||||
function VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstViewNode; override;
|
||||
function VisitFunctionCall(const Node: IFunctionCallNode): TAstViewNode; override;
|
||||
function VisitMacroExpansionNode(const Node: IMacroExpansionNode): TAstViewNode; override;
|
||||
|
||||
// Declarations
|
||||
function VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstViewNode; override;
|
||||
function VisitAssignment(const Node: IAssignmentNode): TAstViewNode; override;
|
||||
function VisitMacroDefinition(const Node: IMacroDefinitionNode): TAstViewNode; override;
|
||||
|
||||
// Metaprogramming
|
||||
function VisitQuasiquote(const Node: IQuasiquoteNode): TAstViewNode; override;
|
||||
function VisitUnquote(const Node: IUnquoteNode): TAstViewNode; override;
|
||||
function VisitUnquoteSplicing(const Node: IUnquoteSplicingNode): TAstViewNode; override;
|
||||
|
||||
// Data Access
|
||||
function VisitIndexer(const Node: IIndexerNode): TAstViewNode; override;
|
||||
function VisitMemberAccess(const Node: IMemberAccessNode): TAstViewNode; override;
|
||||
function VisitRecordLiteral(const Node: IRecordLiteralNode): TAstViewNode; override;
|
||||
|
||||
// Series
|
||||
function VisitCreateSeries(const Node: ICreateSeriesNode): TAstViewNode; override;
|
||||
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstViewNode; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): TAstViewNode; override;
|
||||
|
||||
public
|
||||
constructor Create(AWorkspace: TWorkspace; AParentControl: TControl; AExprDepth: Integer);
|
||||
constructor Create(AWorkspace: TWorkspace; AParentNode: TVisualNode; AExprDepth: Integer);
|
||||
destructor Destroy; override;
|
||||
|
||||
function Clone(ParentControl: TControl; ExprDepth: Integer): IAstVisualizer;
|
||||
function Clone(ParentNode: TVisualNode; ExprDepth: Integer): IAstVisualizer;
|
||||
|
||||
property ExprDepth: Integer read GetExprDepth write SetExprDepth;
|
||||
property ParentControl: TControl read GetParentControl write SetParentControl;
|
||||
property ExprDepth: Integer read GetExprDepth;
|
||||
property ParentNode: TVisualNode read GetParentNode;
|
||||
property Workspace: TWorkspace read GetWorkspace;
|
||||
end;
|
||||
|
||||
@@ -75,11 +89,11 @@ implementation
|
||||
|
||||
{ TAstVisualizer }
|
||||
|
||||
constructor TAstVisualizer.Create(AWorkspace: TWorkspace; AParentControl: TControl; AExprDepth: Integer);
|
||||
constructor TAstVisualizer.Create(AWorkspace: TWorkspace; AParentNode: TVisualNode; AExprDepth: Integer);
|
||||
begin
|
||||
inherited Create;
|
||||
FWorkspace := AWorkspace;
|
||||
FParentControl := AParentControl;
|
||||
FParentNode := AParentNode;
|
||||
FExprDepth := AExprDepth;
|
||||
end;
|
||||
|
||||
@@ -95,21 +109,18 @@ begin
|
||||
if not Assigned(Node) then
|
||||
exit(nil);
|
||||
|
||||
// Dynamic dispatch via Visitor pattern
|
||||
dataValue := Node.Accept(Self);
|
||||
|
||||
if dataValue.Kind = TDataValueKind.vkGeneric then
|
||||
begin
|
||||
Result := dataValue.AsGeneric<TAstViewNode>;
|
||||
end
|
||||
Result := dataValue.AsGeneric<TAstViewNode>
|
||||
else
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TAstVisualizer.Clone(ParentControl: TControl; ExprDepth: Integer): IAstVisualizer;
|
||||
function TAstVisualizer.Clone(ParentNode: TVisualNode; ExprDepth: Integer): IAstVisualizer;
|
||||
begin
|
||||
Result := TAstVisualizer.Create(FWorkspace, ParentControl, ExprDepth);
|
||||
Result := TAstVisualizer.Create(FWorkspace, ParentNode, ExprDepth);
|
||||
end;
|
||||
|
||||
function TAstVisualizer.GetExprDepth: Integer;
|
||||
@@ -117,9 +128,9 @@ begin
|
||||
Result := FExprDepth;
|
||||
end;
|
||||
|
||||
function TAstVisualizer.GetParentControl: TControl;
|
||||
function TAstVisualizer.GetParentNode: TVisualNode;
|
||||
begin
|
||||
Result := FParentControl;
|
||||
Result := FParentNode;
|
||||
end;
|
||||
|
||||
function TAstVisualizer.GetWorkspace: TWorkspace;
|
||||
@@ -127,17 +138,7 @@ begin
|
||||
Result := FWorkspace;
|
||||
end;
|
||||
|
||||
procedure TAstVisualizer.SetExprDepth(const Value: Integer);
|
||||
begin
|
||||
FExprDepth := Value;
|
||||
end;
|
||||
|
||||
procedure TAstVisualizer.SetParentControl(const Value: TControl);
|
||||
begin
|
||||
FParentControl := Value;
|
||||
end;
|
||||
|
||||
// --- Visitor Implementations ---
|
||||
// --- Visitor Implementation Helpers ---
|
||||
|
||||
function TAstVisualizer.VisitConstant(const Node: IConstantNode): TAstViewNode;
|
||||
begin
|
||||
@@ -154,7 +155,7 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TKeywordNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// --- List Visitors ---
|
||||
// Lists
|
||||
|
||||
function TAstVisualizer.VisitParameterList(const Node: IParameterList): TAstViewNode;
|
||||
begin
|
||||
@@ -181,7 +182,7 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TRecordFieldHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// --- Node Visitors ---
|
||||
// Control Flow
|
||||
|
||||
function TAstVisualizer.VisitBlockExpression(const Node: IBlockExpressionNode): TAstViewNode;
|
||||
begin
|
||||
@@ -198,6 +199,18 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TTernaryExpressionNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
function TAstVisualizer.VisitRecurNode(const Node: IRecurNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TRecurNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
function TAstVisualizer.VisitNop(const Node: INopNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TNopNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// Functions
|
||||
|
||||
function TAstVisualizer.VisitLambdaExpression(const Node: ILambdaExpressionNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TLambdaExpressionNodeHandler.Create(Node));
|
||||
@@ -213,6 +226,8 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TMacroExpansionNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// Declarations
|
||||
|
||||
function TAstVisualizer.VisitVariableDeclaration(const Node: IVariableDeclarationNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TVariableDeclarationNodeHandler.Create(Node));
|
||||
@@ -228,6 +243,8 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TMacroDefinitionNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// Metaprogramming
|
||||
|
||||
function TAstVisualizer.VisitQuasiquote(const Node: IQuasiquoteNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TQuasiquoteNodeHandler.Create(Node));
|
||||
@@ -243,6 +260,8 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TUnquoteSplicingNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// Data Access
|
||||
|
||||
function TAstVisualizer.VisitIndexer(const Node: IIndexerNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TIndexerNodeHandler.Create(Node));
|
||||
@@ -258,6 +277,8 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TRecordLiteralNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
// Series
|
||||
|
||||
function TAstVisualizer.VisitCreateSeries(const Node: ICreateSeriesNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TCreateSeriesNodeHandler.Create(Node));
|
||||
@@ -273,14 +294,4 @@ begin
|
||||
Result := TAstViewNode.Create(Self, TSeriesLengthNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
function TAstVisualizer.VisitRecurNode(const Node: IRecurNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TRecurNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
function TAstVisualizer.VisitNop(const Node: INopNode): TAstViewNode;
|
||||
begin
|
||||
Result := TAstViewNode.Create(Self, TNopNodeHandler.Create(Node));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user