gotthardsen / Delphi-ANTRL4-Grammar

ANTLR4 Grammar and C# parser, lexer for Delphi XE
GNU Lesser General Public License v3.0
16 stars 7 forks source link

Omit formalParameterSection and typeDecl when implement a declared pure function #3

Open zhsh00 opened 2 years ago

zhsh00 commented 2 years ago

when define the function of object in Delphi.g4. the formalParameterSection and typeDecl are not necessary.but when define the pure function, it's not.

methodDeclHeading            : (customAttribute)? ('class')?  methodKey methodName (formalParameterSection)?
                             | (customAttribute)? ('class')? 'function' methodName (formalParameterSection)? (':' (customAttribute)? typeDecl)?
                             | (customAttribute)? 'class' 'operator' methodName (formalParameterSection)? (':' (customAttribute)? typeDecl)?
                             ;    
procDeclHeading              : (customAttribute)? 'procedure' ident (formalParameterSection)?             //CHANGED
                             | (customAttribute)? 'function' ident (formalParameterSection)? ':' typeDecl
                             ;

I think it should like this(And Delphi6 can recognize this style code yet):

procDeclHeading              : (customAttribute)? 'procedure' ident (formalParameterSection)?             //CHANGED
                             | (customAttribute)? 'function' ident (formalParameterSection)? (':' typeDecl)?
                             ;

test case:

unit FunctionImplementOmitDeclParamAndResult;

interface

function GetShortName(S: WideString): WideString;

implementation

function GetShortName;
begin
  begin
//Result := S;
  end;
end;

end.

Maybe, We should use 2 rules for declaration and implementation of the pure procedure(function) and method?