mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 17:59:27 +02:00
* Delphi allows TEnum.in
This commit is contained in:
parent
be5e84715c
commit
fc6fc67295
@ -2627,6 +2627,8 @@ var
|
||||
SrcPos, ScrPos: TPasSourcePos;
|
||||
ProcType: TProcType;
|
||||
ProcExpr: TProcedureExpr;
|
||||
AllowKWAsSubIdent : Boolean;
|
||||
|
||||
begin
|
||||
Result:=nil;
|
||||
CanSpecialize:=aCannot;
|
||||
@ -2723,7 +2725,7 @@ begin
|
||||
else
|
||||
ParseExcExpectedIdentifier;
|
||||
end;
|
||||
|
||||
AllowKWAsSubIdent:=(msDelphi in CurrentModeswitches);
|
||||
Result:=Last;
|
||||
ISE:=nil;
|
||||
NextToken;
|
||||
@ -2754,6 +2756,17 @@ begin
|
||||
Func:=Expr;
|
||||
NextToken;
|
||||
end
|
||||
else if AllowKWAsSubIdent and (Curtoken>=tkabsolute) and (Curtoken<=tkXor) then
|
||||
begin
|
||||
// Delphi allows keywords as identifier e.g. TEnum.In, but only for enums.
|
||||
// Unfortunately, we do not know at this point if the previous identifier is an enum, so we allow it always.
|
||||
// Not ideal :/
|
||||
aName:=aName+'.'+CurTokenString;
|
||||
Expr:=CreatePrimitiveExpr(AParent,pekIdent,CurTokenString);
|
||||
AddToBinaryExprChain(Result,Expr,eopSubIdent,ScrPos);
|
||||
Func:=Expr;
|
||||
NextToken;
|
||||
end
|
||||
else
|
||||
begin
|
||||
UngetToken;
|
||||
@ -2947,6 +2960,7 @@ const
|
||||
Var
|
||||
AllowedBinaryOps : Set of TToken;
|
||||
SrcPos: TPasSourcePos;
|
||||
|
||||
begin
|
||||
AllowedBinaryOps:=BinaryOP;
|
||||
if Not AllowEqual then
|
||||
|
@ -5,7 +5,7 @@ unit tcexprparser;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, tcbaseparser, pastree, PScanner;
|
||||
Classes, SysUtils, fpcunit, testregistry, tcbaseparser, pastree, pparser, PScanner;
|
||||
|
||||
type
|
||||
|
||||
@ -110,6 +110,8 @@ type
|
||||
Procedure TestAPlusBBracketDotC;
|
||||
Procedure TestADotBDotC;
|
||||
Procedure TestADotBBracketC;
|
||||
procedure TestADotKeyWord;
|
||||
procedure TestADotKeyWordOnlyDelphi;
|
||||
Procedure TestSelfDotBBracketC;
|
||||
Procedure TestAasBDotCBracketFuncParams;
|
||||
Procedure TestRange;
|
||||
@ -1236,6 +1238,27 @@ begin
|
||||
AssertExpression('right b',PlusB.Right,pekIdent,'b');
|
||||
end;
|
||||
|
||||
procedure TTestExpressions.TestADotKeyWord;
|
||||
|
||||
begin
|
||||
Add('{$MODE DELPHI}');
|
||||
Add('Type TEnum = (&in,&of);');
|
||||
Add('Var a : TEnum;');
|
||||
Add('begin');
|
||||
Add(' a:=Tenum.in;');
|
||||
ParseExpression;
|
||||
AssertExpression('Binary identifier',TheExpr,pekBinary,TBinaryExpr);
|
||||
end;
|
||||
|
||||
procedure TTestExpressions.TestADotKeyWordOnlyDelphi;
|
||||
begin
|
||||
Add('Type TEnum = (&in,&of);');
|
||||
Add('Var a : TEnum;');
|
||||
Add('begin');
|
||||
Add(' a:=Tenum.in;');
|
||||
AssertException(EParserError,@ParseExpression);
|
||||
end;
|
||||
|
||||
procedure TTestExpressions.TestADotBDotC;
|
||||
var
|
||||
B, SubB: TBinaryExpr;
|
||||
|
Loading…
Reference in New Issue
Block a user