caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yutaka OIWA <oiwa@yl.is.s.u-tokyo.ac.jp>
To: caml-list@inria.fr
Subject: [Caml-list] Announce: Regexp/OCaml syntax extension
Date: 21 Mar 2003 01:50:36 +0900	[thread overview]
Message-ID: <vfiwuiuugmb.fsf@tuba.is.s.u-tokyo.ac.jp> (raw)

Hello subscribers:

I release a camlp4-macro package called Regexp/OCaml.

I believe Objective Caml is a powerful tool not only for writing an
interpreter and compiler but also for writing casual "script"
applications which were in a territory of Perl, Python and
Ruby. However, string decomposition is one of OCaml's weak points when
compared to those scripting languages: the interfaces of both Str
module and Pcre module are very primitive and cumbersome if they are
heavily used.  Regexp/OCaml solves this point by providing syntax
support for regular expression matching.

Regexp/OCaml provides convenient syntax sugar for regular expression
match against strings using PCRE/OCaml library. The features of this
macro package are the following:

    * Convenient syntax: similar to standard match-with expressions
    * Binding matching substrings to variables: no more $1, $2, ...
    * Automagical easy-to-use type-coercion: no flood of int_of_string etc.
    * Support for optional-patterns: gives string option type etc.
    * Default values for optional-patterns 

For example, parsing an entry for some log file becomes as easy as follows:

  try
    while true do
      let line = input_line ic in
        Regexp.match line with
          "^\((\d\d):(\d\d):(\d\d)\)\[(.*?)\] (.*)$" 
           as hour : int, min: int, sec : int, name, line ->
             let time = hour * 3600 + min * 60 + sec in
             ...
        | "^# (.*)$" as meta_info ->
             ...
        | _ -> ()
    done
  with End_of_file -> ()

This short code parses both line in format like
  "(00:34:32) [foobar] something" and "# some meta info"
and binds appropriate data into variables which can be used inside "...".
Compare the code above with an equivalent without using syntax extension.

Regexp/OCaml is downloadable from the web location
http://www.yl.is.s.u-tokyo.ac.jp/~oiwa/caml/ .

In addition to the main macro called pa_regexp_match, the package also
contains two tiny macros:

 1) pa_pragma changes an option for loaded camlp4 macros inside source code.
 2) pa_once provides "once" construct which evaluates any expression
    only once per execution (pa_regexp_match uses this internally).

Any comments will be greatly appreciated.

-- 
Yutaka Oiwa              Yonezawa Lab., Dept. of Computer Science,
      Graduate School of Information Sci. & Tech., Univ. of Tokyo.
      <oiwa@yl.is.s.u-tokyo.ac.jp>, <yutaka@oiwa.shibuya.tokyo.jp>
PGP fingerprint = C9 8D 5C B8 86 ED D8 07  EA 59 34 D8 F4 65 53 61

-------------------
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:[~2003-03-20 16:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-20 16:50 Yutaka OIWA [this message]
2003-03-21 10:18 ` Richard W.M. Jones
2003-03-28 20:13 ` Pierre Weis

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=vfiwuiuugmb.fsf@tuba.is.s.u-tokyo.ac.jp \
    --to=oiwa@yl.is.s.u-tokyo.ac.jp \
    --cc=caml-list@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).