From: Matt Wette <matthew.wette@verizon.net>
To: guile-devel@gnu.org
Subject: Re: regex-case
Date: Mon, 08 Feb 2016 08:04:55 -0800 [thread overview]
Message-ID: <DDBA210D-167E-4C8B-8F71-E90BD2392432@verizon.net> (raw)
In-Reply-To: <CAGua6m2+kmcANNp0Y9Q7HqjK80wkwsF0vvxDuPrJ8oRe8u4iYg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1731 bytes --]
Matt Wette
matthew.wette@verizon.net
> On Feb 8, 2016, at 7:40 AM, Stefan Israelsson Tampe <stefan.itampe@gmail.com> wrote:
> ---------- Forwarded message ----------
> From: Stefan Israelsson Tampe <stefan.itampe@gmail.com <mailto:stefan.itampe@gmail.com>>
> Date: Mon, Feb 8, 2016 at 4:31 PM
> Subject: Re: regex-case
> To: Ludovic Courtès <ludo@gnu.org <mailto:ludo@gnu.org>>
>
>
> An interesting question is what can be done by ice-9/match
To provide background to the guile-devel list my prototype implementation for regex-case is as follows (w/ error messages suggested by Ludo now included):
;; helper macro for regex-case
;; (rx-let m (v ...) exp ...) => (let ((v (match:substring m 1)) ...) exp ...)
(define-syntax rx-let
(lambda (x)
(syntax-case x ()
((_ m (v ...) exp ...)
(with-syntax (((i ...)
(let f ((n 1) (vl #'(v ...))) ; fold (v ...) to (1 ...)
(if (null? vl) '() (cons n (f (1+ n) (cdr vl)))))))
#'(let ((v (match:substring m i)) ...) exp ...))))))
(define-syntax regex-case
(lambda (x)
(syntax-case x (else)
((_ str ((pat v ...) exp ...) ...)
(with-syntax (((id ...) (generate-temporaries #'(pat ...))))
#'(let ((id (make-regexp pat)) ...)
(cond
((regexp-exec id str) =>
(lambda (m) (rx-let m (v ...) exp ...)))
...
(else (error "regex-case: no match"))))))
((_ str ((pat v ...) exp ...) ... (else else-exp ...))
(with-syntax (((id ...) (generate-temporaries #'(pat ...))))
#'(let ((id (make-regexp pat)) ...)
(cond
((regexp-exec id str) =>
(lambda (m) (rx-let m (v ...) exp ...)))
...
(else else-exp ...))))))))
[-- Attachment #2: Type: text/html, Size: 5719 bytes --]
next prev parent reply other threads:[~2016-02-08 16:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net>
[not found] ` <87oabrgtrg.fsf@gnu.org>
[not found] ` <CAGua6m1_gbvJk_XPzg95NTRYwZAXO_wKJyKyfjOT-vFirn3Vcg@mail.gmail.com>
2016-02-08 15:40 ` Fwd: regex-case Stefan Israelsson Tampe
2016-02-08 16:04 ` Matt Wette [this message]
2016-02-08 16:15 ` regex-case Stefan Israelsson Tampe
2016-02-08 16:50 ` regex-case Stefan Israelsson Tampe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DDBA210D-167E-4C8B-8F71-E90BD2392432@verizon.net \
--to=matthew.wette@verizon.net \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).