RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

Array digraphs (. .) do not work with integer indexes #263

Open JBontes opened 6 years ago

JBontes commented 6 years ago

The following code will not process correctly

unit TestAST;

interface

implementation

procedure test;
var
  x: array of string;
begin
  x[10]:= 'test';
  x(.11.):= 'test2';
end;

end.

The 11 will be seen as a float number.

JBontes commented 6 years ago

The fix is as follows:

procedure TmwBasePasLex.NumberProc;
begin
  Inc(FBuffer.Run);
  FTokenID := ptIntegerConst;
  while CharInSet(FBuffer.Buf[FBuffer.Run], ['0'..'9', '.', 'e', 'E']) do
  begin
    case FBuffer.Buf[FBuffer.Run] of
      '.':
        if FBuffer.Buf[FBuffer.Run + 1] in ['.',')'] then    //(. .) digraph
          Break
        else
          FTokenID := ptFloat
    end;
    Inc(FBuffer.Run);
  end;
end;

Will do a pull request if I find more issues.