egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
69 stars 17 forks source link

SRFI 115: Scheme Regular Expressions #70

Open lassik opened 4 years ago

lassik commented 4 years ago

https://srfi.schemers.org/srfi-115/srfi-115.html

How hard would this be to implement using PCRE?

jpellegrini commented 4 years ago

It would be nice to have this SRFI, since it's part of R7RS large.

Now, what would be the advantage of re-implementing it with PCRE? Performance only, or something else?

lassik commented 4 years ago

Now, what would be the advantage of re-implementing it with PCRE?

The main thing is that we wouldn't need to have the matcher in Scheme code since PCRE already implements it. We could just translate each S-expression regexp to a string suitable for PCRE. Presumably PCRE is also a lot faster.

jpellegrini commented 4 years ago

Hmm, that sounds really nice! The Scheme with a FAST implementation of SRFI-115. :) :)

jpellegrini commented 4 years ago

@lassik do you want to work on this?

lassik commented 4 years ago

I don't have time to do a full implementation, but I can give pointers.

irregex is a well-known Scheme library by Alex Shinn, author of Chibi-Scheme. It has been ported to Chicken and probably other Schemes. Among other things, it contains a sre->string utility that converts (what I believe is) a SRFI 115 SRE (Scheme Regular Expression) into a PCRE string regexp. Here it is:

https://github.com/ashinn/irregex/blob/master/irregex-utils.scm#L84

I suspect it's not very battle-tested, but it's probably the best starting point. In case of problems, the SRFI 115 mailing list can help.

lassik commented 4 years ago

Documentation for the irregex library:

http://snow-fort.org/s/gmail.com/alexshinn/chibi/irregex/0.9.3/index.html

Here's the PCRE library that ships with Chibi-Scheme:

https://github.com/ashinn/chibi-scheme/blob/master/lib/chibi/regexp/pcre.scm

It has a converter in the opposite direction: pcre->sre.

lassik commented 4 years ago

Alex's code is generally MIT/BSD licensed.

egallesio commented 7 months ago

Hi @lassik,

I have implemented SRFI-115 (using the implementation given in the SRFI). I tried to translate the Scheme regexps to PRCE regexps, using the links you provided. I have something for simple regexps, but it doesn't work in the general case. You're right: it would be really cool to have it for STklos; I'll try to finish the implementation later.