Module Submission: Regexp::MultiLanguage

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Module Submission: Regexp::MultiLanguage

    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

    robby.walker@gmail.com Guest

  2. Similar Questions and Discussions

    1. Module submission: REV
      Hi, I've written a mini programming language called REV for data validation. REV stands for Really Easy Validation - and is a language similar...
    2. how make multilanguage in flex
      in Struts ?i can use <bean:message key=""/> to get a resource text from *.properties? but i can't find the same way in flex , anybody know it ?...
    3. multilanguage chars in XML
      Hi there, I'm trying to get some text data from an XML file with spanish characters (such as ?, ? and so). I've tried to change the text...
    4. Extend Multilanguage Cast
      Hi! I have a movie with multilanguage support by copying the external cast file, changing the members and then exchange the cast file at runtime....
    5. multilanguage website
      I'm trying to make a multilanguage website. When the user enters the site, I want to detect the language and automatically make a redirection. How...
  3. #2

    Default Re: Module Submission: Regexp::MultiLanguage

    [email]robby.walker@gmail.com[/email] 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: [url]http://camelbones.sourceforge.net[/url]
    Hire me! My resume: [url]http://www.dot-app.org[/url]
    Sherm Pendley Guest

  4. #3

    Default Re: Module Submission: Regexp::MultiLanguage

    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:
    > [email]robby.walker@gmail.com[/email] 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: [url]http://camelbones.sourceforge.net[/url]
    > Hire me! My resume: [url]http://www.dot-app.org[/url]
    robby.walker@gmail.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139