View Issue Details

IDProjectCategoryView StatusLast Update
0037807FPCPackagespublic2020-09-24 11:57
ReporterJoe care Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86-64OSWin64 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037807: [fcl-passrc][patch] (. and .) as replacement for square braces are not parsed
Descriptionparsing code with (. and .) as replacement for [ and ] gives an error in pparser.
Steps To Reproduce[code]
const c:array(.0..1.) of byte = (1,2); begin write(c(.0.)); end.
[/code]
compiles fine with fpc
but gives an error when parsing with passrc
Additional InformationThere are two ways to fix this:
First the scanner takes (. and .) and produces tkSqareBraceOpen and tSquareBraceClose. This defintly fixes the error and would give a correct program, regresion: the pasTree of the parser would not fully represent the code and paswrite would write a sightly different program than the original.
Better solution the scanner gets two new tokens e.G: tkBraceDotOpen and tkDotBraceClose. But then all other programs had to handle those new tokens.
... so I went for the first solution.
Tagsfcl-passrc, patch
Fixed in Revision46937
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Joe care

2020-09-24 10:08

reporter  

pscanner-quickfix.patch (2,237 bytes)   
Index: pscanner.pp
===================================================================
--- pscanner.pp	(Revision 46934)
+++ pscanner.pp	(Arbeitskopie)
@@ -4324,7 +4324,12 @@
     '(':
       begin
       Inc(FTokenPos);
-      if {$ifdef UsePChar}FTokenPos[0] <> '*'{$else}(FTokenPos>l) or (s[FTokenPos]<>'*'){$endif} then
+      if {$ifdef UsePChar}FTokenPos[0] = '.'{$else}(FTokenPos>l) or (s[FTokenPos]<>'.'){$endif} then
+        begin
+        Inc(FTokenPos);
+        Result := tkSquaredBraceOpen;
+        end
+      else if {$ifdef UsePChar}FTokenPos[0] <> '*'{$else}(FTokenPos>l) or (s[FTokenPos]<>'*'){$endif} then
         Result := tkBraceOpen
       else
         begin
@@ -4448,9 +4453,14 @@
     '.':
       begin
       Inc(FTokenPos);
-      if {$ifdef UsePChar}FTokenPos[0]='.'{$else}(FTokenPos<=l) and (s[FTokenPos]='.'){$endif} then
+      if {$ifdef UsePChar}FTokenPos[0]=')'{$else}(FTokenPos<=l) and (s[FTokenPos]=')'){$endif} then
         begin
         Inc(FTokenPos);
+        Result := tkSquaredBraceClose;
+        end
+      else if {$ifdef UsePChar}FTokenPos[0]='.'{$else}(FTokenPos<=l) and (s[FTokenPos]='.'){$endif} then
+        begin
+        Inc(FTokenPos);
         Result := tkDotDot;
         end
       else
@@ -4492,14 +4502,14 @@
       end;
     '0'..'9':
       begin
-      // 1, 12, 1.2, 1.2E3, 1.E2, 1E2, 1.2E-3, 1E+2
+      // 1, 12, 1.2, 1.2E3, 1.E2, 1E2, 1.2E-3, 1E+2 and .)
       // beware of 1..2
       TokenStart := FTokenPos;
       repeat
         Inc(FTokenPos);
       until {$ifdef UsePChar}not (FTokenPos[0] in Digits){$else}(FTokenPos>l) or not (s[FTokenPos] in Digits){$endif};
-      if {$ifdef UsePChar}(FTokenPos[0]='.') and (FTokenPos[1]<>'.'){$else}
-          (FTokenPos<=l) and (s[FTokenPos]='.') and ((FTokenPos=l) or (s[FTokenPos+1]<>'.')){$endif}then
+      if {$ifdef UsePChar}(FTokenPos[0]='.') and (FTokenPos[1]<>'.') and (FTokenPos[1]<>')'){$else}
+          (FTokenPos<=l) and (s[FTokenPos]='.') and ((FTokenPos=l) or (s[FTokenPos+1]<>'.') and ((FTokenPos=l) or (s[FTokenPos+1]<>')')){$endif}then
         begin
         inc(FTokenPos);
         while {$ifdef UsePChar}FTokenPos[0] in Digits{$else}(FTokenPos<=l) and (s[FTokenPos] in Digits){$endif} do
pscanner-quickfix.patch (2,237 bytes)   

Joe care

2020-09-24 11:09

reporter   ~0125809

Also appended a test in tests/tcscanner ...
tcscanner.patch (938 bytes)   
Index: tcscanner.pas
===================================================================
--- tcscanner.pas	(Revision 46934)
+++ tcscanner.pas	(Arbeitskopie)
@@ -444,8 +448,10 @@
   if DoClear then
     FResolver.Clear;
   FResolver.AddStream('afile.pp',TStringStream.Create(Source));
+  {$ifndef NOCONSOLE} // JC: To get the tests to run with GUI
   Writeln('// '+TestName);
   Writeln(Source);
+  {$EndIf}
 //  FreeAndNil(FScanner);
 //  FScanner:=TTestingPascalScanner.Create(FResolver);
   FScanner.OpenFile('afile.pp');
@@ -734,6 +768,7 @@
 
 begin
   TestToken(tkSquaredBraceOpen,'[');
+  TestToken(tkSquaredBraceOpen,'(.'); // JC: Test for the BraceDotOpen
 end;
 
 
@@ -741,6 +776,8 @@
 
 begin
   TestToken(tkSquaredBraceClose,']');
+  TestToken(tkSquaredBraceClose,'.)'); // JC: Test for the DotBraceClose
+  TestTokens([tkNumber,tkSquaredBraceClose],'1.)'); // JC: Test for a Number followed by DotBraceClose

 end;
 
 
tcscanner.patch (938 bytes)   

Michael Van Canneyt

2020-09-24 11:57

administrator   ~0125814

Checked and applied, thank you very much !

Issue History

Date Modified Username Field Change
2020-09-24 10:08 Joe care New Issue
2020-09-24 10:08 Joe care File Added: pscanner-quickfix.patch
2020-09-24 10:08 Joe care Tag Attached: fcl-passrc
2020-09-24 10:08 Joe care Tag Attached: patch
2020-09-24 11:09 Joe care Note Added: 0125809
2020-09-24 11:09 Joe care File Added: tcscanner.patch
2020-09-24 11:57 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-09-24 11:57 Michael Van Canneyt Status new => resolved
2020-09-24 11:57 Michael Van Canneyt Resolution open => fixed
2020-09-24 11:57 Michael Van Canneyt Fixed in Version => 3.3.1
2020-09-24 11:57 Michael Van Canneyt Fixed in Revision => 46937
2020-09-24 11:57 Michael Van Canneyt FPCTarget => 3.2.2
2020-09-24 11:57 Michael Van Canneyt Note Added: 0125814