Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler directives are not recorded #252

Open
JBontes opened this issue Oct 16, 2017 · 0 comments
Open

Compiler directives are not recorded #252

JBontes opened this issue Oct 16, 2017 · 0 comments

Comments

@JBontes
Copy link

JBontes commented Oct 16, 2017

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 pushed a commit to JBontes/DelphiAST that referenced this issue Oct 16, 2017
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 17, 2017
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 17, 2017
JBontes pushed a commit to JBontes/DelphiAST that referenced this issue Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant