ajs writes "The next Apocalypse document is slated to focus on regular expressions, and in preperation for that Larry has outlined his thoughts on some major changes to the regular expression syntax. Be aware that this is discussion only and the ideas you see here could change a lot before A5 is published and again further before Perl 6 has a full-fledged interpreter."
/^
(\d+) # id
(T?) # TP
_
(\d+) # SeqNo
X
/xg
And instead we can have beautiful XML regexps like:
/
<start-of-string/>
<capture>
<one-or-more>
<number/> <!-- id -->
</one-or-more>
</capture>
<capture>
<optional>
<string>T</string> <!-- TP -->
</optional>
</capture>
<string>_</string>
<capture>
<one-or-more>
<number/> <!-- Seq No. -->
</one-or-more>
</capture>
<string>X</string>
/xml
(and yes, I'm just kidding)
We knew you were kidding...
Elian on 2002-04-23T15:01:53
The replacement version was far too concise to be real XML.;-p
This, or something like it, was my April Fool's joke for this year. The scary thing was it turned out to mirror a real proposal for XML regexes...Re:Regexps as... XML!
djberg96 on 2002-04-23T19:08:48
I heard that this was one of the examples they're going to use in ORA's upcoming release, How to convert absolutely everything to XML (and like it).Re:Regexps as... XML!
gnat on 2002-04-23T20:54:07
Tsk tsk, that's not an O'Reilly title. You must be thinking of "Fucking Everything Up With XML", "XML Nightmares: The Definitive Guide", or "Hell & XML".--Nat
Re:Regexps as... XML!
jhi on 2002-04-23T21:46:02
Don't you also have "XML Pocket Reference" (1183 pages) in the works?
Re:Regexps as... XML!
ziggy on 2002-04-24T13:37:30
ITYMTS "Hell & XML"."Hell & XML":-) Re:Regexps as... XML!
jhi on 2002-04-24T00:50:34
Hey, that looks like RELAX-NG!
Re:Regexps as... XML!
chromatic on 2002-04-24T03:10:28
Hmm, that looks rather similar to Regexp::English. I'm not sure whether to be impressed or frightened.Re:Regexps as... XML!
babbage on 2002-04-25T18:07:51
Heh. Cool.(This post is nearly content free, but I'm posting it because I just accidentally modded your comment as overrrated when I meant to put underrated, so I'm hoping that by posting I'll negate the mis-moderation. If it doesn't work, I apologize...)
Re:Regexps as... XML!
bronto on 2002-04-24T09:09:09
Beware, someone could take that seriously;-) Re:Regexps as... XML!
shotgunefx on 2002-04-25T06:25:08
I know Perl is used for many things, but a lot of what Perl is used for is dealing with tag based languages on some level. The use of angle brackets I think is sure to cause headaches and line noise. On the other hand, maybe most people will stop trying to roll their own parsers.Re:Regexps as... XML!
Matts on 2002-04-25T06:49:46
That is actually a genuine concern of mine - all of a sudden anything used for parsing angle-brackets stuff has to use \< instead of plain <
*shrug*, it's no bigger or smaller a concern for me than the entire thing that is Perl6.Re:Regexps as... XML!
wickline on 2002-04-25T12:07:16
sounds like a decent argument for including more XML/HTML manip modules in the basic distribution, and referencing them in the docs (particularly the faq)
-matt
Re:Regexps as... XML!
koschei on 2002-04-26T14:26:50
What I'd like to see are more articles on what one can do with XML and the XML modules and *why* you'd use XML for it rather than any other method.
I've been casually observing XML for a while (and had to study it for half a semester or so, which means my knowledge went down rather than up) but it hasn't energised me into doing anything with it. The most I do is aggregate some RSS/RDF feeds for regular news emails.
So what is the practical side of XML? Can we see more XML and Perl articles on perl.com? Should I absorb xml.com perhaps?
I mean, it's the nature of things to change, but we're not going to win over converts from other languages if they have to learn all new regex syntax to use perl 6.
Re:forking the world again?
rafael on 2002-04-23T21:04:23
In other words, Perl's regexps drive the other languages' implementations.Note that the new syntax is also there to allow more powerful, BNF-like, constructs.
Re:forking the world again?
hossman on 2002-04-23T21:19:00
In other words, Perl's regexps drive the other languages' implementations.Yes, but if all those millions of young'ns out there that only know java, and are just now learning the wonders of regexps read about "Perl regular expressions" in their javadocs, and then try to use perl6 and discover that the syntax has completely changed, they aren't going to be eager to figure it out.
Note that the new syntax is also there to allow more powerful, BNF-like, constructs.
Don't get me wrong, I'd love if if Perl made it trivial to write a parser for a BNF expressable grammer, but wouldn't that functionality be better left to a module (Parse::BNF sounds like a great name) with methods for defining grammers using hashes of hashes of arrays of hashes of tokens => subs?
I mean, consider how many people use regexps on a daily basis to how many would even want to use BNF grammers on a weekly basis.
Re:forking the world again?
Elian on 2002-04-23T22:07:38
They'll cope.Yes, but if all those millions of young'ns out there that only know java, and are just now learning the wonders of regexps read about "Perl regular expressions" in their javadocs, and then try to use perl6 and discover that the syntax has completely changed, they aren't going to be eager to figure it out.In other words, Perl's regexps drive the other languages' implementations.:) The current regex syntax is past the point where adding new syntax is conceptually feasable.
Also, if you really really want perl 5 syntax, I expect that can be arranged somehow. If we're going to be able to parse perl, we're going to have to be able to parse perl 5 regexes...
Recursive regexes
robin on 2002-04-24T12:15:22
The current regex syntax is past the point where adding new syntax is conceptually feasible.
I'm not so sure about that.Re:forking the world again?
erikharrison on 2002-04-24T14:51:13
Adding constructs to the current regex syntax has been difficult - not impossible, but the (?x . .
.) syntax is incredibly strained. As such the syntax needs a change, and I would argue that since Perl is so widely known for being innovative in it's regexes that we should be willing to take the plunge to change it, should it be necessary. One of the things Larry has pointed out over the perl6-language list is that Perl isn't realy good at writing parsers. We can write lexers and tokenizers pretty well, but true parsers are non trivial. This is a strange weakness for a text processing language.
The angles getting new uses enhances Perl regexes wihtout breaking to much. Newbies Perl 5 regexes will port with only some backslashes to keep tags kosher, most of the time. If we are worried about the newbies, it should be pointed out that at the basic level regexes do what they always did.
/start(.*)stop/; print $1;
still does what we expect. Few languages offer 'Perl compatible Regexes', but plenty offer 'Perl like regexes'. We're gonna have to teach the Java Junkies they can't && their character classes anyway, so why not teach them about angles?All in all I find that interlanguage communication shouldn't be a reason to disapprove of Larry's changes. The only case where I'd be worried is Python, and that is because Guido himself asked p5p about whether or not certain syntax would be used so that Python could extend Perl's regex abilities a little. Since they are the only ones that asked, they're the only ones I'm worried about. As I said before, if everyone agrees that Perl is king of regexes, then we shouldn't let that fame prevent us from enhancing our regex syntax and ability.
Re:forking the world again?
Elian on 2002-04-24T17:21:54
I think we have far more to worry about from Ruby than we do from Python...
Re:Not to sound negative, but...
pdcawley on 2002-04-24T08:26:37
Having done a chunk of non trivial perl 6 coding (A Scheme Interpreter), I can tell you that it 'feels' like Perl. My general feeling was along the lines of "Why can't I do this in Perl now", and not just for the// operator. given/when, the new subroutine prototyping rules, lexically scoped subs and all the rest just felt right. Re:Not to sound negative, but...
2shortplanks on 2002-04-24T09:21:59
Hmmm. I've had this argument several times.I've argued that this language is still Perl in the sense that the code (as Piers says above) still feels a lot like Perl. Remember that the stuff always being talked about are the differences not what has stayed the same.
I've argued (recently, with limited success) that Perl 6 is Perl because Perl is the community and the devlopers, not any one bit of software or code.
However, I've also argued quite a lot that maybe it should have a different name (if just for branding) as this is to a certain respect a different language and a new direction, and deserves (at least from a marketting point of view) to have a fresh start. Somewhat like a sub-brand of an existing product.
Of course, I'm Just Another Perl Hacker, not anyone who's actually doing anything constructive towords Perl 6, so in the end I'm just waffling...
Re:Not to sound negative, but...
Damian on 2002-04-24T20:23:07
from what I have read, none of it looks like the
perl I know and love.
The Apocalypses and Exegeses can easily give that impression. But so can reading perldelta for any particular release of Perl 5. And the reason is the same: those documents are all about what is changing, and rarely mention what is staying the same (because then they'd be 10 times longer!)
But Perl 6 really is Perl. It feels like Perl to program in, and most of its syntax and semantics are identical to those of Perl 5.
It's like the old saying: if it looks like a Terminator, and it tracks like a Terminator, and it will-not-stop-till-you-are-DEAD like a Terminator, then it's a Terminator. The fact that it's now made of mimetic polyalloy rather than gears and levers and nuts and bolts doesn't affect its intrinsic Terminatorosity.
Perl 6 is still the same killer language you know and love. We're just making it smoother, faster, more uniform, and vastly more adaptable.
If you're interested in seeing just how similar Perl 6 is going to be to Perl 5 in most cases, check out...And Now For Something Completely Similar Re:Not to sound negative, but...
mshiltonj on 2002-04-25T13:16:01
If you're interested in seeing just how similar Perl 6 is going to be to Perl 5 in most cases, check out...And Now For Something Completely Similar [samag.com]
Good article. It eliminated my trepidation about perl6. Now that I have a new eye to the changes, I'll have to read the Apocalyse and Exegesis docs in earnest.
Thanks!Re:Not to sound negative, but...
Odud on 2002-04-25T16:10:41
I found "...And Now" a very reassuring document - If the examples are typical of the amount of conversion necessary then we have little to fear. I hope that Damian will be able to update the document or produce additional ones when the regex details are finalised.