[erlang-questions] Adoption of perl/javascript-style regexp syntax

Richard O'Keefe ok@REDACTED
Wed Jun 3 08:02:53 CEST 2009


On 3 Jun 2009, at 5:09 pm, Kevin Scaldeferri wrote:
>
> So, you'd like it to be Perl, then?

No, absolutely the complete and total reverse.

Perl is a horrible example of how to do it WRONG.

Perl doesn't do any of the things I have stressed as important.
In fact, it goes about as far as it can in the opposite direction.

The kind of regular expression I want is the POSIX kind:  the
kind that can be implemented to run in linear time, not the
Perl kind that takes exponential time.

>
I just want to be able to compute them *AS* regular expression
values, not as strings.  It's like XML:  if you want to build
XML, strings are a horrible way to do it.

Unlike Perl, I don't want *any* special syntax for regular expressions.

I've now found a page that describes fairly precisely what I want
for regular expressions in Erlang, except the page describes how to
do it for Scheme.

http://www.scsh.net/docu/post/sre.html

One of the examples from that page is matching
c[ad]+r.  In Erlang, something like
	{seq,"c",{plus,{alt,"a","d"}},"r"}
would do it.  Now this is clumsier than /c[ad]+r/,
but with building blocks like that you can write

matcher(Start,Opt1,Opt2,Finish) ->
     {seq,Start,{plus,{alt,Opt1,Opt2}},Finish}.

where the things passed in are *regular expressions*,
including strings as a special case, so there is no
quoting problem.

Take a real example from an AWK script.

/^[a-zA-Z][a-zA-Z0-9.]*[         ]*<-[   ]*function/

I'd like to be able to write this:

opt_space() -> {star,{cset," \t"}}.

letters() -> "a-zA-Z".

continuers() -> "0-9." ++ letters().

identifier() -> {seq,{cset,letters()},{star,{cset,continuers()}}}.

operator(X) -> {seq,opt_space(),X,opt_space()}.

pattern() ->
     {seq,bol,identifier(),operator("<-"),"function"}.

It's longer, but in a complete program, I'm likely to have a use
for most of these bits, and I am _certainly_ going to find it
easier to get this right one step at a time.

Do you see any Perl here?  I don't.



More information about the erlang-questions mailing list