Saturday, February 2, 2013

RFC on VimRegStyle


VimRegStyle

more than just a pattern library for sexy regex

This is a request for feedback on a new plugin: https://github.com/Raimondi/VimRegStyle

VimRegStyle is designed to be a repository of PCRE ←→ Vim regex equivalences and general pattern library for Vimmers.

Our goal is to have somewhere for the collection of common regex patterns expressed in the Vim regex flavour. We frequently get regex help requests on #vim that are answered with “look that common pattern up on a regex lib site” only to have them come back and say “it didn’t work” because they plugged the PCRE into Vim and got spanked for it.

No more! Now we have a library of our own!

So… what do I want from you? Feedback on:
  1. Design issues (concerns & improvements)(*)
  2. Ideas for tools, commands, maps and scripts surrounding such a pattern library.
(*) This might be the place to mention that we’ve taken several rather bold steps in the implementation of the pattern repository files:
  1. the patterns/ directory contains *.vrs files with the following format:
    name flavour pattern
    Where:
    • name contains no whitespace
    • flavour can be vim or pcre
    • pattern is not delimited — use a bare regex
  2. the patterns are further enhanced in the following two ways; they:
    • accept PCRE style multiline, whitespace insensitive syntax. All multiline patterns must commence on the line below the named entry and must be indented with whitespace.
    • accept a new regex atom: \%{name,count,separator} providing pattern composition by inline-expanding the named pattern at the current point in the regex (optionally count times, each one separated by separator.)

      As an example:, assuming the VRS library had a pattern called _ip4_segment that represented a single 0-255 chunk, an ip4 regex could then be written using this composition atom as: \<\%{_ip4_segment,4,.}>
      As a side note, the Extended Regex features mentioned here will be further elaborated on in a separate article. These features can be freely used in other projects, pulling from arbitrary lookup sources, including the runtime vars in Vim itself. But more on that later.
When we’re finished with this RFC process we will be looking for pattern contributions. Thanks to all who contribute their time and energy into this project! :-)

No comments:

Post a Comment