You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to provide the implementing developer with the ability to specify what constructs of the source to include within the Syntax Tree.
This could be done as a Set, so the implementing developer can choose to, for example, exclude the complete STATEMENTS section from each method implementation from the Syntax Tree, or to exclude global variables/constants etc.
This way, if a tool using the AST is only interested in a particular area of the source, they can omit the rest and make the subsequent scraping/transformation operation(s) of their implementing tool quicker.
The text was updated successfully, but these errors were encountered:
This is difficult to do in the actual AST building, but very easy to do in the generation of the output XML:
procedure NodeToXMLInternal(const Node: TSyntaxNode; const Indent: string);
var
HasChildren: Boolean;
NewIndent: string;
Attr: TPair<TAttributeType, string>;
ChildNode: TSyntaxNode;
NodeOK: boolean;
begin
NodeOK:= not(Node.Typ in Exclude) and (Node.Typ in InternalInclude);
HasChildren := Node.HasChildren;
if NodeOK then begin
if Formatted then begin
NewIndent:= Indent + ' ';
Builder.Append(Indent);
end;
Builder.Append('<' + UpperCase(SyntaxNodeNames[Node.Typ]));
if (Node is TCompoundSyntaxNode) then begin
Builder.Append(' begin_line="' + IntToStr(TCompoundSyntaxNode(Node).Line) + '"');
Builder.Append(' begin_col="' + IntToStr(TCompoundSyntaxNode(Node).Col) + '"');
Builder.Append(' end_line="' + IntToStr(TCompoundSyntaxNode(Node).EndLine) + '"');
Builder.Append(' end_col="' + IntToStr(TCompoundSyntaxNode(Node).EndCol) + '"');
end else begin
Builder.Append(' line="' + IntToStr(Node.Line) + '"');
Builder.Append(' col="' + IntToStr(Node.Col) + '"');
end;
for Attr in Node.Attributes do Builder.Append(' ' + AttributeName[Attr.Key] + '="' + XMLEncode(Attr.Value) + '"');
if HasChildren then Builder.Append('>')
else Builder.Append('/>');
if Formatted then Builder.AppendLine;
end;
for ChildNode in Node.ChildNodes do NodeToXMLInternal(ChildNode, NewIndent);
if NodeOK then begin
if HasChildren then begin
if Formatted then Builder.Append(Indent);
Builder.Append('</' + UpperCase(SyntaxNodeNames[Node.Typ]) + '>');
if Formatted then Builder.AppendLine;
end;
end;
end;
begin
if Include = [] then InternalInclude:= [ntUnknown..ntWrite]
else InternalInclude:= Include;
NodeToXMLInternal(Node, '');
end;
It would be useful to provide the implementing developer with the ability to specify what constructs of the source to include within the Syntax Tree.
This could be done as a Set, so the implementing developer can choose to, for example, exclude the complete STATEMENTS section from each method implementation from the Syntax Tree, or to exclude global variables/constants etc.
This way, if a tool using the AST is only interested in a particular area of the source, they can omit the rest and make the subsequent scraping/transformation operation(s) of their implementing tool quicker.
The text was updated successfully, but these errors were encountered: