Loading ...
Sorry, an error occurred while loading the content.

Re: perl x modifier regex ?

Expand Messages
  • Theerasak Photha
    ... No, but there is this: http://www.vim.org/scripts/script.php?script_id=1091
    Message 1 of 4 , Dec 28, 2006
    • 0 Attachment
      On 12/28/06, Marc Chantreux <marc.chantreux@...> wrote:
      > hi all,
      >
      > Is there a way to obtain the perl x modifier behaviour in vim regex
      > (spaces are non significants, comments are allowed). This is very
      > usefull to make a regexp more readable.

      No, but there is this:

      http://www.vim.org/scripts/script.php?script_id=1091
    • A.J.Mechelynck
      ... You can always add one or more lines of comments above or below the line including the pattern in a Vim script, or even, in most cases, at the end of the
      Message 2 of 4 , Dec 28, 2006
      • 0 Attachment
        Marc Chantreux wrote:
        > hi all,
        >
        > Is there a way to obtain the perl x modifier behaviour in vim regex
        > (spaces are non significants, comments are allowed). This is very
        > usefull to make a regexp more readable.
        >
        >
        > regards
        > mc
        >

        You can always add one or more lines of comments above or below the line
        including the pattern in a Vim script, or even, in most cases, at the end of
        the line; but IIUC you cannot insert comments in the middle of a pattern.

        To use perl regexps, you can of course embed perl statements in a perl-enabled
        version of Vim; but of course at the cost of making the script less portable.


        Best regards,
        Tony.
      • Marc Chantreux
        Hi Theerasak, my problem is not to read the regExp but maintain them so your script don t help here. It sounds good btw. Regards, mc
        Message 3 of 4 , Jan 2, 2007
        • 0 Attachment
          Hi Theerasak,

          my problem is not to read the regExp but maintain them so your script
          don't help here. It sounds good btw.

          Regards,
          mc

          Theerasak Photha a écrit :
          > On 12/28/06, Marc Chantreux <marc.chantreux@...> wrote:
          >> hi all,
          >>
          >> Is there a way to obtain the perl x modifier behaviour in vim regex
          >> (spaces are non significants, comments are allowed). This is very
          >> usefull to make a regexp more readable.
          >
          > No, but there is this:
          >
          > http://www.vim.org/scripts/script.php?script_id=1091
        • Marc Chantreux
          ... Ok. There is no solution so i decided to write functions that returns RE chunks in vimfiles/autoload/RE{,/XML}.vim 2 advantages to proceed like this : -
          Message 4 of 4 , Jan 2, 2007
          • 0 Attachment
            A.J.Mechelynck a écrit :
            > You can always add one or more lines of comments above or below the
            > line including the pattern in a Vim script, or even, in most cases, at
            > the end of the line; but IIUC you cannot insert comments in the middle
            > of a pattern.
            Ok. There is no solution so i decided to write functions that returns RE
            chunks in vimfiles/autoload/RE{,/XML}.vim

            2 advantages to proceed like this :
            - readable.
            - reusable

            For Exemple, the way to match an XML tag is almost a FAQ on this list.
            Why not provide something like the awsome Regexp::Common perl module ?

            I wrote :

            function RE#Magic()
            return '\v'
            endfunction

            function RE#Submatch( regExp )
            return '('.a:regExp.')'
            endfunction

            function RE#OptionnalSubmatch( regExp )
            return '(%('.a:regExp.'){0,1})'
            endfunction

            function RE#XML#Ident()
            return '[[:alpha:]][[:alnum:]]*'
            endfunction

            function RE#XML#NSIdent()
            let ident = RE#XML#Ident()
            " a namespace
            " : separator
            " a tagname
            return
            \ RE#OptionnalSubmatch( ident ) .
            \ RE#OptionnalSubmatch( ':' ) .
            \ RE#OptionnalSubmatch( ident ) .
            endfunction

            Comments and advices about it would be really nice.

            > To use perl regexps, you can of course embed perl statements in a
            > perl-enabled version of Vim; but of course at the cost of making the
            > script less portable.
            I gave this solution away a long time ago. I think that all alien
            langages (langages other than viml) is the worst idea of the vim
            developper team.

            regards
            mc
          Your message has been successfully submitted and would be delivered to recipients shortly.