Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/DelphiAST.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,7 @@ function TPasSyntaxTreeBuilder.Run(SourceStream: TStream): TSyntaxNode;
on E: EParserException do
raise ESyntaxTreeException.Create(E.Line, E.Col, Lexer.FileName, E.Message, Result);
on E: ESyntaxError do
raise ESyntaxTreeException.Create(E.PosXY.X, E.PosXY.Y, Lexer.FileName, E.Message, Result);
raise ESyntaxTreeException.Create(E.PosXY.Y, E.PosXY.X, Lexer.FileName, E.Message, Result);
else
FreeAndNil(Result);
raise;
Expand Down
23 changes: 23 additions & 0 deletions Test/UnitTests/DelphiAST.Tests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ procedure TestInvalidSyntax;
AssertTrue(Raised, 'Invalid syntax did not raise ESyntaxTreeException');
end;

procedure TestUnexpectedEndOfFilePosition;
var
Root: TSyntaxNode;
Raised: Boolean;
begin
Root := nil;
Raised := False;
try
Root := ParseSource('unit Broken;' + sLineBreak + 'interface' + sLineBreak +
'implementation' + sLineBreak + 'procedure Run;' + sLineBreak + 'begin');
except
on E: ESyntaxTreeException do
begin
Raised := True;
AssertEquals(5, E.Line, 'The end of file is on line 5.');
AssertEquals(6, E.Col, 'The end of file is after the 5 characters of "begin".');
end;
end;
Root.Free;
AssertTrue(Raised, 'An unexpected end of file did not raise ESyntaxTreeException');
end;

{$IFNDEF FPC}
procedure TestBinarySerializationRoundTrip;
var
Expand Down Expand Up @@ -296,6 +318,7 @@ procedure RunAllTests;
RunTest('AST.ConstantEndPosition', TestConstantEndPosition);
RunTest('AST.VariableEndPosition', TestVariableEndPosition);
RunTest('Parser.InvalidSyntax', TestInvalidSyntax);
RunTest('Parser.UnexpectedEndOfFilePosition', TestUnexpectedEndOfFilePosition);
{$IFNDEF FPC}
RunTest('Serialization.BinaryRoundTrip', TestBinarySerializationRoundTrip);
{$ENDIF}
Expand Down
Loading