Macro expander integrated in binder
This commit is contained in:
@@ -24,7 +24,7 @@ type
|
||||
private
|
||||
FJsonObjectStack: TStack<TJSONObject>;
|
||||
procedure DataValueToJson(const AValue: TDataValue; const AParent: TJSONObject; const AName: string);
|
||||
function JsonToNode(const AJson: TJSONValue): IAstNode;
|
||||
function JsonToNode(const AJson: TJSONValue; const ExpectedType: String = ''): IAstNode;
|
||||
function JsonToDataValue(const AObj: TJSONObject; const AName: string): TDataValue;
|
||||
|
||||
function JsonToConstantNode(const AObj: TJSONObject): IConstantNode;
|
||||
@@ -276,7 +276,6 @@ var
|
||||
param: IIdentifierNode;
|
||||
i: Integer;
|
||||
begin
|
||||
// Added serialization for macro definitions.
|
||||
Node.Name.Accept(Self);
|
||||
for param in Node.Parameters do
|
||||
param.Accept(Self);
|
||||
@@ -719,7 +718,7 @@ function TJsonAstConverter.JsonToMacroDefNode(const AObj: TJSONObject): IMacroDe
|
||||
var
|
||||
name: IIdentifierNode;
|
||||
params: TArray<IIdentifierNode>;
|
||||
body: IAstNode;
|
||||
body: IQuasiquoteNode;
|
||||
paramArray: TJSONArray;
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -731,7 +730,7 @@ begin
|
||||
for i := 0 to paramArray.Count - 1 do
|
||||
params[i] := JsonToIdentifierNode(paramArray.Items[i] as TJSONObject);
|
||||
|
||||
body := JsonToNode(AObj.GetValue('Body'));
|
||||
body := IQuasiquoteNode(JsonToNode(AObj.GetValue('Body'), 'Quasiquote'));
|
||||
Result := TAst.MacroDef(name, params, body);
|
||||
end;
|
||||
|
||||
@@ -874,7 +873,7 @@ begin
|
||||
Result := TAst.SeriesLength(JsonToIdentifierNode(AObj.GetValue('Series') as TJSONObject));
|
||||
end;
|
||||
|
||||
function TJsonAstConverter.JsonToNode(const AJson: TJSONValue): IAstNode;
|
||||
function TJsonAstConverter.JsonToNode(const AJson: TJSONValue; const ExpectedType: String = ''): IAstNode;
|
||||
var
|
||||
obj: TJSONObject;
|
||||
nodeType: string;
|
||||
@@ -885,6 +884,9 @@ begin
|
||||
obj := AJson as TJSONObject;
|
||||
nodeType := obj.GetValue<string>('NodeType');
|
||||
|
||||
if (ExpectedType <> '') and (nodeType <> ExpectedType) then
|
||||
raise EInvalidCast.CreateFmt('Expected a JSON object of type %s for deserialization, but got a %s.', [ExpectedType, nodeType]);
|
||||
|
||||
if nodeType = 'Constant' then
|
||||
Result := JsonToConstantNode(obj)
|
||||
else if nodeType = 'Identifier' then
|
||||
|
||||
Reference in New Issue
Block a user