Ruby equivalent of assemble RE?

K

Kenneth McDonald

James said:
I'm not aware of one, though we did play with the idea a little in a
very old Ruby Quiz:

http://www.rubyquiz.com/quiz4.html

At 3,000 lines (granted a lot of that is documentation), it's a hefty
port job. I think it's a neat library though. Would be cool to see
it done.

James Edward Gray II
If what you want is a way to easily assemble and use regular
expressions, I have a Python library that comes in at about 700-800
lines (excluding unit tests and docs). For example, to define a re
matching integer complex numbers (uses the fact that Python allows
named, not just numbered, re groups):

intPat = OPT("-") + CHAR("0123456789")*1 # *1 means 1 or more.
complexPat = intPat['real'] + ALT("-", "+")['op'] + intPat['im']

Let's find out the real parts of all complex numbers in a string:

for matchresult in complexPat.iter(somestring): print matchresult['real']

Using some of the package's predefined patterns, let's define a complex
num pattern that handles floating point numbers and whitespace:

complex = PAT.float['real'] + CHAR.whitespace*0 + ALT("-", "+")['op']
+ PAT.float['im']

etc. etc. I'd like to convert it to Ruby, but don't have the time. It'd
be a significant but not huge job--more tedious than anything else. I
suspect the Ruby version would come in a little shorter, maybe 600
lines? Anyone interested?


Ken
 
J

John Ky

Sounds interesting, can I have a look at the source code? I may just
be interested in rewriting it in ruby.

Thanks

-John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top