[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby equivalent of assemble RE?

John Ky

10/12/2006 10:48:00 PM

Is there a ruby equivalent of this?

http://search.cpan.org/dist/Regexp-Assemble/A...

Thanks

-John

3 Answers

James Gray

10/13/2006 3:13:00 AM

0

On Oct 12, 2006, at 5:47 PM, John Ky wrote:

> Is there a ruby equivalent of this?
>
> http://search.cpan.org/dist/Regexp-Assemble/A...

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/...

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

Kenneth McDonald

10/13/2006 5:17:00 AM

0

James Edward Gray II wrote:
> On Oct 12, 2006, at 5:47 PM, John Ky wrote:
>
>> Is there a ruby equivalent of this?
>>
>> http://search.cpan.org/dist/Regexp-Assemble/A...
>
> 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/...
>
> 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

John Ky

10/13/2006 5:51:00 AM

0

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

Thanks

-John

On 10/13/06, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote:
> James Edward Gray II wrote:
> 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