clarification for regexp-replace in srfi-115 / chibi.regex

4 views
Skip to first unread message

Duy Nguyen

unread,
Apr 9, 2020, 5:03:48 AM4/9/20
to chibi-...@googlegroups.com, Arthur A. Gleckler
This was posted in srfi-115 list, but I hope to catch Alex's attention
by doing it here instead.

'subst' parameter of regexp-replace is described like this

---
subst can be a string, an integer or symbol indicating the contents of
a numbered or named submatch of re, 'pre for the substring to the left
of the match, or 'post for the substring to the right of the match.
---

This makes replacement very limited. I found that chibi.regex accepts
'subst' as a _list_ of those items too. With that we can start doing
something like this regexp

s/\(<first>\)...\(<second>\)/blah \2 - \1/'

The SRFI should probably mention that it is an error if a capture
group is named 'pre or 'post because it's ambiguous. Each Scheme
implementation can decide whatever they want to do in that case.

Also, 'subst' can be a procedure in chibi.regex and that makes
replacement much more flexible.


Is it reasonable to amend the SRFI like above? As far as I know, all
srfi-115 implementations out there are based on chibi.regex, which
already supports that. The only exception is Gauche, which translates
SRE to its own AST syntax, and I made sure that it supports the same.

If the SRFI is set in stone, I think we could make a new one and let
it be voted to replace srfi-115 in r7rs-large.
--
Duy

Alex Shinn

unread,
Apr 9, 2020, 9:45:50 AM4/9/20
to chibi-...@googlegroups.com, Arthur A. Gleckler
Thanks for the ping, I'll follow up on the SRFI list.

--
Alex

--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CACsJy8CtnmPW50GB_5mH3u5E2zU5mvYKScEK30aCPWU%3DiXrk9w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages