[erlang-questions] Adoption of perl/javascript-style regexp syntax
Richard O'Keefe
ok@REDACTED
Thu Jun 4 06:00:33 CEST 2009
On 4 Jun 2009, at 6:53 am, Kevin Scaldeferri wrote:
> $re1 = qr/abc/
> $re2 = qr/123/
> $re3 = qr/${re1}asdf${re2}/
>
> You can have a named capture:
>
> /\w*\.(?<suffix>\w)/
Anyone out there remember TECO?
Once said to be the only programming language where
a valid program was indistinguishable from line noise.
Now joined by Perl.
> Well, fortunately regexes in perl are only strings insomuch as any
> source code construct is a string.
Not true. Statement blocks nest without backslashes.
Expressions nest without backslashes.
Given Perl's string interpolation, arguably Perl's _strings_
aren't "strings", but they DO require special syntax, including
backslashes, to embed expressions in them.
> $opt_space = qr/[ \t]*/;
> $letters = qr/[a-zA-Z]/;
> $continuers = qr/[0-9\.]|${letters}/;
> $identifier = qr/${letters}${continuers}*/;
>
> sub operator {
> $x = shift;
> qr/${opt_space}${x}${opt_space}/;
> }
>
> $larrow = operator("<-");
> $pattern = qr/^${identifier}${larrow}function/;
>
>
> So, other than your opposition to a concise syntax, I'm not really
> seeing your point.
I'm not opposed to a concise syntax.
I'm opposed to _complex_ syntax.
I'm opposed to an _unreadable_ syntax.
I'm opposed to an _error-prone_ syntax.
I'm opposed to _nested_ syntaxes with conflicting rules.
Like for example the way that "$" in a Perl regular expression
might mean end-of-string or might mean here-comes-a-variable.
Regular expressions are nice and concise and readable
when and only when they are _simple_.
Regular expressions are _still_ a really great tool when they
are complex, but stringy syntax is then no longer a good way to
write them.
More information about the erlang-questions
mailing list