Skip to content
Open
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
32 changes: 31 additions & 1 deletion Source/DelphiAST.pas
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ TPasSyntaxTreeBuilder = class(TmwSimplePasParEx)
procedure AddressOp; override;
procedure AlignmentParameter; override;
procedure AnonymousMethod; override;
procedure AnonymousMethodKind; override;
procedure AnonymousMethodType; override;
procedure ArrayBounds; override;
procedure ArrayConstant; override;
procedure ArrayDimension; override;
Expand Down Expand Up @@ -175,6 +177,7 @@ TPasSyntaxTreeBuilder = class(TmwSimplePasParEx)
procedure ParameterName; override;
procedure PointerSymbol; override;
procedure PointerType; override;
procedure ProceduralDirectiveOf; override;
procedure ProceduralType; override;
procedure ProcedureHeading; override;
procedure ProcedureDeclarationSection; override;
Expand Down Expand Up @@ -294,7 +297,8 @@ TStringStreamHelper = class helper for TStringStream
type
TAttributeValue = (atAsm, atTrue, atFunction, atProcedure, atClassOf, atClass,
atConst, atConstructor, atDestructor, atEnum, atInterface, atNil, atNumeric,
atOut, atPointer, atName, atString, atSubRange, atVar, atDispInterface);
atOut, atPointer, atName, atString, atSubRange, atVar, atDispInterface,
atOfObject, atReferenceTo);

var
AttributeValues: array[TAttributeValue] of string;
Expand Down Expand Up @@ -455,6 +459,26 @@ procedure TPasSyntaxTreeBuilder.AnonymousMethod;
end;
end;

procedure TPasSyntaxTreeBuilder.AnonymousMethodKind;
var
value: string;
begin
value := LowerCase(Lexer.Token);
DoHandleString(value);
FStack.Peek.SetAttribute(anName, value);
inherited;
end;

procedure TPasSyntaxTreeBuilder.AnonymousMethodType;
begin
FStack.Push(ntType).SetAttribute(anKind, AttributeValues[atReferenceTo]);
try
inherited;
finally
FStack.Pop;
end;
end;

procedure TPasSyntaxTreeBuilder.ArrayBounds;
begin
FStack.Push(ntBounds);
Expand Down Expand Up @@ -1890,6 +1914,12 @@ procedure TPasSyntaxTreeBuilder.PositionalArgument;
end;
end;

procedure TPasSyntaxTreeBuilder.ProceduralDirectiveOf;
begin
FStack.Peek.SetAttribute(anKind, AttributeValues[atOfObject]);
inherited;
end;

procedure TPasSyntaxTreeBuilder.ProceduralType;
begin
FStack.Push(ntType).SetAttribute(anName, Lexer.Token);
Expand Down
10 changes: 8 additions & 2 deletions Source/SimpleParser/SimpleParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ TmwSimplePasPar = class(TObject)
procedure AncestorIdList; virtual;
procedure AncestorId; virtual;
procedure AnonymousMethod; virtual;
procedure AnonymousMethodKind; virtual;
procedure AnonymousMethodType; virtual;
procedure ArrayConstant; virtual;
procedure ArrayBounds; virtual;
Expand Down Expand Up @@ -5591,20 +5592,25 @@ procedure TmwSimplePasPar.AnonymousMethod;
Block;
end;

procedure TmwSimplePasPar.AnonymousMethodKind;
begin
NextToken;
end;

procedure TmwSimplePasPar.AnonymousMethodType;
begin
ExpectedEx(ptReference);
Expected(ptTo);
case TokenID of
ptProcedure:
begin
NextToken;
AnonymousMethodKind;
if TokenID = ptRoundOpen then
FormalParameterList;
end;
ptFunction:
begin
NextToken;
AnonymousMethodKind;
if TokenID = ptRoundOpen then
FormalParameterList;
Expected(ptColon);
Expand Down
24 changes: 24 additions & 0 deletions Test/Snippets/proceduraltypes.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
unit proceduraltypes;

interface

type
TPlainProc = procedure(const aX: Integer);
TPlainFunc = function(const aX: Integer): Boolean;

TMethodProc = procedure(const aX: Integer) of object;
TMethodFunc = function(const aX: Integer): Boolean of object;

TAnonProc = reference to procedure(const aX: Integer);
TAnonFunc = reference to function(const aX: Integer): Boolean;

TNoParamsProc = procedure;
TNoParamsMethod = procedure of object;
TNoParamsAnon = reference to procedure;

TStdCallProc = procedure(const aX: Integer); stdcall;
TStdCallMethod = procedure(const aX: Integer) of object; stdcall;

implementation

end.