164 lines
4.8 KiB
ObjectPascal
164 lines
4.8 KiB
ObjectPascal
unit Myc.Ast.Attributes;
|
|
|
|
interface
|
|
|
|
uses
|
|
system.sysutils;
|
|
|
|
type
|
|
{ Defines the content type for the LLM schema generation. }
|
|
TFieldKind = (
|
|
fkNode, // Node (recursive structure)
|
|
fkIdentifier, // Identifier ["Id", "name"]
|
|
fkKeyword, // Keyword literal ["Key", "name"]
|
|
fkLambda, // Lambda definition ["Fn", [...], body]
|
|
fkTuple, // Tuple (explicit ["Tuple", [...]] structure)
|
|
fkString, // Raw String (for identifiers/names)
|
|
fkValue, // TDataValue (primitive constants like number, string, boolean)
|
|
fkNullableNode, // Optional Node ('AstNode | null')
|
|
fkArrayOfNodes, // Raw Array of Nodes (used inside Tuple)
|
|
fkArrayOfPairs, // Special structure for CondExpr: [[Cond, Branch], ...]
|
|
fkArrayOfKeys, // Special structure for an array of keywords
|
|
fkPipeInputs // Specific structure: ["Tuple", [ ["Tuple", [Id, Tuple]], ... ]]
|
|
);
|
|
|
|
{ AstTagAttribute: Defines the JSON Tag for an AST Node. }
|
|
AstTagAttribute = class(TCustomAttribute)
|
|
private
|
|
FTag: string;
|
|
public
|
|
constructor Create(const ATag: string);
|
|
property Tag: string read FTag;
|
|
end;
|
|
|
|
{ AstFieldAttribute: Defines a field within the JSON Array. }
|
|
AstFieldAttribute = class(TCustomAttribute)
|
|
private
|
|
FName: string;
|
|
FKind: TFieldKind;
|
|
FIndex: Integer;
|
|
public
|
|
constructor Create(AIndex: Integer; const AName: string; AKind: TFieldKind);
|
|
property Index: Integer read FIndex;
|
|
property Name: string read FName;
|
|
property Kind: TFieldKind read FKind;
|
|
end;
|
|
|
|
{ AstDocAttribute: Provides semantic documentation for the LLM. }
|
|
AstDocAttribute = class(TCustomAttribute)
|
|
private
|
|
FDescription: string;
|
|
public
|
|
constructor Create(const ADescription: string);
|
|
property Description: string read FDescription;
|
|
end;
|
|
|
|
{ AstScriptExampleAttribute: Provides an example in script syntax.
|
|
The generator converts this to JSON AST for the LLM prompt. }
|
|
AstScriptExampleAttribute = class(TCustomAttribute)
|
|
private
|
|
FScript: string;
|
|
public
|
|
constructor Create(const AScript: string);
|
|
property Script: string read FScript;
|
|
end;
|
|
|
|
{ AstSignatureAttribute: Defines a specific overload signature for an RTL function. }
|
|
AstSignatureAttribute = class(TCustomAttribute)
|
|
private
|
|
FSignature: string;
|
|
public
|
|
constructor Create(const ASignature: string);
|
|
property Signature: string read FSignature;
|
|
end;
|
|
|
|
// Decorates a native function to be exported to the Myc runtime.
|
|
// 'IsPure' hints the compiler that the function has no side effects.
|
|
TRtlExportAttribute = class(TCustomAttribute)
|
|
type
|
|
TPurity = (Pure, Impure);
|
|
public
|
|
Name: string;
|
|
IsPure: Boolean;
|
|
constructor Create(const AName: string); overload;
|
|
constructor Create(const AName: string; APurity: TPurity); overload;
|
|
end;
|
|
|
|
// Decorates a class function to be exported as a constant value.
|
|
// The function is invoked once at registration time.
|
|
TRtlConstAttribute = class(TCustomAttribute)
|
|
public
|
|
Name: string;
|
|
constructor Create(const AName: string);
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ AstTagAttribute }
|
|
|
|
constructor AstTagAttribute.Create(const ATag: string);
|
|
begin
|
|
inherited Create;
|
|
FTag := ATag;
|
|
end;
|
|
|
|
{ AstFieldAttribute }
|
|
|
|
constructor AstFieldAttribute.Create(AIndex: Integer; const AName: string; AKind: TFieldKind);
|
|
begin
|
|
inherited Create;
|
|
FIndex := AIndex;
|
|
FName := AName;
|
|
FKind := AKind;
|
|
end;
|
|
|
|
{ AstDocAttribute }
|
|
|
|
constructor AstDocAttribute.Create(const ADescription: string);
|
|
begin
|
|
inherited Create;
|
|
FDescription := ADescription;
|
|
end;
|
|
|
|
{ AstScriptExampleAttribute }
|
|
|
|
constructor AstScriptExampleAttribute.Create(const AScript: string);
|
|
begin
|
|
inherited Create;
|
|
FScript := AScript;
|
|
end;
|
|
|
|
{ AstSignatureAttribute }
|
|
|
|
constructor AstSignatureAttribute.Create(const ASignature: string);
|
|
begin
|
|
inherited Create;
|
|
FSignature := ASignature;
|
|
end;
|
|
|
|
//==================================================================================================
|
|
// Attribute Implementations
|
|
//==================================================================================================
|
|
|
|
constructor TRtlExportAttribute.Create(const AName: string);
|
|
begin
|
|
inherited Create;
|
|
Name := AName;
|
|
IsPure := False;
|
|
end;
|
|
|
|
constructor TRtlExportAttribute.Create(const AName: string; APurity: TPurity);
|
|
begin
|
|
inherited Create;
|
|
Name := AName;
|
|
IsPure := APurity = Pure;
|
|
end;
|
|
|
|
constructor TRtlConstAttribute.Create(const AName: string);
|
|
begin
|
|
inherited Create;
|
|
Name := AName;
|
|
end;
|
|
|
|
end.
|