DelphiAST icon indicating copy to clipboard operation
DelphiAST copied to clipboard

[Position information] Each node should have begin and end position

Open uschuster opened this issue 10 years ago • 1 comments

#89 was about correct position information for "begin end", repeat and while loops, for "begin end" it was fixed, but repeat and while are of type TSyntaxNode and do not have an end.

Each syntax node should have a begin and an end position. For example a node of type ntUnit starts often at 1:1, but where does it end? The number of whitespaces between "unit" and the unit name itself can be greater than one and guessing the end works only for nodes without whitespaces.

Checking out https://github.com/uschuster/DelphiAST/tree/master/SynEditTest might help to understand the issue. Make sure you compile it with define WITH_SYNTAX_TREE and against VirtualTrees 5.x.

uschuster avatar Jan 13 '16 20:01 uschuster

For repeat the following fix will work:

procedure TPasSyntaxTreeBuilder.RepeatStatement;
begin
//  FStack.Push(ntRepeat);
//  try
//    inherited;
//  finally
//    FStack.Pop;
//  end;
  FStack.PushCompoundSyntaxNode(ntRepeat);
  try
    inherited;
    SetCurrentCompoundNodesEndPosition;
  finally
    FStack.Pop;
  end;
end;

I'm not sure the CompoundSyntaxNode is the fix for all problems.

The while can be a single do statement or a compound statement, so that is sort of covered.

JBontes avatar May 10 '16 19:05 JBontes