DelphiAST
DelphiAST copied to clipboard
Compiler directives are not recorded
For now we should simply record any compiler directives. In future we should have some parsing for the directives.
The fix:
procedure TPasSyntaxTreeBuilder.CompilerDirective;
begin
FStack.AddValuedChild(ntCompilerDirective, Lexer.Token);
inherited;
end;
procedure TmwSimplePasPar.CompilerDirective;
begin
Expected(ptCompDirect);
end;
procedure TmwSimplePasPar.HandlePtCompDirect(Sender: TmwBasePasLex);
begin
if (not Lexer.IsJunk) then CompilerDirective;
end;
An attempt at parsing compiler directives:
procedure TPasSyntaxTreeBuilder.CompilerDirective;
var
Directive: string;
Node: TSyntaxNode;
Part2: integer;
begin
Directive:= Uppercase(Lexer.Token);
Node:= FStack.AddValuedChild(ntCompilerDirective, Directive);
//Parse the directive
if (Directive.StartsWith('(*$')) then begin
Delete(Directive, 1, 3);
StringReplace(Directive,'*)','}',[]);
end else begin
Delete(Directive, 1, 2);
end;
Part2:= 1;
while not(Directive[Part2] in [' ', '+', '-', '}']) do begin
Inc(Part2);
end;
Node.Attribute[anType]:= LeftStr(Directive, Part2-1);
Delete(Directive, 1, Part2-1);
Delete(Directive, Length(Directive), 1);
Directive:= Trim(Directive);
Node.Attribute[anKind]:= Directive;
inherited;
end;