caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pixel <pixel@mandrakesoft.com>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Regular expression library: a poll on features
Date: 05 Jul 2002 17:56:10 +0200	[thread overview]
Message-ID: <lyadp6i2xx.fsf@leia.mandrakesoft.com> (raw)
In-Reply-To: <20020705161302.C20462@pauillac.inria.fr>

Xavier Leroy <xavier.leroy@inria.fr> writes:

(posting on the list cuz of the wishlist below)

> 1- back-references in regexps (e.g. "([a-z]+)\1", meaning any sequence
> of lowercase letters followed by another occurrence of the same sequence);

IMO only usefull in few cases. Could be dropped with no pb.

> 
> 2- partial string matching as per Str.string_partial_match, i.e.
> the ability to recognize that a string is a prefix of a string that
> match a regexp.

quite a surprising feature. I can't imagine an interesting example of
its use.


Here is my wishlist to have regexps easily _usable_
(ie. fill the gap with perl/ruby)

- with compiler support (a la printf's format):

  flags = [ `CASELESS | `MULTILINE | `DOTALL | `EXTENDED | `ANCHORED ]
  m : ?option:flags -> regexp -> string -> string tuple option
  match_all : ?option:flags -> regexp -> string -> string tuple list
  cond_match : ?option:flags -> string -> regexp -> (string tuple -> 'a)
                                       -> regexp -> (string tuple -> 'a)
                                          ...
                                       -> 'a
           (with checking the last regexp is always true unless 'a is unit)
  subst     : string -> regexp -> (string tuple -> string) -> string
  gsubst    : string -> regexp -> (string tuple -> string) -> string
  try_subst : string -> regexp -> (string tuple -> string) -> string option

examples

    match Re.m "(\w+)=(\S+)" s with
    | None -> ...
    | Some(v, val) -> ...
    
    Re.cond_match s
      "^\s*#" (fun() -> None)
      "(\w+)=(\S+)" (fun (v, val) -> Some(v, val))
      "" (fun() -> failwith ("bad line " ^ s))
    
    Re.cond_match s "warning: (.*)" (fun s -> eprintf "a problem occured: %s\n" s)

    Re.subst (Re.subst s "^\s+" (fun() -> "")) "\s+$" (fun() -> "")


- Without compiler support

  flags = [ `CASELESS | `MULTILINE | `DOTALL | `EXTENDED | `ANCHORED ]
  re : string -> regexp
  m : ?option:flags -> regexp -> string -> string list option
  match_all : ?option:flags -> regexp -> string -> string list list
  cond_match : ?option:flags -> string -> (regexp * (string list -> 'a)) list -> 'a
  subst     : string -> regexp -> (string list -> string) -> string
  gsubst    : string -> regexp -> (string list -> string) -> string
  try_subst : string -> regexp -> (string list -> string) -> string option

examples

    match m (re"(\w+)=(\S+)") s with
    | Some [ v ; val ] -> ...
    | _ -> ...
    
    cond_match s [ 
        re"^\s*#", fun() -> None ;
        re"(\w+)=(\S+)", fun (v, val) -> Some(v, val) ;
        re"", fun() -> failwith ("bad line " ^ s) ;
    ]
    
    cond_match s "warning: (.*)" (fun s -> eprintf "a problem occured: %s\n" (hd s))

    subst (subst s (re"^\s+") (fun _ -> "")) (re"\s+$") (fun _ -> "")
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-07-05 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-05 14:13 Xavier Leroy
2002-07-05 15:56 ` Pixel [this message]
2002-07-15 15:52 ` [Caml-list] " Xavier Leroy
2002-07-15 18:41   ` Matt Armstrong

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lyadp6i2xx.fsf@leia.mandrakesoft.com \
    --to=pixel@mandrakesoft.com \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@inria.fr \
    /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 NNTP newsgroup(s).