niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl » modules
Module Submission: Regexp::MultiLanguage
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
robby.walker@gmail.com
*nix forums beginner


Joined: 23 Jun 2006
Posts: 7

PostPosted: Thu Jun 22, 2006 9:40 pm    Post subject: Re: Module Submission: Regexp::MultiLanguage Reply with quote

Yes - it's easily extendable - there's 5 functions you have to write
for your Regexp::MultiLanguage::YourLanguage module. Each 'dialect' is
generally only 20 lines long - at this point the three languages that
are there were just the top priorities.

- Robby

Sherm Pendley wrote:
Quote:
robby.walker@gmail.com writes:

I'm working on a project where I need to use a set of common regular
expressions in more than one programming language. To facilitate this,
I've written Regexp::MultiLanguage which parses a simple language and
produces code that works in Perl, PHP, and JavaScript. (plus, adding
new languages is easy) Sound useful? Is this already implemented? Is
the name OK?

It sounds like it might be useful, and I've no issues with the name, but
it does sound rather incomplete. What about sed, Java, PCRE, etc?

More to the point I suppose, do you plan to provide a mechanism for users
to add new language support modules? Regexp::MultiLanguage::Java for
instance. If you do provide such a mechanism, then the languages that
happen to be supported by the "core" module becomes much less critical.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Back to top
Sherm Pendley
*nix forums Guru


Joined: 03 Mar 2005
Posts: 527

PostPosted: Thu Jun 22, 2006 6:43 pm    Post subject: Re: Module Submission: Regexp::MultiLanguage Reply with quote

robby.walker@gmail.com writes:

Quote:
I'm working on a project where I need to use a set of common regular
expressions in more than one programming language. To facilitate this,
I've written Regexp::MultiLanguage which parses a simple language and
produces code that works in Perl, PHP, and JavaScript. (plus, adding
new languages is easy) Sound useful? Is this already implemented? Is
the name OK?

It sounds like it might be useful, and I've no issues with the name, but
it does sound rather incomplete. What about sed, Java, PCRE, etc?

More to the point I suppose, do you plan to provide a mechanism for users
to add new language support modules? Regexp::MultiLanguage::Java for
instance. If you do provide such a mechanism, then the languages that
happen to be supported by the "core" module becomes much less critical.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Back to top
robby.walker@gmail.com
*nix forums beginner


Joined: 23 Jun 2006
Posts: 7

PostPosted: Thu Jun 22, 2006 5:53 pm    Post subject: Module Submission: Regexp::MultiLanguage Reply with quote

I'm working on a project where I need to use a set of common regular
expressions in more than one programming language. To facilitate this,
I've written Regexp::MultiLanguage which parses a simple language and
produces code that works in Perl, PHP, and JavaScript. (plus, adding
new languages is easy) Sound useful? Is this already implemented? Is
the name OK?

For example, here is a sample Regexp::MultiLanguage input:

number : integer || binary

integer : /\d+/
binary : /0b[01]+/i

I'd eventually like to extend this language to allow named regexp
captures and more, but for version 0.01 I'm keeping it simple.

I then use the following code (which assumes the above input is stored
in $snippet)

use Regexp::MultiLanguage qw(Perl JavaScript PHP);

print "Perl: \n";
print Regexp::MultiLanguage->compile( $snippet, 'Perl', 'isa_' );

print "\nJavaScript: \n";
print Regexp::MultiLanguage->compile( $snippet, 'JavaScript',
'isa_' );

print "\nPHP: \n";
print Regexp::MultiLanguage->compile( $snippet, 'PHP', 'isa_' );

This produces the following:

Perl:
sub isa_number { (isa_integer($_[0]) || isa_binary($_[0])) }

sub isa_integer { ($_[0] =~ m/\d+/) }

sub isa_binary { ($_[0] =~ m/0b[01]+/i) }

1;

JavaScript:
function isa_number(value) { return (isa_integer($_[0]) ||
isa_binary($_[0])) }

function isa_integer(value) { return (value.match(/\d+/) }

function isa_binary(value) { return (value.match(/0b[01]+/i) }

PHP:
<?php

function isa_number( $text ) { return (isa_integer( $text ) ||
isa_binary( $text )); }

function isa_integer( $text ) { return preg_match("/\\d+/", $text);
}

function isa_binary( $text ) { return preg_match("/0b[01]+/i",
$text); }


?>

I'd love to hear your comments.

Thanks,
- Robby
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sat Jan 10, 2009 12:44 am | All times are GMT
navigation Forum index » Programming » Perl » modules
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts strange error when importing a module Robin Becker python 1 Thu Jul 20, 2006 4:04 pm
No new posts subprocess module Bulkan-Savun Evcimen python 0 Thu Jul 20, 2006 1:59 pm
No new posts understanding submission mode / sender:-header not added Heiko Schlittermann Exim 0 Wed Jul 19, 2006 9:52 pm
No new posts Load Module Kaushal Shriyan Apache 1 Tue Jul 18, 2006 12:52 pm
No new posts RFC: my iterthreader module Justin Azoff python 0 Tue Jul 18, 2006 3:15 am

Online Advertising | Loans | Credit Cards | Neopets Cheats, Games and Neopoints | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3577s ][ Queries: 20 (0.2286s) ][ GZIP on - Debug on ]