caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Stefan Heimann <lists@stefanheimann.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] ocamllex, regular expression syntax
Date: Tue, 03 Jun 2003 09:42:42 +1000	[thread overview]
Message-ID: <3EDBE0F2.2010009@ozemail.com.au> (raw)
In-Reply-To: <20030522205632.GA2130@kunz.ratzer>

Stefan Heimann wrote:

> Hi,
> 
> [sorry if this posting appears twice. I first submitted it with my
> news client. It seems not to appear on the mailing list and so I
> decided to post it again]
> 
> 
> I new to ocaml and today I played a little bit around with
> ocamllex. Now I'm wondering why ocamllex has this strange regular
> expression syntax. One has to quoted every character
> Regular expressions like this
> 
> "[^"\\]*(\\.[^"\\]*)*"
> 
> are not easy to read, but with the ocamllex syntax it is even more
> difficult:
> 
> '"'[^'"''\\']*('\\'_[^'"''\\']*)*'"'
> 
> (and harder to write).
> 
> Is this just for historical reason or is there a practical reason for
> this syntax? 


The ocamllex syntax is MUCH more readable
if you figure out how to use it correctly:

let bindigit = ['0'-'1']
let octdigit = ['0'-'7']
let digit = ['0'-'9']
let hexdigit = digit | ['A'-'F'] | ['a'-'f']


let bin_lit  = '0' ('b' | 'B') (underscore? bindigit) +
let oct_lit  = '0' ('o' | 'O') (underscore? octdigit) +
let dec_lit  = ('0' ('d' | 'D'))? digit (underscore? digit) *
let hex_lit  = '0' ('x' | 'X') (underscore? hexdigit)  +

The reason for quoting characters is now obvious:
ocamllex provides regular *definitions* not just
regular expressions, and they're infinitely superior;
its much better to use identifers for expressions,
than to embed them in strings like pcre

	"<alpha>*" // pcre
	alpha * // ocamllex

You'd be mad not to write your example like this:

let quote = '"'
let slosh = "\\"
let any = _
let nsq = [^'\\''"'] (* WEAK! *)

dquote nsq * ( any nsq * ) * dquote

which I can actually read :-)

the [] syntax is weak though, Felix does much better
(and regular definitions are built into the language
like patterns are in ocaml)

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


-------------------
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


      parent reply	other threads:[~2003-06-02 23:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-22 20:56 Stefan Heimann
2003-05-22 23:04 ` David Brown
2003-05-23  8:36   ` Stefan Heimann
2003-05-23  6:31 ` Pierre Weis
2003-05-23  8:27   ` Stefan Heimann
2003-05-23  8:53 ` Luc Maranget
2003-06-02 23:42 ` John Max Skaller [this message]

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=3EDBE0F2.2010009@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@inria.fr \
    --cc=lists@stefanheimann.net \
    /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).