Skip to content

Report a syntax error at its line, not its column - #2

Merged
partouf merged 1 commit into
mainfrom
fix/syntax-error-position
Oct 8, 2026
Merged

partouf merged 1 commit into
mainfrom
fix/syntax-error-position

Conversation

@partouf

@partouf partouf commented Oct 8, 2026

Copy link
Copy Markdown
Member

Bug. TPasSyntaxTreeBuilder.Run(SourceStream) turns an ESyntaxError into ESyntaxTreeException.Create(Line, Col, ...) but passed E.PosXY.X, E.PosXY.Y. TmwBasePasLex.GetPosXY puts the column in X and the line in Y, so line and column were swapped. The EParserException path next to it was already right, and so is ParserMessage, which passes Y, X.

Repro. ESyntaxError comes from ExpectedFatal, which is how an unexpected end of file is reported:

unit Broken;
interface
implementation
procedure Run;
begin

The exception reported line 6, col 5. It now reports line 5, col 6.

Fix. Pass E.PosXY.Y, E.PosXY.X.

Test. Parser.UnexpectedEndOfFilePosition is added to Test/UnitTests. It fails on main ("Expected 5 but got 6") and passes with this change.

TPasSyntaxTreeBuilder.Run turns an ESyntaxError into an ESyntaxTreeException,
whose constructor takes the line first and the column second. It passed
E.PosXY.X, E.PosXY.Y, but TmwBasePasLex.GetPosXY puts the column in X and the
line in Y, so the two came out swapped. The EParserException path next to it
was right; ParserMessage already passes Y, X.

ESyntaxError is what ExpectedFatal raises, which is how an unexpected end of
file is reported. A unit that stops after the `begin` of a routine on line 5

  unit Broken;
  interface
  implementation
  procedure Run;
  begin

was reported at line 6, col 5 instead of line 5, col 6.
@partouf
partouf merged commit d1649b5 into main Oct 8, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

1 participant