dgrok icon indicating copy to clipboard operation
dgrok copied to clipboard

Fix the wrong look-ahead for the TypeDecl rule

Open tomalla5120x opened this issue 7 years ago • 0 comments

Given the following code:

unit Unit1;
interface
type
    TMyClass = class
    private
        type
            TMyRec = record
            end;
    protected
        Foo: Integer;
    end;
implementation
end.

The parser incorrectly interprets the semi-keyword 'protected' as a type identifier and issues the following error message: "Expected EqualSign but found Identifier".

The visibility specifiers are indeed semi-keywords, i.e. they can in certain situations be treated as identifiers (like procedure names for instance). This however is an exception, where visibility specifiers strict, private, public, protected and published (among other keywords like procedure, class or type) explicitly terminate the nested type declarations section.

The solution was simple: in a look-ahead procedure for the TypeDecl rule, I added an additional constraint check for visibility semi-keywords. If they are present, the rule is no longer accepted and the type section is terminated.

tomalla5120x avatar Apr 08 '17 12:04 tomalla5120x