Recent

Author Topic: TPerlRegEx  (Read 11415 times)

fatmonk

  • Sr. Member
  • ****
  • Posts: 252
TPerlRegEx
« on: April 17, 2013, 11:22:52 am »
(Edit: Sorry, just realised that this should have been in the 'Ported from Delphi' sub-folder - If a mod could move it that would be good. Ta, FM)

I'm struggling to find a way of using Perl compatible regular expressions in a project.

The closest I have got is to download TPerlRegEx from http://www.regexbuddy.com/delphi.html - it's a Delphi wrapper around a C++ PCRE library apparently.

I've extracted the archive and put it where Lazarus and the fpc can find it, and I've converted one of the .pas files via the Lazarus Tools menu.

The other .pas file, however won't convert.

I've added PerlregEx to the uses clause of the units that I want to use the regular expressions in (I need to use replace functionality so the built in RegEx support isn't really enough, I don't think) and the reference to the second .pas file seems to get picked up correctly but the compiler fails with the following messages:

Code: [Select]
C:\lazarus\components\perlregex\pcre.pas(623,22) Fatal: Syntax error, ":" expected but ";" found
If I change the ; characters for : then I get the following errors:

Code: [Select]
C:\lazarus\components\perlregex\pcre.pas(623,32) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(624,33) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(625,31) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(626,45) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(627,39) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(628,33) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(629,29) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(630,40) Error: Can't declare local procedure as EXTERNAL
C:\lazarus\components\perlregex\pcre.pas(631,45) Error: Can't declare local procedure as EXTERNAL
C:\lazarus\components\perlregex\pcre.pas(632,23) Fatal: Syntax error, ":" expected but ";" found

How can I get these Delphi units to compile correctly in my project?

