----- Original Message -----
From: "Hal E. Fulton" <hal9000 / hypermetrics.com>

I'd like to write a complex regex in a more readable
form which could then be "compiled" to a Ruby regex.
(Now that I think about it, the analogy between regex
notation and machine language is not a bad one.)
----------------------------

It's important, however, not to confuse "the regular language described by a
regular expression" with "a language for building objects of the class
Regexp".  For example, the current regexp literal is a (yucky) language for
building Regexps, but `a+' is *not* a member of the regular language it
describes, which only has words with 1 or more `a's in it.  You see what I'm
saying?  (I'm not even sure I understood you right!)



----------------------------
Here's a very rough first effort. (One too simple really.)

  phone = RegexLang.new(<<EOF)
    string "("
    digits(3,:area_code,Fixnum)
    # Above: Grab three digits, store in area_code
    # as a Fixnum
    string ") "
    match(:rest) do  # Store this stuff in 'rest' as
      digits(3)      # a String
      string "-"
      digits(4)
    end
  EOF

----------------------------

I was hoping for something clearer than regexps, but without giving up *too*
much in the way of concision (is that a word?):

  phone = RegexLang.new(<<EOF)
    '(' area_code=d*3.to_i ') ' rest=(d*3 '-' d*4)
  EOF


Feels like too much magic to me, though.  Seems like we whould be able to do
something closer... closer to pure Ruby...

...

I'm not seeing it yet, though.  :(

We're trying to define in one fell swoop a (possibly infinite) set of
strings.  Could we use some sort of... of... like this:

  #  /a*b/
  'a'*(0..) + 'b'

  #  /(a|b){5,7}/
  ('a' | 'b') * 5..7

Those aren't great examples, but it seems like it could be done with a fair
amount of overloading/defining in the base classes.

So...

  local_number = Digit*3 + '-' + Digit*4
  area_code    = Digit*3  #  .to_i here??
  phone_number = '(' + area_code + ') ' + local_number


Oh, I don't know.  It's a start.  At least it looks like Ruby and not Perl!

Speaking of which, I went to read about the changes to regexps in Perl 6.
It was in one of Larry Wall's apocalypses.  It drove home several important
points for me, but really only one of them was fit for a public forum :)

- Just because you can see the problem, that need not imply you have *any*
clue about the solution.  (Obviously, this goes for myself as well as for
LW!)


----------------------------
Take a left turn at Albuquerque
----------------------------

I did that once!  On a road trip.  It was cool...

Chris