Skip to content

Commit

Permalink
RomanYankovsky#255 Treat array of const correctly
Browse files Browse the repository at this point in the history
array of const is a special construct. `const` here is not an identifier.
  • Loading branch information
jbontes committed Oct 17, 2017
1 parent 5fcd93f commit bbbe2e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Source/DelphiAST.pas
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ TPasSyntaxTreeBuilder = class(TmwSimplePasPar)
procedure ArrayBounds; override;
procedure ArrayConstant; override;
procedure ArrayDimension; override;
procedure ArrayOfConst; override;
procedure AsmStatement; override;
procedure AsOp; override;
procedure AssignOp; override;
Expand Down Expand Up @@ -584,6 +585,17 @@ procedure TPasSyntaxTreeBuilder.ArrayDimension;
end;
end;

procedure TPasSyntaxTreeBuilder.ArrayOfConst;
begin
//do not fill the name attribute. const is a keyword, not a type.
FStack.Push(ntType).Attribute[anKind]:= AttributeValues[atConst];
try
inherited;
finally
FStack.Pop;
end;
end;

procedure TPasSyntaxTreeBuilder.AsmStatement;
begin
FStack.PushCompoundSyntaxNode(ntStatements).Attribute[anType]:= AttributeValues[atAsm];
Expand Down
47 changes: 32 additions & 15 deletions Source/SimpleParser/SimpleParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ TmwSimplePasPar = class(TObject)
procedure ArrayConstant; virtual;
procedure ArrayBounds; virtual;
procedure ArrayDimension; virtual;
procedure ArrayOfConst; virtual;
procedure ArraySubType; virtual;
procedure ArrayType; virtual;
procedure AsmStatement; virtual;
procedure AssignOp; virtual;
Expand Down Expand Up @@ -795,7 +797,7 @@ procedure TmwSimplePasPar.ExpectedEx(const Syms: TptTokenKinds);
for Sym in Syms do begin
Symbols:= Symbols + Optional + TokenName(Sym);
Optional:= ' or ';
end;
end;
if (Lexer.TokenID = ptNull) then
raise ESyntaxError.CreatePos(Format(rsExpected, [Symbols, rsEndOfFile]), FLexer.PosXY)
else if Assigned(FOnMessage) then begin
Expand Down Expand Up @@ -1015,7 +1017,7 @@ procedure TmwSimplePasPar.ThenStatement;
procedure TmwSimplePasPar.Semicolon;
begin
case Lexer.TokenID of
ptElse, ptEnd, ptExcept, ptfinally, ptFinalization, ptRoundClose, ptUntil: ;
ptElse, ptEnd, ptExcept, ptFinally, ptFinalization, ptRoundClose, ptUntil: ;
else
Expected(ptSemiColon);
end;
Expand Down Expand Up @@ -1438,12 +1440,12 @@ procedure TmwSimplePasPar.AccessSpecifier;

procedure TmwSimplePasPar.ReadAccessIdentifier;
begin
variable;
Variable;
end;

procedure TmwSimplePasPar.WriteAccessIdentifier;
begin
variable;
Variable;
end;

procedure TmwSimplePasPar.StorageSpecifier;
Expand Down Expand Up @@ -3304,7 +3306,7 @@ procedure TmwSimplePasPar.ArrayType;
Expected(ptArray);
ArrayBounds;
Expected(ptOf);
TypeKind;
ArraySubType;
end;

procedure TmwSimplePasPar.EnumeratedType;
Expand Down Expand Up @@ -4261,6 +4263,19 @@ procedure TmwSimplePasPar.ArrayDimension;
OrdinalType;
end;

procedure TmwSimplePasPar.ArrayOfConst;
begin
Expected(ptConst);
end;

procedure TmwSimplePasPar.ArraySubType;
begin
case TokenID of
ptConst: ArrayOfConst;
else TypeKind;
end;
end;

procedure TmwSimplePasPar.ClassForward;
begin
Expected(ptClass);
Expand Down Expand Up @@ -4867,16 +4882,16 @@ procedure TmwSimplePasPar.TypeSimple;
begin
NextToken;
Expected(ptOf);
case TokenID of
ptConst: (*new in ObjectPascal80*)
begin
NextToken;
end;
else
begin
TypeID;
end;
end;
// case TokenID of
// ptConst: (*new in ObjectPascal80*)
// begin
// NextToken;
// end;
// else
// begin
TypeID;
// end;
// end;
end;
else
Expected(ptIdentifier);
Expand Down Expand Up @@ -5465,10 +5480,12 @@ procedure TmwSimplePasPar.AnonymousMethodType;
end;
end;
end;

procedure TmwSimplePasPar.AnonymousMethodTypeProcedure;
begin
Expected(ptProcedure);
end;

procedure TmwSimplePasPar.AnonymousMethodTypeFunction;
begin
Expected(ptFunction);
Expand Down

0 comments on commit bbbe2e2

Please sign in to comment.