Author Topic: SLRE: Super Light Regular Expression library  (Read 1610 times)

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
SLRE: Super Light Regular Expression library
« on: May 04, 2024, 01:44:07 PM »
Another day, another demo.

The one thing this was missing out of the box was a way to retrieve how many total captures were created.

I added the 'slre_count()' function to my forked version to address this oversight.

This time around, the attached archive has a dll instead of a static lib. 

Built with Pelles after a couple of modifications, this worked with both Pelles and MSVC on my system.

Code: [Select]
'******************************************************************************
' SLRE demo by AIR - 2024-05-04
' Github repo for SLRE: https://github.com/cesanta/slre
' My forked version, with 'slre_count()' function: https://github.com/Airr/slre
'******************************************************************************
#include "slre.h"
$typedef struct slre_cap slre_cap
$Pragma comment(lib, "slre.lib")

dim as slre_cap cap[BCXSTRSIZE]
Dim source$
source$ = "As we commemorate the 60th anniversary of BASIC, let's raise a glass to Kemeny and Kurtz."

if slre_match("(commemorate).+\s(\d+.+C).+\s(Kemeny.+Kurtz)", source$, len(source$), cap, BCXSTRSIZE, 0) then
    for Integer j = 0 to slre_count() - 1
            print Left$(cap[j].ptr$, cap[j].len)
    next
end if


AIR.

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #1 on: May 05, 2024, 05:31:46 PM »
which you think better ?
did you made performance test ?

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #2 on: May 05, 2024, 08:15:27 PM »
Hi, Morgan.

No performance tests were performed by me.

If we're comparing SLRE to the Tiny-Regex implementation, SLRE wins for having capture groups and a simpler API.  While one could accomplish the concept of capture groups with Tiny-Regex, one would need to actually implement that functionality.  In that case, maybe Henry Spencer's Regex implementation might be a better choice (but it uses POSIX syntax which is nothing like PERL syntax) [Note:  This is what PellesC offers by way of regex].

If we compare SLRE to something like PCRE/2, from a feature set perspective PCRE wins.

Personally, I like SLRE.  It's pretty lightweight, and does the job for me.

AIR.

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #3 on: May 05, 2024, 08:41:34 PM »
thanks. i like the tiny because it's pd
also the work on slre had stopped at some point,
when the programmer was hired by some company

edit: i'm talking about library i found on bcx example by mr bcx
i'm not sure if it's the one you use
« Last Edit: May 06, 2024, 08:30:01 AM by morgan »

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #4 on: May 12, 2024, 09:21:41 AM »
i'm talking about library i found on bcx example by mr bcx
i'm not sure if it's the one you use

Hi, Morgan.

Can you point me at the example?

AIR.

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #5 on: May 12, 2024, 01:05:52 PM »
i didn't find it, yet.
what i found is the original lib source
https://slre.sourceforge.net/

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #6 on: May 12, 2024, 03:38:39 PM »
You can grab the forked (from the original GitHub repository) source from my repository:  https://github.com/Airr/slre

My forked version includes the slre_count() function that I added.

AIR.

Robert

  • Hero Member
  • *****
  • Posts: 1237
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #7 on: May 12, 2024, 03:50:25 PM »
i didn't find it, yet.
what i found is the original lib source
https://slre.sourceforge.net/

Hi Morgan:

Maybe it was something in this thread ?

https://bcxbasiccoders.com/smf/index.php?topic=400.msg1713#msg1713

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #8 on: May 13, 2024, 01:47:12 AM »
i think it ' s very old example
that i found on bcx archive.
yesterday i made a search there
i didn't find mrbcx files.
what am i missing ?

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #9 on: May 13, 2024, 12:35:02 PM »
anyway as i said (from memory)
and now checked it
this library started with permissive license
but now it is under a company
with other license
https://github.com/cesanta/slre/

Robert

  • Hero Member
  • *****
  • Posts: 1237
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #10 on: May 13, 2024, 01:00:03 PM »
anyway as i said (from memory)
and now checked it
this library started with permissive license
but now it is under a company
with other license
https://github.com/cesanta/slre/

Hi Morgan:

MrBCX used SLRE in his Fast File Search.

FFS.zip

https://bcxbasiccoders.com/mrbcx_samples/mrbcx.htm

the source code of Sergey Lyubka is still available on the website

https://slre.sourceforge.net/

which has this license

Quote

* Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
* All rights reserved
*
* "THE BEER-WARE LICENSE" (Revision 42):
* Sergey Lyubka wrote this file.  As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return.
*
« Last Edit: May 13, 2024, 01:03:17 PM by Robert »

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #11 on: May 13, 2024, 01:28:03 PM »
i already said this above
this is the old code
it has modified since then

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #12 on: May 13, 2024, 04:04:34 PM »
Hi, Morgan.

Is the issue for you primarily the license?

I did a quick diff between the two (at work so limited time) and it seems that the 'newer' version has undergone extensive refactoring.

Have you tried either one with code you're writing?

AIR.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2229
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #13 on: May 13, 2024, 04:43:04 PM »
anyway as i said (from memory)
and now checked it
this library started with permissive license
but now it is under a company
with other license
https://github.com/cesanta/slre/

The developer of SLRE is also the Founder/Director of Cesanta.

The Cesanta/slre is dual-licensed ... meaning, you can either buy a commercial license from
Cesanta or, if you commercialize your software, GPL2 requires you to open source your app.

If you don't sell your app then both licenses are pointless.

airr

  • Full Member
  • ***
  • Posts: 187
    • View Profile
Re: SLRE: Super Light Regular Expression library
« Reply #14 on: May 13, 2024, 04:55:55 PM »
I couldn't resist, here's a rudimentary example using the ORIGINAL SLRE version from SourceForge:

Code: [Select]
#include "slre.c"

Dim test$
test$ = "DIM HelpMenu AS HMENU"

$Typedef struct slre slre
$Typedef struct cap  cap

Dim As slre sl
Dim As cap captures[BCXSTRSIZE]

If Not slre_compile(&sl, "^DIM\s+?(.+)\s+?\S+\s+?(\S+)") Then
    Print "Error compiling RE: ", sl.err_str$
    End = 1
End If

If Not slre_match(&sl, test$, Len(test$), captures) Then
    Print "No Matches Found"
    End = 1
End If

Print "Variable Name: ", Left$(captures[1].ptr$, captures[1].len)
Print "Variable Type: ", Left$(captures[2].ptr$, captures[2].len)

Pause


AIR.

Edit:  Forgot to mention that I had to edit the source to address warnings about incompatible assignments.
« Last Edit: May 13, 2024, 05:03:02 PM by airr »