andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 62 forks source link

Problems with DefParam and OverMeth defines in Delphi 12. #379

Closed SkybuckFlying closed 6 months ago

SkybuckFlying commented 6 months ago
  1. Put version information in file.

  2. Rad Studio 12 errors/PascalCoin related:

[dcc32 Error] uregexpr.pas(5872): E2035 Not enough actual parameters

procedure TRegExpr.Split(const AInputStr: RegExprString; APieces: TStrings);
var
  PrevPos: PtrInt;
begin
  PrevPos := 1;
  if Exec(AInputStr) then
    repeat
      APieces.Add(System.Copy(AInputStr, PrevPos, MatchPos[0] - PrevPos));
      PrevPos := MatchPos[0] + MatchLen[0];
    until not ExecNext;
  APieces.Add(System.Copy(AInputStr, PrevPos, MaxInt)); // Tail
end;

Cause of error:

Something wrong with DefParam define.

  1. Next error:
function TRegExpr.Replace(const AInputStr: RegExprString;
  const AReplaceStr: RegExprString;
  AUseSubstitution: boolean{$IFDEF DefParam} = False{$ENDIF}): RegExprString;
var
  PrevPos: PtrInt;
begin
  Result := '';
  PrevPos := 1;
  if Exec(AInputStr) then
    repeat
      Result := Result + System.Copy(AInputStr, PrevPos, MatchPos[0] - PrevPos);
      if AUseSubstitution // ###0.946
      then
        Result := Result + Substitute(AReplaceStr)
      else
        Result := Result + AReplaceStr;
      PrevPos := MatchPos[0] + MatchLen[0];
    until not ExecNext;
  Result := Result + System.Copy(AInputStr, PrevPos, MaxInt); // Tail
end; { of function TRegExpr.Replace
  -------------------------------------------------------------- }
// ======== Define Pascal-language options
// Define 'UseAsserts' option (do not edit this definitions).
// Asserts used to catch 'strange bugs' in TRegExpr implementation (when something goes
// completely wrong). You can swith asserts on/off with help of {$C+}/{$C-} compiler options.
{$IFDEF D3} {$DEFINE UseAsserts} {$ENDIF}
{$IFDEF FPC} {$DEFINE UseAsserts} {$ENDIF}
// Define 'use subroutine parameters default values' option (do not edit this definition).
{$IFDEF D4} {$DEFINE DefParam} {$ENDIF}
{$IFDEF FPC} {$DEFINE DefParam} {$ENDIF}
// Define 'OverMeth' options, to use method overloading (do not edit this definitions).
{$IFDEF D5} {$DEFINE OverMeth} {$ENDIF}
{$IFDEF FPC} {$DEFINE OverMeth} {$ENDIF}
// Define 'InlineFuncs' options, to use inline keyword (do not edit this definitions).
//{$IFDEF D8} {$DEFINE InlineFuncs} {$ENDIF}
{$IFDEF FPC} {$DEFINE InlineFuncs} {$ENDIF}

Also OverMeth define is also problematic.

Perhaps defines for D4 and D5 are no longer present in RAD Studio 12/Delphi 12.

I think real problem could be: // ======== Determine compiler {$I regexpr_compilers.inc} // ======== Define base compiler options This include file is not included with PascalCoin.

No this file is there lol, maybe Delphi 12, can't find it haha.

I think real problem is, missing defines for latest Delphi version:

Example of what it looks like:

{$IFDEF VER350}
  {$DEFINE D_105}
  {$DEFINE D_104}
  {$DEFINE D_103}

Delphi 12 is version VER360.

So nice example how version defines can break code ! ;)

Alexey-T commented 6 months ago

file src/regexpr_compilers.inc has OK defines for D 12:


{$IFDEF VER360}
  {$DEFINE D_110}
  {$DEFINE D_104}
  {$DEFINE D_103}
  {$DEFINE D_102}
  {$DEFINE D_101}
  {$DEFINE D_100}
  {$DEFINE D_XE8}
  {$DEFINE D_XE7}
  {$DEFINE D_XE6}
  {$DEFINE D_XE5}
  {$DEFINE D_XE4}
  {$DEFINE D_XE3}
  {$DEFINE D_XE2}
  {$DEFINE D_XE}
  {$DEFINE D2010}
  {$DEFINE D2009}
  {$DEFINE D2007}
  {$DEFINE D2006}
  {$DEFINE D2005}
  {$DEFINE D8}
  {$DEFINE D7}
  {$DEFINE D6}
  {$DEFINE D5}
  {$DEFINE D4}
  {$DEFINE D3}
  {$DEFINE D2}
{$ENDIF} // D 12.0

so I am puzzled. i don't have D12 installed yet..

Alexey-T commented 6 months ago

let's test this. add crap-code 'dddd' into the {$IFDEF VER360} in the file regexpr_compilers.inc. like this:

{$IFDEF VER360}
ddd
{$ENDIF}

does D 12 show error for this crap-code? it must show error. if no error - then file regexpr_compilers.inc is not used for you. why?

