chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: regex and named subpatterns


From: Alex Shinn
Subject: Re: [Chicken-users] Re: regex and named subpatterns
Date: Thu, 06 Mar 2008 19:21:13 +0900
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (darwin)

>>>>> "Hans" == Hans Nowak <address@hidden> writes:

    Hans> In PCRE, a subpattern can be named in one
    Hans> of three ways: (?<name>...)  or (?'name'...)  as
    Hans> in Perl, or (?P<name>...) as in Python.

Yep, PCRE is "Perl Compatible" - it's an entirely separate
code-base from the Perl regexp engine.

    Hans> It's a bit odd though that Chicken (maybe
    Hans> unintentionally) supports the construct in regular
    Hans> expressions, but provides no ways to make use of
    Hans> it.

Chicken regexp's historically weren't tied to PCRE, and
provided a fairly minimal feature set to accomodate all the
backends equally.  It now always uses PCRE, and you could
get at the named subpatterns with pcre_get_named_substring()
if you returned the match object, but personally I don't
think it should be bound too strongly to PCRE.

Note that you don't need the match object to implement the
style you're used to, the positions list gives you all the
info you need:

  (define (rxmatch-group str m n)
    (let ((pos (list-ref m n)))
      (cons (substring str (car pos) (cadr pos)) pos)))

  (define (rxmatch-group-string str m n)
    (let ((pos (list-ref m n)))
      (substring str (car pos) (cadr pos))))

... will give you exactly the same behavior you demonstrated
(except that you need to pass the string).

Named matches *would* need the original object, though, or
alternately some extension including an alist with the
positions list.

-- 
Alex




reply via email to

[Prev in Thread] Current Thread [Next in Thread]