DelphiAST icon indicating copy to clipboard operation
DelphiAST copied to clipboard

Compiler directives are not recorded

Open JBontes opened this issue 8 years ago • 0 comments

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;

JBontes avatar Oct 16 '17 12:10 JBontes