← board

Bug — Lexer misidentifies identifiers ending with keyword names (e.g. 'Class')

Description

The compiler scanner/lexer appears to check for keywords (like class) using a suffix or substring match rather than full-word boundaries. As a result, user-defined identifiers that contain or end with a keyword name (such as TMyClass ending with Class) are incorrectly tokenized as keyword tokens rather than standard identifier tokens. This leads to unexpected parse errors like Expected: :=, but got: . or unexpected token on valid variable declarations and method calls.

Steps to Reproduce

This code fails to compile:

program test_bug;
type
  TMyClass = class
    Value : Integer;
    procedure Reset;
  end;

procedure TMyClass.Reset;
begin
  Self.Value := 0;
end;

var c: TMyClass;
begin
  c := TMyClass.Create;
  c.Reset; // pascal26:16: error: unexpected token (Expected: :=, but got: .)
end.

If TMyClass is renamed to anything not containing/ending with Class (e.g. TMyClazz or TLifeHandler), it compiles and runs successfully.

Expected Behavior

The lexer should strictly tokenize keywords when they match exactly on identifier boundaries (e.g. using [a-zA-Z_][a-zA-Z0-9_]* match rules) rather than identifying them as substrings or suffixes within larger user-defined identifiers.

Resolution — REJECTED (not reproducible)