I've also tried adding:
Code: [Select]
{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

to the pcre.pas (the conversion added it to PerlRegEx.pas automatically) but then I get a whole bunch of other errors:

Code: [Select]
C:\lazarus\components\perlregex\pcre.pas(627,32) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(627,10) Error: function header doesn't match the previous declaration "pcre_compile:<erroneous type>;"
C:\lazarus\components\perlregex\pcre.pas(378,10) Hint: Found declaration: pcre_compile(const PChar,LongInt,const PPAnsiChar,PInteger,const PChar):^real_pcre;
C:\lazarus\components\perlregex\pcre.pas(628,33) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(629,31) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(630,45) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(631,39) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(632,33) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(633,29) Error: Identifier not found "external"
C:\lazarus\components\perlregex\pcre.pas(634,40) Error: Can't declare local procedure as EXTERNAL
C:\lazarus\components\perlregex\pcre.pas(635,45) Error: Can't declare local procedure as EXTERNAL
C:\lazarus\components\perlregex\pcre.pas(636,33) Error: Can't declare local procedure as EXTERNAL
C:\lazarus\components\perlregex\pcre.pas(636,10) Error: No function result type specified for function "pcre_fullinfo"
C:\lazarus\components\perlregex\pcre.pas(637,44) Error: Can't declare local procedure as EXTERNAL

(I've removed a lot of duplicated and similar errors to keep the message post shorter).

Any help gratefully received.

Thanks,

FM
« Last Edit: April 17, 2013, 11:25:59 am by fatmonk »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12771
  • FPC developer.
Re: TPerlRegEx
« Reply #1 on: April 17, 2013, 11:27:37 am »
I downloaded the zip, and ran

Quote
fpc -Sd PerlRegEx.pas
Free Pascal Compiler version 2.6.0 [2011/12/25] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling PerlRegEx.pas
Compiling pcre.pas
2108 lines compiled, 0.5 sec

So I don't really understand the problem :-)

( -Sd is the commandline equivalent of mode delphi. Did you add the $mode delphi block to both files (perlregex and pcre) after the interface statement? )
« Last Edit: April 17, 2013, 11:29:31 am by marcov »

fatmonk

  • Sr. Member
  • ****
  • Posts: 252
Re: TPerlRegEx
« Reply #2 on: April 17, 2013, 11:37:27 am »
I'm gonna need a bit more than that  :P

How did you compile that? Straight from the command line (I haven't played with the fpc command line yet)? In it's own project (the zip doesn't contain a project itself so what kind f Lazarus project was it and how did you add that unit to it?).

Apologies for dumb questions, but having come from Borland C++ Builder about 10 years ago I'm just starting out getting to grips with lazarus and fpc.

Thanks,

FM

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TPerlRegEx
« Reply #3 on: April 17, 2013, 12:24:21 pm »
@FM: BTW, did you know there is a regex implementation in FPC? Not complete, but maybe enough for your needs:
http://wiki.lazarus.freepascal.org/Regexpr

Yes, it looks like Marco compiled it straight from the command line: his output shows he compiles PerlRegEx.pas

Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TPerlRegEx
« Reply #4 on: April 17, 2013, 12:44:38 pm »
Quote
Yes, it looks like Marco compiled it straight from the command line: his output shows he compiles PerlRegEx.pas
And without converting first.

fatmonk

  • Sr. Member
  • ****
  • Posts: 252
Re: TPerlRegEx
« Reply #5 on: April 17, 2013, 02:14:50 pm »
Trying hard here and taking baby steps, but not really in the right direction...

Here's where I'm getting with a command line compile (same options plus directory pointing bits):
Code: [Select]
C:\lazarus\fpc\2.6.2\bin\i386-win32>fpc -Sd -Fuc:\lazarus\* c:\lazarus\component
s\perlregex\PerlRegEx.pas
Free Pascal Compiler version 2.6.2 [2013/03/17] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling c:\lazarus\components\perlregex\PerlRegEx.pas
Compiling C:\lazarus\lcl\lclintf.pas
Compiling C:\lazarus\lcl\lclproc.pas
lclproc.pas(40,28) Fatal: Can't find unit LazLogger used by LCLProc
Fatal: Compilation aborted
Error: C:\lazarus\fpc\2.6.2\bin\i386-win32\ppc386.exe returned an error exitcode
 (normal if you did not specify a source file to be compiled)

C:\lazarus\fpc\2.6.2\bin\i386-win32>

However, even if it compiles there with no problem that doesn't really help me when I can't include that in my GUI based project created within Lazarus.

Regarding the built in RegEx support - I'm looking for something with a RegEx.replace() type function... this all stems from the fact that an XML validate won't run with an external DTD file. On the fly I want to create a shadow version of an XML file loaded into a SynEdit. The shadow version will be created by running a RegEx on the content of the SynEdit and inserting the content of the external DTD file in the correct place. In PHP using the PCREs it's really simple(from my post over at StackOverflow):

Essentially I have:

Code: [Select]
<?Line1?>
Line2
Line3

And I want to do a RegExp type search and replace for '<?Line1?>' replacing with '<?Line1?>\n<![DTD\nINFO WOULD\nGO HERE\n!]' to give me:

Code: [Select]
<?Line1?>
<![DTD
INFO WOULD
GO HERE
!]
Line2
Line3

In PHP I would use:

Code: [Select]
preg_replace('/(<\?.*\?>)/im','$1
<![DTD
INFO WOULD
GO HERE
!]',$sourcestring);


If I could get TPerlRegEx included in my project I think @d be able to achieve what I want that way. Using the built in RegEx stuff seems like it would be quite convoluted - unless I've misunderstood of course.

-FM


Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TPerlRegEx
« Reply #6 on: April 17, 2013, 06:28:07 pm »
Quote
Here's where I'm getting with a command line compile (same options plus directory pointing bits):
You are compiling the converted unit, which has Windows unit replaced with LCLIntf and friends. No command line option other than -Sd should be required.

OK, the code is a bit windows centric so I try to remove that. Attached is my modification that should compile on (maybe) any platform. The unicode related defines and codes are also removed (I don't really know the effect, please test and fix yourself if required).

mica

  • Full Member
  • ***
  • Posts: 196
Re: TPerlRegEx
« Reply #7 on: April 18, 2013, 06:07:13 pm »
you can try brre

http://code.google.com/p/brre/

some time ago there was an discussion to include it into FPC

eny

  • Hero Member
  • *****
  • Posts: 1665
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TPerlRegEx
« Reply #9 on: April 19, 2013, 07:45:50 am »
or try http://www.lazarus.freepascal.org/index.php/topic,18028.msg101089.html#msg101089
I already suggested the Sorokin unit above; the OP needed more functionality...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018