Open RomanYankovsky opened 9 years ago
I'm astonished that this code is supposed to work. Delphi syntax is surprising me every day more. Sorry for being off topic.
Well obviously you'd need a mode just like the inComment mode to see if we're dealing with COM automation. IMO this can only be done with knowledge of the header files. If the method we're calling is part of a dispinterface then enable inAutomation mode.
Steps to resolve this would be:
@JBontes I think this doesn't worth the effort at this moment... :(
Hm, I'm just thinking about the :=
we can use that part so the logic would be:
if inside method parameters and nextToken = :=
then enable named parameter mode.
@JBontes yes, but it also requires more changes. 'Unit' is not an identifier, it's a keyword. Parser doesn't expect any keywords at this place. Actually, I believe named parameters are already supported. The problem is in keyword-as-identifier issue.
Hence the need for a mode change. Let me see if this is doable.
This can be fixed as follows:
const
ReservedWords = [ptAnd, ptEnd, ptInterface, ptrecord, ptvar,ptarray,ptexcept,ptis,ptrepeat,ptwhile,ptas,ptexports,
ptlabel,ptresourcestring, ptwith,ptasm,ptfile,ptlibrary,ptset,ptxor,ptbegin,ptfinalization,
ptmod,ptshl,ptcase,ptfinally,ptnil,ptshr,ptclass,ptfor,ptnot,ptstring,ptconst,ptfunction,ptobject,
ptthen,ptconstructor,ptgoto,ptof,ptthreadvar,ptdestructor,ptif,ptor,ptto,ptdispinterface,
ptimplementation,ptpacked,pttry,ptdiv,ptin,ptprocedure,pttype,ptdo,ptinherited,ptprogram,
ptunit,ptdownto,ptinitialization,ptproperty,ptuntil,ptelse,ptinline,ptraise,ptuses];
procedure TmwSimplePasPar.Factor;
begin
case TokenID of
ptAsciiChar, ptStringConst:
begin
CharString;
end;
ptAddressOp, ptDoubleAddressOp, ptIdentifier, ptInherited, ptPointerSymbol:
begin
Designator;
end;
ptRoundOpen:
begin
RoundOpen;
ExpressionList;
RoundClose;
end;
ptIntegerConst, ptFloat:
begin
Number;
end;
ptNil:
begin
NilToken;
end;
ptMinus:
begin
UnaryMinus;
Factor;
end;
ptNot:
begin
NotOp;
Factor;
end;
ptPlus:
begin
NextToken;
Factor;
end;
ptSquareOpen:
begin
SetConstructor;
end;
ptString:
begin
StringStatement;
end;
ptFunction, ptProcedure:
AnonymousMethod;
else if (TokenID in ReservedWords) then begin
InitAhead;
AheadParse.NextToken;
if (AheadParse.TokenId = ptAssign) then begin
Lexer.ForceTokenID:= ptIdentifier;
Factor;
Exit;
end;
end;
end;
while TokenID = ptSquareOpen do
IndexOp;
while TokenID = ptPointerSymbol do
PointerSymbol;
if TokenID = ptRoundOpen then
Factor;
while TokenID = ptPoint do
begin
DotOp;
Factor;
end;
end;
TmwBasePasLex = class(TObject)
...
public
constructor Create;
...
property FileName: string read GetFileName;
property ForceTokenID: TptTokenKind write FTokenId; //provide a means to force the tokenid.
//only use for COM named parameters.
end;