From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA28969; Thu, 20 Mar 2003 17:50:44 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA29688 for ; Thu, 20 Mar 2003 17:50:43 +0100 (MET) Received: from venus.is.s.u-tokyo.ac.jp (venus.is.s.u-tokyo.ac.jp [133.11.12.9]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h2KGoeX09259 for ; Thu, 20 Mar 2003 17:50:41 +0100 (MET) Received: from tuba.is.s.u-tokyo.ac.jp (tuba.is.s.u-tokyo.ac.jp [133.11.12.102]) by venus.is.s.u-tokyo.ac.jp (8.11.6/3.7W) with ESMTP id h2KGoaA25366 for ; Fri, 21 Mar 2003 01:50:36 +0900 (JST) Received: (from oiwa@localhost) by tuba.is.s.u-tokyo.ac.jp (8.11.6+Sun/3.7W) id h2KGoaI08266; Fri, 21 Mar 2003 01:50:36 +0900 (JST) X-Authentication-Warning: tuba.is.s.u-tokyo.ac.jp: oiwa set sender to oiwa@yl.is.s.u-tokyo.ac.jp using -f To: caml-list@inria.fr Subject: [Caml-list] Announce: Regexp/OCaml syntax extension From: Yutaka OIWA Date: 21 Mar 2003 01:50:36 +0900 Message-ID: User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; yutaka:01 oiwa:01 u-tokyo:01 camlp:01 -macro:01 python:01 ocaml's:01 pcre:01 $1,:01 $2,:01 easy-to-use:99 parses:01 foobar:01 shibuya:01 regexp:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. , 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