Part of the program I am working on needs to convert regular expressions in vim style to Perl regular expressions. I'm reading them in from a file and converting them at runtime.
I've been looking through the vim documentation and found
this description of the differences between the two regex styles. Some of those don't look too difficult to deal with - for instance, I can easily change \c to (?i). However, for most of them I'm not sure how I'd go about implementing them.
For example, I need to change \%(atom) into (?:atom). At first glance that looks ok, but then I started thinking about nested parentheses. If I use a greedy quantifier, it might eat up too much of the string, since it will go to the last closing parenthesis in the whole pattern. If I use a non-greedy quantifier, it won't work for something like /\%(foo(bar))/. Is there a way to make this work?
After reading
this explanation of the 'magic' modifiers, I think they would be possible to do, if fairly complicated given the number of things I need to check for and replace. Same goes for the differing newline behaviour - it looks somewhat tricky but doable if I have the patience. :) However, I'm not sure how I could successfully match the 'atom' for the zero-width assertions, and the \& modifier looks like a nightmare; can anyone think of a good way to deal with either of these?
This is a project I'm doing to help me learn Perl. It's not anything critical, so in the end if there's no way to convert some of those incompatibilities then I'll probably just ignore them. :P But if anyone can come up with some ideas for nice ways to do this I'd really appreciate it, since I'd like my program to be able to correctly interpret as many patterns as possible. Alternatively, if anyone knows of some magical CPAN module that would do this for me, that'd be great - I searched but unfortunately couldn't find one.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.