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

RFC (take 2): External submatches (aka. the here-document trick)

Expand Messages
  • Scott Bigham
    [Well, that took longer than I thought. Catching and storing the external submatches was easy enough, but shepherding them safely through all the syntax
    Message 1 of 2 , Jan 8, 2000
      [Well, that took longer than I thought. Catching and storing the
      external submatches was easy enough, but shepherding them safely
      through all the syntax state stacks without getting them prematurely
      deleted was tricky. Frankly, I'm surprised the previous patch worked
      at all. I think I've got it this time, though; passed all my tests so
      far with flying colors.]

      Here is the latest version of my external submatches patch. Since it's
      been a while, I'll give you the teaser again:

      Sometimes the start and end patterns of a region need to share a
      common sub-expression. A common example is the "here" document in
      Perl and many Unix shells. This effect can be achieved with the |/\z|
      special regular expression atom, which marks a sub-expression as
      "external", in the sense that it can be referenced from outside the
      pattern in which it is defined. The here-document example, for
      instance, can be done like this:
      :syn region hereDoc start="<<\z\(\I\i*\)" end="^\z\1$"

      As can be seen here, the \z atom actually does double duty. In the
      start pattern, it marks the "\(\I\i*\)" sub-expression as external;
      in the end pattern, it changes the \1 back-reference into an external
      reference referring to the first external sub-expression in the start
      pattern. External references can also be used in skip patterns:
      :syn region foo start="start \(\I\i*\)" skip="not end \z\1" end="end \z\1"

      The patch is against a virgin 5.6a; a quick scan through the official
      patches since then didn't turn up any obvious potential conflicts, but I
      can't be sure. Have at it, and let me know if I've broken anything.

      -sbigham
    • Johannes Zellner
      On Sat, 8 Jan 2000, Scott Bigham wrote: [...] ... [...] cool! [...] ... [...] The patch works fine with a 5.6a including patches 1-18 (with some `hunks ). --
      Message 2 of 2 , Jan 9, 2000
        On Sat, 8 Jan 2000, Scott Bigham wrote:

        [...]
        > Here is the latest version of my external submatches patch. Since it's
        > been a while, I'll give you the teaser again:
        [...]
        cool!

        [...]
        > The patch is against a virgin 5.6a; a quick scan through the official
        > patches since then didn't turn up any obvious potential conflicts, but I
        > can't be sure. Have at it, and let me know if I've broken anything.
        [...]
        The patch works fine with a 5.6a including patches 1-18
        (with some `hunks').

        --
        Johannes
      Your message has been successfully submitted and would be delivered to recipients shortly.