SkybuckFlying commented 6 months ago

Here is list of compiler versions.

I don't blame you for not finding this, I also had difficulities of finding it, only way to get it is to replace Sydney with Athens to produce this correct link, tried to report this on reddit, but some guy being kind anal about it:

https://docwiki.embarcadero.com/RADStudio/Athens/en/Compiler_Versions

<html>
<body>
<!--StartFragment-->
Delphi conditional VER<nnn> | Product | Product Version | Package Version | CompilerVersion
-- | -- | -- | -- | --
VER360 | Delphi 12.0 Athens / C++Builder 12.0 Athens | 29 | 290 | 36.0
VER350 | Delphi 11.0 Alexandria / C++Builder 11.0 Alexandria | 28 | 280 | 35.0
VER340 | Delphi 10.4 Sydney / C++Builder 10.4 Sydney | 27 | 270 | 34.0
VER330 | Delphi 10.3 Rio / C++Builder 10.3 Rio | 26 | 260 | 33.0
VER320 | Delphi 10.2 Tokyo / C++Builder 10.2 Tokyo | 25 | 250 | 32.0
VER310 | Delphi 10.1 Berlin / C++Builder 10.1 Berlin | 24 | 240 | 31.0
VER300 | Delphi 10 Seattle / C++Builder 10 Seattle | 23 | 230 | 30.0
VER290 | Delphi XE8 / C++Builder XE8 | 22 | 220 | 29.0
VER280 | Delphi XE7 / C++Builder XE7 | 21 | 210 | 28.0
VER270 | Delphi XE6 / C++Builder XE6 | 20 | 200 | 27.0
VER260 | Delphi XE5 / C++Builder XE5 | 19 | 190 | 26.0
VER250 | Delphi XE4 / C++Builder XE4 | 18 | 180 | 25.0
VER240 | Delphi XE3 / C++Builder XE3 | 17 | 170 | 24.0
VER230 | Delphi XE2 / C++Builder XE2 | 16 | 160161 is the version for the five FireMonkey packages at XE2 Update 2: fmi161.bpl, fmx161.bpl, fmxase161.bpl, fmxdae161.bpl, and fmxobj161.bpl. | 23.0
VER220 | Delphi XE / C++Builder XE | 15 | 150 | 22.0
VER210 | Delphi 2010 / C++Builder 2010 | 14 | 140 | 21.0
VER200 | Delphi 2009 / C++Builder 2009 | 12 | 120 | 20.0
VER190 | Delphi 2007 for .Net [1] | 11 | 110 | 19.0
VER180 or VER185 | Delphi 2007 / C++Builder 2007 for Win32 [1] | 11 | 110 | 18.5
VER180 | Delphi 2006 / C++Builder 2006 | 10 | 100 | 18.0
VER170 | Delphi 2005 | 9 | 90 | 17.0
VER160 | Delphi 8 for .Net | 8 | 80 | 16.0
VER150 | Delphi 7 (and 7.1) | 7 | 70 | 15.0
VER140 | Delphi 6 / C++Builder 6 | 6 | 60 | 14.0
VER130 | Delphi 5 / C++Builder 5 | 5 | NA | NA
VER125 | C++Builder 4 | 4 | NA | NA
VER120 | Delphi 4 | 4 | NA | NA
VER110 | C++Builder 3 | 3 | NA | NA
VER100 | Delphi 3 | 3 | NA | NA
VER93 | C++Builder 1 | NA | NA | NA
VER90 | Delphi 2 | 2 | NA | NA
VER80 | Delphi 1 | 1 | NA | NA
VER70 | Borland Pascal 7.0 | NA | NA | NA
VER15 | Turbo Pascal for Windows 1.5 | NA | NA | NA
VER10 | Turbo Pascal for Windows 1.0 | NA | NA | NA
VER60 | Turbo Pascal 6.0 | NA | NA | NA
VER55 | Turbo Pascal 5.5 | NA | NA | NA
VER50 | Turbo Pascal 5.0 | NA | NA | NA
VER40 | Turbo Pascal 4.0 | NA | NA | NA

