fcl_passrc: pparser, pscanner: range -> EParserError : Expected "=" at token "of" ; scanner returns tkWhitespace
Original Reporter info from Mantis: gvs
-
Reporter name:
Original Reporter info from Mantis: gvs
- Reporter name:
Description:
as i tried to update my test_parser.pp the following error was reported
(input was testunit1.pp)
EParserError : Expected "=" at token "of" at line ...
the input line is: TIntegerSet = Set of 0..SizeOf(Integer)*8-1;
-> this is because it is now parsed as a range
now i tried to overcome this by changing the code to match this case.
then i found out that the scanner returns a tkWhitespace on a normal range
declaration like "TASubRangeType=one..two;" at the position of the first "." .
even if i set the scanner to "FSkipWhiteSpace:= true;" i get this result.
futher more UngetToken caused an error if i try to roll back to "=" or "of" .
the code below will solve the problem without doing a check as it was intended
with "If not ((CurToken=tkEqual) then ParseExc ..." .
it is new to me that a scanner returns a whitespace, it is ignored.
Steps to reproduce:
pparser line 2060 (changed to do the job, with writeln debuging):
// Starts after the type name
Function TPasParser.ParseRangeType(AParent : TPasElement; Const TypeName : String) : TPasRangeType;
Var PE : TPasExpr;
begin
Result := TPasRangeType(CreateElement(TPasRangeType, TypeName, AParent));
try
writeln('SkipWhiteSpace: ',Scanner.SkipWhiteSpace);
if (AParent is TPasSetType) then //in a set it starts with 'of'
begin
WriteLn(' SET "',CurTokenString,'" = ',CurTokenName);
If not (CurToken=tkof) then
ParseExc(Format(SParserExpectTokenError,[TokenInfos[tkof]]));
NextToken;
end
else
begin //normal range starts with '='
//while CurToken = tkWhitespace do UngetToken; EParserError : Internal error: Cannot unget more tokens, history buffer is full at token "Whitespace" in file testunit2.pp at line 11 column 22
WriteLn(' RANGE0 "',CurTokenString,'" = ',CurTokenName);
while (CurToken=tkWhitespace) do NextToken;
if (CurToken=tktype) then NextToken; //## arangetypealias = type 0..$FF;
WriteLn(' RANGE1 "',CurTokenString,'" = ',CurTokenName);
//If not ((CurToken=tkEqual){or(CurToken=tkof)}) then //## tkof : TIntegerSet = Set of 0..SizeOf(Integer)*8-1; <- EParserError : Expected "=" at token "of"
// ParseExc(Format(SParserExpectTokenError,[TokenInfos[tkEqual]]));
end;
//NextToken;
WriteLn(' NEXT "',CurTokenString,'" = ',CurTokenName);
PE:=DoParseExpression(Result,Nil);
...
Additional information:
input to test with:
Unit testunit2;
Interface
Type
TIntegerSet=set of 0..(Integer) * 8 - 1;
TASubRangeType=one..two;
TASubRangeType = one .. two ;
Implementation
end.
And the "debug" output:
SkipWhiteSpace: TRUE
SET "of" = of
NEXT "0" = Number
SkipWhiteSpace: TRUE
RANGE0 "" = Whitespace
RANGE1 "one" = Identifier one
NEXT "one" = Identifier one
SkipWhiteSpace: TRUE
RANGE0 "" = Whitespace
RANGE1 "one" = Identifier one
NEXT "one" = Identifier one
Mantis conversion info:
- Mantis ID: 21642
- Build: trunk
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 20863 (#b0077a11)
- Target version: 2.6.1