More Perl regex stuff in E

mzukowski@bco.com mzukowski@bco.com
Fri, 16 Apr 1999 08:43:30 -0700


I'm not familiar enough with E or perl's regex syntax to really understand
your code, but I know that Python does let you break up strings just like C
so that you can do something like:

r = re.compile( "\n?" # optional newline(?)
			"[ \t]*" # zero or more tabs or spaces
		)

This is a common idiom in Python regex code and a simple way to explain what
you are doing.  The compiler implicitly concatenates those strings into one
string as the argument to re.compile.

Do you have a need for real language transformation tools?  I'm quite
involved with the ANTLR community and have done some serious parsers and
translators using that tool (Pick to VB, GCC to GCC).  It has a hook so that
it can generate to different languages by adding your own code generator.
Currently it supports Java and C++.  Since E is similar to Java it shouldn't
be too hard to generate E directly.  If it generated E directly, that would
imply that the generated code would be secure, yes?  

What sort of need would the E community have for an LL lexer, parser, and
tree parser generation tool?

Monty
www.antlr.org

> -----Original Message-----
> From:	Mark S. Miller [SMTP:markm@caplet.com]
> Sent:	Thursday, April 15, 1999 11:22 PM
> To:	E Language Discussions
> Subject:	More Perl regex stuff in E
> 
> I don't know whether to laugh or cry.  Before I started *using* Perl
> regular 
> expressions in E, I felt my code was readable.  The following code doesn't
> 
> look readable to me, but is this just because I'm not used to reading this
> 
> style?  In any case, it's small, was easy to write, worked the first time,
> 
> and does something a bit complicated: parsing updoc scripts.  It 
> successfully parsed the output of html2txt() applied to some of my 
> documentation pages.  If I'd tried to write this without regex's, it might
> 
> be locally more readable, but would also be a lot more code -- an 
> interesting tradeoff.  How does it compare with regex use in Perl or 
> Python?
> 
> Here's a readability test: By reading this code, can you easily tell what 
> syntax it parses?
> 
> (If your mailer wrapped the lines, please unwrap them before reading)
> 
> 
> define parseUpdoc(script) {
>     define result := [] diverge
>     while (script =~ rx`(?ms)(@comment.*?)\n?[ \t]*\?[
> \t]?(@code.*?)\n(@rest.*)`) {
>         script := rest
>         while (script =~ rx`(?ms)[ \t]*>[ \t]?(@moreCode.*?)\n(@rest.*)`)
> {
>             code += "\n" + moreCode
>             script := rest
>         }
>         if (script =~ rx`(?ms)[ \t]*#[ \t]+?(@label\w*):[
> \t]*(@output.*?)[
> \t]*\n(@rest.*)`) {
>             script := rest
>             while (script =~ rx`(?ms)[ \t]*#[ \t]*(@moreOutput.*?)[
> \t]*\n(@rest.*)`) {
>                 output += "\n" + moreOutput
>                 script := rest
>             }
>             result push(CarrotMaker(comment, code, label, output))
>         } else {
>             result push(CarrotMaker(comment, code, null, null))
>         }
>     }
>     result snapshot
> }
>