<br class="Apple-interchange-newline"><!--EndFragment-->
</body>
</html>Delphi conditional VER<nnn>  Product Product Version Package Version CompilerVersion
VER360  Delphi 12.0 Athens / C++Builder 12.0 Athens 29  290 36.0
VER350  Delphi 11.0 Alexandria / C++Builder 11.0 Alexandria 28  280 35.0
VER340  Delphi 10.4 Sydney / C++Builder 10.4 Sydney 27  270 34.0
VER330  Delphi 10.3 Rio / C++Builder 10.3 Rio   26  260 33.0
VER320  Delphi 10.2 Tokyo / C++Builder 10.2 Tokyo   25  250 32.0
VER310  Delphi 10.1 Berlin / C++Builder 10.1 Berlin 24  240 31.0
VER300  Delphi 10 Seattle / C++Builder 10 Seattle   23  230 30.0
VER290  Delphi XE8 / C++Builder XE8 22  220 29.0
VER280  Delphi XE7 / C++Builder XE7 21  210 28.0
VER270  Delphi XE6 / C++Builder XE6 20  200 27.0
VER260  Delphi XE5 / C++Builder XE5 19  190 26.0
VER250  Delphi XE4 / C++Builder XE4 18  180 25.0
VER240  Delphi XE3 / C++Builder XE3 17  170 24.0
VER230  Delphi XE2 / C++Builder XE2 16  160161 is the version for the five FireMonkey packages at XE2 Update 2: fmi161.bpl, fmx161.bpl, fmxase161.bpl, fmxdae161.bpl, and fmxobj161.bpl.    23.0
VER220  Delphi XE / C++Builder XE   15  150 22.0
VER210  Delphi 2010 / C++Builder 2010   14  140 21.0
VER200  Delphi 2009 / C++Builder 2009   12  120 20.0
VER190  Delphi 2007 for .Net [[1]](https://docwiki.embarcadero.com/RADStudio/Athens/en/Compiler_Versions#cite_note-multiple-1)  11  110 19.0
VER180 or VER185    Delphi 2007 / C++Builder 2007 for Win32 [[1]](https://docwiki.embarcadero.com/RADStudio/Athens/en/Compiler_Versions#cite_note-multiple-1)   11  110 18.5
VER180  Delphi 2006 / C++Builder 2006   10  100 18.0
VER170  Delphi 2005 9   90  17.0
VER160  Delphi 8 for .Net   8   80  16.0
VER150  Delphi 7 (and 7.1)  7   70  15.0
VER140  Delphi 6 / C++Builder 6 6   60  14.0
VER130  Delphi 5 / C++Builder 5 5   NA  NA
VER125  C++Builder 4    4   NA  NA
VER120  Delphi 4    4   NA  NA
VER110  C++Builder 3    3   NA  NA
VER100  Delphi 3    3   NA  NA
VER93   C++Builder 1    NA  NA  NA
VER90   Delphi 2    2   NA  NA
VER80   Delphi 1    1   NA  NA
VER70   Borland Pascal 7.0  NA  NA  NA
VER15   Turbo Pascal for Windows 1.5    NA  NA  NA
VER10   Turbo Pascal for Windows 1.0    NA  NA  NA
VER60   Turbo Pascal 6.0    NA  NA  NA
VER55   Turbo Pascal 5.5    NA  NA  NA
VER50   Turbo Pascal 5.0    NA  NA  NA
VER40   Turbo Pascal 4.0    NA  NA  NA
SkybuckFlying commented 6 months ago

Based on this list, I believe comment down below from this file might be wrong:

{$IFDEF VER350}
  {$DEFINE D_105}
  {$DEFINE D_104}
  {$DEFINE D_103}
  {$DEFINE D_102}
  {$DEFINE D_101}
  {$DEFINE D_100}
  {$DEFINE D_XE8}
  {$DEFINE D_XE7}
  {$DEFINE D_XE6}
  {$DEFINE D_XE5}
  {$DEFINE D_XE4}
  {$DEFINE D_XE3}
  {$DEFINE D_XE2}
  {$DEFINE D_XE}
  {$DEFINE D2010}
  {$DEFINE D2009}
  {$DEFINE D8}
  {$DEFINE D7}
  {$DEFINE D6}
  {$DEFINE D5}
  {$DEFINE D4}
  {$DEFINE D3}
  {$DEFINE D2}
{$ENDIF} // D 10.5

Then again does D 10.5 actually exist ?

According to list above, this would be D 11 ?!

SkybuckFlying commented 6 months ago

OK,

I take your word for it that it has correct defines.

That means PascalCoin is using an old version of this file.

I will update it and do a pull request for PascalCoin.

Sorry to have bothered you I guess...

Just wasn't sure what was going on.

I should have checked your code first to see if it was already updated.

OK, I see it's already in there, closing this issue, problem should be fixeable by updating PascalCoin, if not I shall return ! =D

Alexey-T commented 6 months ago

in current TRegexpr code, comment about 'd 10.5' was fixed long ago:

{$IFDEF VER350}
  {$DEFINE D_110}
  {$DEFINE D_104}
  {$DEFINE D_103}
  {$DEFINE D_102}
  {$DEFINE D_101}
  {$DEFINE D_100}
  {$DEFINE D_XE8}
  {$DEFINE D_XE7}
  {$DEFINE D_XE6}
  {$DEFINE D_XE5}
  {$DEFINE D_XE4}
  {$DEFINE D_XE3}
  {$DEFINE D_XE2}
  {$DEFINE D_XE}
  {$DEFINE D2010}
  {$DEFINE D2009}
  {$DEFINE D2007}
  {$DEFINE D2006}
  {$DEFINE D2005}
  {$DEFINE D8}
  {$DEFINE D7}
  {$DEFINE D6}
  {$DEFINE D5}
  {$DEFINE D4}
  {$DEFINE D3}
  {$DEFINE D2}
{$ENDIF} // D 11.0