Keywords
This commit is contained in:
@@ -9,6 +9,7 @@ uses
|
||||
System.Generics.Defaults,
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Value,
|
||||
Myc.Data.Keyword,
|
||||
Myc.Ast.Nodes,
|
||||
Myc.Ast.Types,
|
||||
Myc.Ast.Scope;
|
||||
@@ -31,6 +32,7 @@ type
|
||||
// --- Factory functions ---
|
||||
class function Constant(const AValue: TDataValue): IConstantNode; overload; static;
|
||||
class function Constant(const AValue: String): IConstantNode; overload; static;
|
||||
class function Keyword(const AName: string): IKeywordNode; static;
|
||||
class function Identifier(AName: string): IIdentifierNode; static;
|
||||
class function BinaryExpr(ALeft: IAstNode; AOperator: TScalar.TBinaryOp; ARight: IAstNode): IBinaryExpressionNode; static;
|
||||
class function UnaryExpr(const AOperator: TScalar.TUnaryOp; const ARight: IAstNode): IUnaryExpressionNode; static;
|
||||
@@ -57,6 +59,7 @@ type
|
||||
class function AssignResult(const AValue: IAstNode): IAssignmentNode; static; deprecated;
|
||||
class function Indexer(const ABase: IAstNode; const AIndex: IAstNode): IIndexerNode; static;
|
||||
class function MemberAccess(const ABase: IAstNode; const AMember: IIdentifierNode): IMemberAccessNode; static;
|
||||
class function RecordLiteral(const AFields: TArray<TRecordFieldLiteral>): IRecordLiteralNode; static;
|
||||
class function CreateSeries(const ADefinition: String): ICreateSeriesNode; static;
|
||||
class function AddSeriesItem(
|
||||
const ASeries: IIdentifierNode;
|
||||
@@ -96,6 +99,16 @@ type
|
||||
property Name: string read FName;
|
||||
end;
|
||||
|
||||
TKeywordNode = class(TAstNode, IKeywordNode)
|
||||
private
|
||||
FValue: IKeyword;
|
||||
function GetValue: IKeyword;
|
||||
public
|
||||
constructor Create(const AName: string);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
property Value: IKeyword read FValue;
|
||||
end;
|
||||
|
||||
TBinaryExpressionNode = class(TAstNode, IBinaryExpressionNode)
|
||||
private
|
||||
FLeft: IAstNode;
|
||||
@@ -287,6 +300,16 @@ type
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
end;
|
||||
|
||||
TRecordLiteralNode = class(TAstNode, IRecordLiteralNode)
|
||||
private
|
||||
FFields: TArray<TRecordFieldLiteral>;
|
||||
function GetFields: TArray<TRecordFieldLiteral>;
|
||||
public
|
||||
constructor Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
function Accept(const Visitor: IAstVisitor): TDataValue; override;
|
||||
property Fields: TArray<TRecordFieldLiteral> read FFields;
|
||||
end;
|
||||
|
||||
TCreateSeriesNode = class(TAstNode, ICreateSeriesNode)
|
||||
private
|
||||
FDefinition: String;
|
||||
@@ -367,6 +390,25 @@ begin
|
||||
Result := FName;
|
||||
end;
|
||||
|
||||
{ TKeywordNode }
|
||||
|
||||
constructor TKeywordNode.Create(const AName: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FValue := TKeywordRegistry.Intern(AName);
|
||||
StaticType := TTypes.Keyword;
|
||||
end;
|
||||
|
||||
function TKeywordNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitKeyword(Self);
|
||||
end;
|
||||
|
||||
function TKeywordNode.GetValue: IKeyword;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TBinaryExpressionNode }
|
||||
|
||||
constructor TBinaryExpressionNode.Create(const ALeft: IAstNode; AOperator: TScalar.TBinaryOp; const ARight: IAstNode);
|
||||
@@ -768,6 +810,24 @@ begin
|
||||
Result := FMember;
|
||||
end;
|
||||
|
||||
{ TRecordLiteralNode }
|
||||
|
||||
constructor TRecordLiteralNode.Create(const AFields: TArray<TRecordFieldLiteral>);
|
||||
begin
|
||||
inherited Create;
|
||||
FFields := AFields;
|
||||
end;
|
||||
|
||||
function TRecordLiteralNode.Accept(const Visitor: IAstVisitor): TDataValue;
|
||||
begin
|
||||
Result := Visitor.VisitRecordLiteral(Self);
|
||||
end;
|
||||
|
||||
function TRecordLiteralNode.GetFields: TArray<TRecordFieldLiteral>;
|
||||
begin
|
||||
Result := FFields;
|
||||
end;
|
||||
|
||||
{ TCreateSeriesNode }
|
||||
|
||||
constructor TCreateSeriesNode.Create(const ADefinition: String);
|
||||
@@ -930,6 +990,11 @@ begin
|
||||
Result := TIndexerNode.Create(ABase, AIndex);
|
||||
end;
|
||||
|
||||
class function TAst.Keyword(const AName: string): IKeywordNode;
|
||||
begin
|
||||
Result := TKeywordNode.Create(AName);
|
||||
end;
|
||||
|
||||
class function TAst.LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode): ILambdaExpressionNode;
|
||||
begin
|
||||
Result := TLambdaExpressionNode.Create(AParameters, ABody);
|
||||
@@ -965,6 +1030,11 @@ begin
|
||||
Result := TRecurNode.Create(args);
|
||||
end;
|
||||
|
||||
class function TAst.RecordLiteral(const AFields: TArray<TRecordFieldLiteral>): IRecordLiteralNode;
|
||||
begin
|
||||
Result := TRecordLiteralNode.Create(AFields);
|
||||
end;
|
||||
|
||||
class function TAst.SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode;
|
||||
begin
|
||||
Result := TSeriesLengthNode.Create(ASeries);
|
||||
|
||||
Reference in New Issue
Block a user