Ast UI handlers split into separate units
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -32,7 +32,11 @@ uses
|
|||||||
Myc.Fmx.AstEditor.Layout in '..\Src\AST\Myc.Fmx.AstEditor.Layout.pas',
|
Myc.Fmx.AstEditor.Layout in '..\Src\AST\Myc.Fmx.AstEditor.Layout.pas',
|
||||||
Myc.Fmx.AstEditor.Node in '..\Src\AST\Myc.Fmx.AstEditor.Node.pas',
|
Myc.Fmx.AstEditor.Node in '..\Src\AST\Myc.Fmx.AstEditor.Node.pas',
|
||||||
Myc.Ast.Refactoring.Remove in '..\Src\AST\Myc.Ast.Refactoring.Remove.pas',
|
Myc.Ast.Refactoring.Remove in '..\Src\AST\Myc.Ast.Refactoring.Remove.pas',
|
||||||
Myc.Fmx.AstEditor.Render in '..\Src\AST\Myc.Fmx.AstEditor.Render.pas';
|
Myc.Fmx.AstEditor.Render in '..\Src\AST\Myc.Fmx.AstEditor.Render.pas',
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Lists in '..\Src\AST\Myc.Fmx.AstEditor.Handlers.Lists.pas',
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Primitives in '..\Src\AST\Myc.Fmx.AstEditor.Handlers.Primitives.pas',
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Control in '..\Src\AST\Myc.Fmx.AstEditor.Handlers.Control.pas',
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Data in '..\Src\AST\Myc.Fmx.AstEditor.Handlers.Data.pas';
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,10 @@
|
|||||||
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Node.pas"/>
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Node.pas"/>
|
||||||
<DCCReference Include="..\Src\AST\Myc.Ast.Refactoring.Remove.pas"/>
|
<DCCReference Include="..\Src\AST\Myc.Ast.Refactoring.Remove.pas"/>
|
||||||
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Render.pas"/>
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Render.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Handlers.Lists.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Handlers.Primitives.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Handlers.Control.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Fmx.AstEditor.Handlers.Data.pas"/>
|
||||||
<BuildConfiguration Include="Base">
|
<BuildConfiguration Include="Base">
|
||||||
<Key>Base</Key>
|
<Key>Base</Key>
|
||||||
</BuildConfiguration>
|
</BuildConfiguration>
|
||||||
|
|||||||
@@ -0,0 +1,418 @@
|
|||||||
|
unit Myc.Fmx.AstEditor.Handlers.Control;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
System.SysUtils,
|
||||||
|
System.UITypes,
|
||||||
|
System.Generics.Collections,
|
||||||
|
Myc.Ast,
|
||||||
|
Myc.Ast.Nodes,
|
||||||
|
Myc.Fmx.AstEditor.Render,
|
||||||
|
Myc.Fmx.AstEditor.Node;
|
||||||
|
|
||||||
|
type
|
||||||
|
// --- Logic & Control Flow ---
|
||||||
|
|
||||||
|
TBlockExpressionNodeHandler = class(TBaseNodeHandler<IBlockExpressionNode>)
|
||||||
|
private
|
||||||
|
FExpressionsNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TIfExpressionNodeHandler = class(TBaseNodeHandler<IIfExpressionNode>)
|
||||||
|
private
|
||||||
|
FConditionNode: TAstViewNode;
|
||||||
|
FThenNode: TAstViewNode;
|
||||||
|
FElseNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TTernaryExpressionNodeHandler = class(TBaseNodeHandler<ITernaryExpressionNode>)
|
||||||
|
private
|
||||||
|
FConditionNode: TAstViewNode;
|
||||||
|
FThenNode: TAstViewNode;
|
||||||
|
FElseNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// --- Functions & Calls ---
|
||||||
|
|
||||||
|
TLambdaExpressionNodeHandler = class(TBaseNodeHandler<ILambdaExpressionNode>)
|
||||||
|
private
|
||||||
|
FParamsNode: TAstViewNode;
|
||||||
|
FBodyNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TFunctionCallNodeHandler = class(TBaseNodeHandler<IFunctionCallNode>)
|
||||||
|
private
|
||||||
|
FCalleeNode: TAstViewNode;
|
||||||
|
FArgumentsNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Renders function calls as infix operators (e.g. "A + B" instead of "call + A B")
|
||||||
|
TOperatorCallHandler = class(TBaseNodeHandler<IFunctionCallNode>)
|
||||||
|
private
|
||||||
|
FArgumentNodes: TList<TAstViewNode>;
|
||||||
|
FCalleeName: string;
|
||||||
|
public
|
||||||
|
constructor Create(const ANode: IFunctionCallNode);
|
||||||
|
destructor Destroy; override;
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMacroExpansionNodeHandler = class(TBaseNodeHandler<IMacroExpansionNode>)
|
||||||
|
private
|
||||||
|
FExpandedBodyNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TRecurNodeHandler = class(TBaseNodeHandler<IRecurNode>)
|
||||||
|
private
|
||||||
|
FArgumentsNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMacroDefinitionNodeHandler = class(TBaseNodeHandler<IMacroDefinitionNode>)
|
||||||
|
private
|
||||||
|
FParamsNode: TAstViewNode;
|
||||||
|
FBodyNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TBlockExpressionNodeHandler }
|
||||||
|
|
||||||
|
procedure TBlockExpressionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
OwnerNode.Alignment := laFlush;
|
||||||
|
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'do');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
FExpressionsNode := visu.CallAccept(FNode.Expressions);
|
||||||
|
FExpressionsNode.Frameless := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TBlockExpressionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Block(FNode.Identity, FExpressionsNode.CreateAst.AsExpressionList, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TIfExpressionNodeHandler }
|
||||||
|
|
||||||
|
procedure TIfExpressionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
OwnerNode.Alignment := laFlush;
|
||||||
|
|
||||||
|
FConditionNode := OwnerNode.AddExpr(OwnerNode, 'if', FNode.Condition);
|
||||||
|
FThenNode := OwnerNode.AddExpr(OwnerNode, 'then', FNode.ThenBranch);
|
||||||
|
if Assigned(FNode.ElseBranch) then
|
||||||
|
FElseNode := OwnerNode.AddExpr(OwnerNode, 'else', FNode.ElseBranch);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIfExpressionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
elseAst: IAstNode;
|
||||||
|
begin
|
||||||
|
if Assigned(FElseNode) then
|
||||||
|
elseAst := FElseNode.CreateAst
|
||||||
|
else
|
||||||
|
elseAst := nil;
|
||||||
|
|
||||||
|
Result := TAst.IfExpr(FNode.Identity, FConditionNode.CreateAst, FThenNode.CreateAst, elseAst, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TTernaryExpressionNodeHandler }
|
||||||
|
|
||||||
|
procedure TTernaryExpressionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
FConditionNode := visu.CallAccept(FNode.Condition);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, '?');
|
||||||
|
FThenNode := visu.CallAccept(FNode.ThenBranch);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, ':');
|
||||||
|
FElseNode := visu.CallAccept(FNode.ElseBranch);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTernaryExpressionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.TernaryExpr(FNode.Identity, FConditionNode.CreateAst, FThenNode.CreateAst, FElseNode.CreateAst, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLambdaExpressionNodeHandler }
|
||||||
|
|
||||||
|
procedure TLambdaExpressionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleContainer: TAutoFitLayout;
|
||||||
|
lbl: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, 0);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
OwnerNode.Alignment := laFlush;
|
||||||
|
OwnerNode.BackgroundColor := $090000ff;
|
||||||
|
|
||||||
|
titleContainer := OwnerNode.AddContainer(OwnerNode, loHorizontal, laCenter);
|
||||||
|
lbl := OwnerNode.AddLabel(titleContainer, 'fn');
|
||||||
|
lbl.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
// Parameters: Delegate to List Handler
|
||||||
|
var paramVisu := visu.Clone(titleContainer, 0);
|
||||||
|
FParamsNode := paramVisu.CallAccept(FNode.Parameters);
|
||||||
|
|
||||||
|
// Body
|
||||||
|
FBodyNode := visu.CallAccept(FNode.Body);
|
||||||
|
FBodyNode.Frameless := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLambdaExpressionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
TAst.LambdaExpr(
|
||||||
|
FNode.Identity,
|
||||||
|
FParamsNode.CreateAst.AsParameterList,
|
||||||
|
FBodyNode.CreateAst,
|
||||||
|
FNode.Layout,
|
||||||
|
FNode.Descriptor,
|
||||||
|
FNode.Upvalues,
|
||||||
|
FNode.HasNestedLambdas,
|
||||||
|
FNode.IsPure,
|
||||||
|
FNode.StaticType
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TFunctionCallNodeHandler }
|
||||||
|
|
||||||
|
procedure TFunctionCallNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
callLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
|
||||||
|
callLabel := OwnerNode.AddLabel(OwnerNode, 'call ');
|
||||||
|
callLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
FCalleeNode := visu.CallAccept(FNode.Callee);
|
||||||
|
|
||||||
|
FArgumentsNode := visu.CallAccept(FNode.Arguments);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TFunctionCallNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
TAst.FunctionCall(
|
||||||
|
FNode.Identity,
|
||||||
|
FCalleeNode.CreateAst,
|
||||||
|
FArgumentsNode.CreateAst.AsArgumentList,
|
||||||
|
FNode.StaticType,
|
||||||
|
FNode.IsTailCall,
|
||||||
|
FNode.StaticTarget,
|
||||||
|
FNode.IsTargetPure
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TOperatorCallHandler }
|
||||||
|
|
||||||
|
constructor TOperatorCallHandler.Create(const ANode: IFunctionCallNode);
|
||||||
|
begin
|
||||||
|
inherited Create(ANode);
|
||||||
|
FArgumentNodes := TList<TAstViewNode>.Create;
|
||||||
|
|
||||||
|
if ANode.Callee.Kind = akIdentifier then
|
||||||
|
FCalleeName := ANode.Callee.AsIdentifier.Name
|
||||||
|
else if ANode.Callee.Kind = akKeyword then
|
||||||
|
FCalleeName := ANode.Callee.AsKeyword.Value.Name
|
||||||
|
else
|
||||||
|
FCalleeName := '?';
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TOperatorCallHandler.Destroy;
|
||||||
|
begin
|
||||||
|
FArgumentNodes.Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TOperatorCallHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
i: Integer;
|
||||||
|
argView: TAstViewNode;
|
||||||
|
opLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
OwnerNode.Alignment := laCenter;
|
||||||
|
|
||||||
|
if FNode.Arguments.Count = 1 then
|
||||||
|
begin
|
||||||
|
opLabel := OwnerNode.AddLabel(OwnerNode, FCalleeName);
|
||||||
|
opLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
opLabel.Color := TAlphaColors.Darkorange;
|
||||||
|
opLabel.Margins := TMarginRect.Create(2, 0, 2, 0);
|
||||||
|
|
||||||
|
argView := visu.CallAccept(FNode.Arguments[0]);
|
||||||
|
FArgumentNodes.Add(argView);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
for i := 0 to FNode.Arguments.Count - 1 do
|
||||||
|
begin
|
||||||
|
if i > 0 then
|
||||||
|
begin
|
||||||
|
opLabel := OwnerNode.AddLabel(OwnerNode, ' ' + FCalleeName + ' ');
|
||||||
|
opLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
opLabel.Color := TAlphaColors.Darkorange;
|
||||||
|
// Compact spacing for operators
|
||||||
|
opLabel.Margins := TMarginRect.Create(0, 0, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
argView := visu.CallAccept(FNode.Arguments[i]);
|
||||||
|
FArgumentNodes.Add(argView);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if FNode.Arguments.Count = 0 then
|
||||||
|
begin
|
||||||
|
opLabel := OwnerNode.AddLabel(OwnerNode, FCalleeName);
|
||||||
|
opLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TOperatorCallHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
newArgs: TArray<IAstNode>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
SetLength(newArgs, FArgumentNodes.Count);
|
||||||
|
for i := 0 to FArgumentNodes.Count - 1 do
|
||||||
|
newArgs[i] := FArgumentNodes[i].CreateAst;
|
||||||
|
|
||||||
|
Result :=
|
||||||
|
TAst.FunctionCall(
|
||||||
|
FNode.Identity,
|
||||||
|
FNode.Callee,
|
||||||
|
TArgumentList.Create(newArgs, FNode.Arguments.Identity),
|
||||||
|
FNode.StaticType,
|
||||||
|
FNode.IsTailCall,
|
||||||
|
FNode.StaticTarget,
|
||||||
|
FNode.IsTargetPure
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TMacroExpansionNodeHandler }
|
||||||
|
|
||||||
|
procedure TMacroExpansionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Macro Expansion');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
FExpandedBodyNode := visu.CallAccept(FNode.ExpandedBody);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMacroExpansionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.MacroExpansionNode(FNode.Identity, FNode.CallNode, FExpandedBodyNode.CreateAst.AsTypedNode);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TRecurNodeHandler }
|
||||||
|
|
||||||
|
procedure TRecurNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'recur');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
FArgumentsNode := visu.CallAccept(FNode.Arguments);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRecurNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Recur(FNode.Identity, FArgumentsNode.CreateAst.AsArgumentList, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TMacroDefinitionNodeHandler }
|
||||||
|
|
||||||
|
procedure TMacroDefinitionNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
titleContainer: TAutoFitLayout;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
|
||||||
|
titleContainer := OwnerNode.AddContainer(OwnerNode, loHorizontal, laCenter);
|
||||||
|
titleLabel := OwnerNode.AddLabel(titleContainer, 'Macro Def: ' + FNode.Name.Name);
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
// Parameters List
|
||||||
|
var paramVisu := visu.Clone(titleContainer, visu.ExprDepth);
|
||||||
|
FParamsNode := paramVisu.CallAccept(FNode.Parameters);
|
||||||
|
|
||||||
|
FBodyNode := visu.CallAccept(FNode.Body);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMacroDefinitionNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.MacroDef(FNode.Identity, FNode.Name, FParamsNode.CreateAst.AsParameterList, FBodyNode.CreateAst);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
unit Myc.Fmx.AstEditor.Handlers.Data;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
System.SysUtils,
|
||||||
|
System.UITypes,
|
||||||
|
Myc.Data.Keyword,
|
||||||
|
Myc.Ast,
|
||||||
|
Myc.Ast.Nodes,
|
||||||
|
Myc.Fmx.AstEditor.Render,
|
||||||
|
Myc.Fmx.AstEditor.Node;
|
||||||
|
|
||||||
|
type
|
||||||
|
// --- Declarations & Assignments ---
|
||||||
|
|
||||||
|
TVariableDeclarationNodeHandler = class(TBaseNodeHandler<IVariableDeclarationNode>)
|
||||||
|
private
|
||||||
|
FTargetNode: TAstViewNode;
|
||||||
|
FInitializerNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TAssignmentNodeHandler = class(TBaseNodeHandler<IAssignmentNode>)
|
||||||
|
private
|
||||||
|
FTargetNode: TAstViewNode;
|
||||||
|
FValueNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// --- Metaprogramming ---
|
||||||
|
|
||||||
|
TQuasiquoteNodeHandler = class(TBaseNodeHandler<IQuasiquoteNode>)
|
||||||
|
private
|
||||||
|
FExpressionNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TUnquoteNodeHandler = class(TBaseNodeHandler<IUnquoteNode>)
|
||||||
|
private
|
||||||
|
FExpressionNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TUnquoteSplicingNodeHandler = class(TBaseNodeHandler<IUnquoteSplicingNode>)
|
||||||
|
private
|
||||||
|
FExpressionNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// --- Data Access & Structures ---
|
||||||
|
|
||||||
|
TIndexerNodeHandler = class(TBaseNodeHandler<IIndexerNode>)
|
||||||
|
private
|
||||||
|
FBaseNode: TAstViewNode;
|
||||||
|
FIndexNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMemberAccessNodeHandler = class(TBaseNodeHandler<IMemberAccessNode>)
|
||||||
|
private
|
||||||
|
FBaseNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TRecordFieldHandler = class(TBaseNodeHandler<IRecordFieldNode>)
|
||||||
|
private
|
||||||
|
FKeyLabel: TTextNode;
|
||||||
|
FValueNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TRecordLiteralNodeHandler = class(TBaseNodeHandler<IRecordLiteralNode>)
|
||||||
|
private
|
||||||
|
FFieldsNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// --- Series Operations ---
|
||||||
|
|
||||||
|
TCreateSeriesNodeHandler = class(TBaseNodeHandler<ICreateSeriesNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TAddSeriesItemNodeHandler = class(TBaseNodeHandler<IAddSeriesItemNode>)
|
||||||
|
private
|
||||||
|
FValueNode: TAstViewNode;
|
||||||
|
FLookbackNode: TAstViewNode;
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TSeriesLengthNodeHandler = class(TBaseNodeHandler<ISeriesLengthNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TVariableDeclarationNodeHandler }
|
||||||
|
|
||||||
|
procedure TVariableDeclarationNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
varLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
|
||||||
|
varLabel := OwnerNode.AddLabel(OwnerNode, 'var');
|
||||||
|
|
||||||
|
varLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
FTargetNode := visu.CallAccept(FNode.Target);
|
||||||
|
|
||||||
|
if Assigned(FNode.Initializer) then
|
||||||
|
begin
|
||||||
|
OwnerNode.AddLabel(OwnerNode, ':=');
|
||||||
|
FInitializerNode := visu.CallAccept(FNode.Initializer);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
FInitializerNode := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TVariableDeclarationNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
initAst: IAstNode;
|
||||||
|
begin
|
||||||
|
if Assigned(FInitializerNode) then
|
||||||
|
initAst := FInitializerNode.CreateAst
|
||||||
|
else
|
||||||
|
initAst := nil;
|
||||||
|
Result := TAst.VarDecl(FNode.Identity, FTargetNode.CreateAst, initAst, FNode.StaticType, FNode.IsBoxed);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TAssignmentNodeHandler }
|
||||||
|
|
||||||
|
procedure TAssignmentNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
FTargetNode := visu.CallAccept(FNode.Target);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, ':=');
|
||||||
|
FValueNode := visu.CallAccept(FNode.Value);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAssignmentNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Assign(FNode.Identity, FTargetNode.CreateAst, FValueNode.CreateAst, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TQuasiquoteNodeHandler }
|
||||||
|
|
||||||
|
procedure TQuasiquoteNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Quasiquote');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
FExpressionNode := visu.CallAccept(FNode.Expression);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TQuasiquoteNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Quasiquote(FNode.Identity, FExpressionNode.CreateAst);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TUnquoteNodeHandler }
|
||||||
|
|
||||||
|
procedure TUnquoteNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
leftBracket, rightBracket: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
|
||||||
|
leftBracket := OwnerNode.AddLabel(OwnerNode, '<');
|
||||||
|
// We cannot assign to fields of record properties directly.
|
||||||
|
// Replace the entire margin record.
|
||||||
|
// Default from AddLabel is (cNodePadding, cTitleTopPadding, cNodePadding, cTitleBottomPadding)
|
||||||
|
// We want Right Margin = 0.
|
||||||
|
leftBracket.Margins := TMarginRect.Create(cNodePadding, cTitleTopPadding, 0, cTitleBottomPadding);
|
||||||
|
|
||||||
|
FExpressionNode := visu.CallAccept(FNode.Expression);
|
||||||
|
|
||||||
|
rightBracket := OwnerNode.AddLabel(OwnerNode, '>');
|
||||||
|
// We want Left Margin = 0.
|
||||||
|
rightBracket.Margins := TMarginRect.Create(0, cTitleTopPadding, cNodePadding, cTitleBottomPadding);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnquoteNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Unquote(FNode.Identity, FExpressionNode.CreateAst);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TUnquoteSplicingNodeHandler }
|
||||||
|
|
||||||
|
procedure TUnquoteSplicingNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Unquote-Splicing');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
FExpressionNode := visu.CallAccept(FNode.Expression);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnquoteSplicingNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.UnquoteSplicing(FNode.Identity, FExpressionNode.CreateAst.AsQuasiquote);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TIndexerNodeHandler }
|
||||||
|
|
||||||
|
procedure TIndexerNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
FBaseNode := visu.CallAccept(FNode.Base);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, '[');
|
||||||
|
FIndexNode := visu.CallAccept(FNode.Index);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, ']');
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIndexerNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Indexer(FNode.Identity, FBaseNode.CreateAst, FIndexNode.CreateAst, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TMemberAccessNodeHandler }
|
||||||
|
|
||||||
|
procedure TMemberAccessNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
FBaseNode := visu.CallAccept(FNode.Base);
|
||||||
|
OwnerNode.AddLabel(OwnerNode, '.');
|
||||||
|
OwnerNode.AddLabel(OwnerNode, FNode.Member.Value.Name);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMemberAccessNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.MemberAccess(FNode.Identity, FBaseNode.CreateAst, TAst.Keyword(FNode.Member.Identity.AsKeyword), FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TRecordFieldHandler }
|
||||||
|
|
||||||
|
procedure TRecordFieldHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Orientation := loHorizontal;
|
||||||
|
OwnerNode.Alignment := laCenter;
|
||||||
|
|
||||||
|
FKeyLabel := OwnerNode.AddLabel(OwnerNode, ':' + FNode.Key.Value.Name);
|
||||||
|
FKeyLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
FKeyLabel.Color := TAlphaColors.Mediumvioletred;
|
||||||
|
|
||||||
|
FValueNode := visu.CallAccept(FNode.Value);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRecordFieldHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.RecordField(FNode.Identity, FNode.Key, FValueNode.CreateAst);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TRecordLiteralNodeHandler }
|
||||||
|
|
||||||
|
procedure TRecordLiteralNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
OwnerNode.Alignment := laFlush;
|
||||||
|
|
||||||
|
// Delegate to RecordFieldList
|
||||||
|
FFieldsNode := visu.CallAccept(FNode.Fields);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRecordLiteralNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
TAst.RecordLiteral(
|
||||||
|
FNode.Identity,
|
||||||
|
FFieldsNode.CreateAst.AsRecordFieldList,
|
||||||
|
FNode.ScalarDefinition,
|
||||||
|
FNode.GenericDefinition,
|
||||||
|
FNode.StaticType
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCreateSeriesNodeHandler }
|
||||||
|
|
||||||
|
procedure TCreateSeriesNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Create Series: ' + FNode.Definition);
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCreateSeriesNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.CreateSeries(FNode.Identity.AsDefinition, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TAddSeriesItemNodeHandler }
|
||||||
|
|
||||||
|
procedure TAddSeriesItemNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
visu: IAstVisualizer;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
visu := OwnerNode.Visualizer.Clone(OwnerNode, OwnerNode.Visualizer.ExprDepth + 1);
|
||||||
|
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Add Item to: ' + FNode.Series.Name);
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
FValueNode := visu.CallAccept(FNode.Value);
|
||||||
|
if Assigned(FNode.Lookback) then
|
||||||
|
FLookbackNode := visu.CallAccept(FNode.Lookback)
|
||||||
|
else
|
||||||
|
FLookbackNode := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TAddSeriesItemNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
lookbackAst: IAstNode;
|
||||||
|
begin
|
||||||
|
if Assigned(FLookbackNode) then
|
||||||
|
lookbackAst := FLookbackNode.CreateAst
|
||||||
|
else
|
||||||
|
lookbackAst := nil;
|
||||||
|
|
||||||
|
Result :=
|
||||||
|
TAst.AddSeriesItem(
|
||||||
|
FNode.Identity,
|
||||||
|
FNode.Series, // Reuse original Series Identifier Node
|
||||||
|
FValueNode.CreateAst,
|
||||||
|
lookbackAst,
|
||||||
|
FNode.StaticType
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TSeriesLengthNodeHandler }
|
||||||
|
|
||||||
|
procedure TSeriesLengthNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Length of: ' + FNode.Series.Name);
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSeriesLengthNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.SeriesLength(FNode.Identity, FNode.Series, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
unit Myc.Fmx.AstEditor.Handlers.Lists;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Myc.Ast.Nodes,
|
||||||
|
Myc.Fmx.AstEditor.Render,
|
||||||
|
Myc.Fmx.AstEditor.Node,
|
||||||
|
Myc.Fmx.AstEditor.Handlers;
|
||||||
|
|
||||||
|
type
|
||||||
|
TParameterListHandler = class(TNodeListHandler<IIdentifierNode>)
|
||||||
|
protected
|
||||||
|
function GetOrientation: TLayoutOrientation; override;
|
||||||
|
public
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TArgumentListHandler = class(TNodeListHandler<IAstNode>)
|
||||||
|
protected
|
||||||
|
function GetOrientation: TLayoutOrientation; override;
|
||||||
|
public
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TExpressionListHandler = class(TNodeListHandler<IAstNode>)
|
||||||
|
protected
|
||||||
|
function GetOrientation: TLayoutOrientation; override;
|
||||||
|
function GetAlignment: TLayoutAlignment; override;
|
||||||
|
public
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TRecordFieldListHandler = class(TNodeListHandler<IRecordFieldNode>)
|
||||||
|
protected
|
||||||
|
function GetOrientation: TLayoutOrientation; override;
|
||||||
|
function GetAlignment: TLayoutAlignment; override;
|
||||||
|
public
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TParameterListHandler }
|
||||||
|
|
||||||
|
function TParameterListHandler.GetOrientation: TLayoutOrientation;
|
||||||
|
begin
|
||||||
|
Result := loHorizontal;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TParameterListHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
arr: TArray<IIdentifierNode>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
SetLength(arr, FChildNodes.Count);
|
||||||
|
for i := 0 to FChildNodes.Count - 1 do
|
||||||
|
arr[i] := FChildNodes[i].CreateAst.AsIdentifier;
|
||||||
|
|
||||||
|
Result := TParameterList.Create(arr, FNode.Identity);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TArgumentListHandler }
|
||||||
|
|
||||||
|
function TArgumentListHandler.GetOrientation: TLayoutOrientation;
|
||||||
|
begin
|
||||||
|
Result := loHorizontal;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TArgumentListHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
arr: TArray<IAstNode>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
SetLength(arr, FChildNodes.Count);
|
||||||
|
for i := 0 to FChildNodes.Count - 1 do
|
||||||
|
arr[i] := FChildNodes[i].CreateAst;
|
||||||
|
|
||||||
|
Result := TArgumentList.Create(arr, FNode.Identity);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TExpressionListHandler }
|
||||||
|
|
||||||
|
function TExpressionListHandler.GetOrientation: TLayoutOrientation;
|
||||||
|
begin
|
||||||
|
Result := loVertical;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TExpressionListHandler.GetAlignment: TLayoutAlignment;
|
||||||
|
begin
|
||||||
|
Result := laFlush;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TExpressionListHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
arr: TArray<IAstNode>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
SetLength(arr, FChildNodes.Count);
|
||||||
|
for i := 0 to FChildNodes.Count - 1 do
|
||||||
|
arr[i] := FChildNodes[i].CreateAst;
|
||||||
|
|
||||||
|
Result := TExpressionList.Create(arr, FNode.Identity);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TRecordFieldListHandler }
|
||||||
|
|
||||||
|
function TRecordFieldListHandler.GetOrientation: TLayoutOrientation;
|
||||||
|
begin
|
||||||
|
Result := loVertical;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRecordFieldListHandler.GetAlignment: TLayoutAlignment;
|
||||||
|
begin
|
||||||
|
Result := laFlush;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRecordFieldListHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
var
|
||||||
|
arr: TArray<IRecordFieldNode>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
SetLength(arr, FChildNodes.Count);
|
||||||
|
for i := 0 to FChildNodes.Count - 1 do
|
||||||
|
arr[i] := FChildNodes[i].CreateAst.AsRecordField;
|
||||||
|
|
||||||
|
Result := TRecordFieldList.Create(arr, FNode.Identity);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
unit Myc.Fmx.AstEditor.Handlers.Primitives;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
System.UITypes,
|
||||||
|
System.SysUtils,
|
||||||
|
Myc.Data.Value,
|
||||||
|
Myc.Ast,
|
||||||
|
Myc.Ast.Nodes,
|
||||||
|
Myc.Fmx.AstEditor.Render,
|
||||||
|
Myc.Fmx.AstEditor.Node;
|
||||||
|
|
||||||
|
type
|
||||||
|
TConstantNodeHandler = class(TBaseNodeHandler<IConstantNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TIdentifierNodeHandler = class(TBaseNodeHandler<IIdentifierNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TKeywordNodeHandler = class(TBaseNodeHandler<IKeywordNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TNopNodeHandler = class(TBaseNodeHandler<INopNode>)
|
||||||
|
public
|
||||||
|
procedure BuildUI(OwnerNode: TAstViewNode); override;
|
||||||
|
function ReconstructAst(OwnerNode: TAstViewNode): IAstNode; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TConstantNodeHandler }
|
||||||
|
|
||||||
|
procedure TConstantNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
valueStr: string;
|
||||||
|
isConcise: Boolean;
|
||||||
|
titleLabel: TTextNode;
|
||||||
|
valLabel: TTextNode;
|
||||||
|
begin
|
||||||
|
valueStr := FNode.Value.ToString;
|
||||||
|
isConcise := ((FNode.Value.Kind = TDataValueKind.vkScalar) or (Pos(sLineBreak, valueStr) = 0)) and (Length(valueStr) < 40);
|
||||||
|
|
||||||
|
if isConcise then
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.BackgroundColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderWidth := 0;
|
||||||
|
|
||||||
|
// Compact representation for scalars
|
||||||
|
OwnerNode.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
OwnerNode.Padding := TMarginRect.Create(0, 0, 0, 0);
|
||||||
|
|
||||||
|
valLabel := OwnerNode.AddLabel(OwnerNode, valueStr);
|
||||||
|
valLabel.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := False;
|
||||||
|
OwnerNode.Orientation := loVertical;
|
||||||
|
|
||||||
|
titleLabel := OwnerNode.AddLabel(OwnerNode, 'Const');
|
||||||
|
titleLabel.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
|
||||||
|
OwnerNode.AddLabel(OwnerNode, valueStr);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TConstantNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Constant(FNode.Identity.AsConstant, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TIdentifierNodeHandler }
|
||||||
|
|
||||||
|
procedure TIdentifierNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
lbl: TTextNode;
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.BackgroundColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderWidth := 0;
|
||||||
|
|
||||||
|
// Compact representation for identifiers
|
||||||
|
OwnerNode.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
OwnerNode.Padding := TMarginRect.Create(0, 0, 0, 0);
|
||||||
|
|
||||||
|
lbl := OwnerNode.AddLabel(OwnerNode, FNode.Name);
|
||||||
|
lbl.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIdentifierNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Identifier(FNode.Identity.AsNamed, FNode.Address, FNode.StaticType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TKeywordNodeHandler }
|
||||||
|
|
||||||
|
procedure TKeywordNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
lbl: TTextNode;
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.BackgroundColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderColor := TAlphaColors.Null;
|
||||||
|
OwnerNode.BorderWidth := 0;
|
||||||
|
|
||||||
|
// Compact representation for keywords
|
||||||
|
OwnerNode.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
OwnerNode.Padding := TMarginRect.Create(0, 0, 0, 0);
|
||||||
|
|
||||||
|
lbl := OwnerNode.AddLabel(OwnerNode, ':' + FNode.Value.Name);
|
||||||
|
lbl.Color := TAlphaColors.Mediumvioletred;
|
||||||
|
lbl.Margins := TMarginRect.Create(1, 0, 1, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TKeywordNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := TAst.Keyword(FNode.Identity.AsKeyword);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TNopNodeHandler }
|
||||||
|
|
||||||
|
procedure TNopNodeHandler.BuildUI(OwnerNode: TAstViewNode);
|
||||||
|
var
|
||||||
|
lbl: TTextNode;
|
||||||
|
begin
|
||||||
|
OwnerNode.Frameless := True;
|
||||||
|
OwnerNode.Alignment := TLayoutAlignment.laCenter;
|
||||||
|
OwnerNode.Orientation := TLayoutOrientation.loHorizontal;
|
||||||
|
lbl := OwnerNode.AddLabel(OwnerNode, '...');
|
||||||
|
lbl.FontSettings.Font.Style := [TFontStyle.fsBold];
|
||||||
|
lbl.Margins := TMarginRect.Create(8, 4, 8, 4);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TNopNodeHandler.ReconstructAst(OwnerNode: TAstViewNode): IAstNode;
|
||||||
|
begin
|
||||||
|
Result := FNode;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,6 @@ uses
|
|||||||
Myc.Ast.Visitor,
|
Myc.Ast.Visitor,
|
||||||
Myc.Fmx.AstEditor.Render, // Virtual Engine
|
Myc.Fmx.AstEditor.Render, // Virtual Engine
|
||||||
Myc.Fmx.AstEditor.Node, // View Nodes
|
Myc.Fmx.AstEditor.Node, // View Nodes
|
||||||
Myc.Fmx.AstEditor.Handlers, // Handlers
|
|
||||||
Myc.Fmx.AstEditor.Workspace; // Host
|
Myc.Fmx.AstEditor.Workspace; // Host
|
||||||
|
|
||||||
type
|
type
|
||||||
@@ -87,6 +86,13 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Myc.Fmx.AstEditor.Handlers,
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Data,
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Control,
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Primitives,
|
||||||
|
Myc.Fmx.AstEditor.Handlers.Lists;
|
||||||
|
|
||||||
// Helper to identify standard operators
|
// Helper to identify standard operators
|
||||||
function IsStandardOperator(const Name: string): Boolean;
|
function IsStandardOperator(const Name: string): Boolean;
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user