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

Re: creating syntax file - syn match problem

Expand Messages
  • Ben Fritz
    On Mar 2, 8:56 am, Tarlika Elisabeth Schmitz ... Good to know, glad it helped. ... Good, you have this already. ... For this, I think you ll need to
    Message 1 of 9 , Mar 2, 2012
      On Mar 2, 8:56 am, Tarlika Elisabeth Schmitz
      <v...@...> wrote:
      >
      > Ben, this works a treat for the examples I posted last night - many
      > thanks.
      >

      Good to know, glad it helped.

      > However, I just realized the code blocks are a little more complex than
      > I thought:
      >
      > a) one-line/inline  code blocks are delimited by a set of 3 curly
      > braces.

      Good, you have this already.

      > b) multi-line blocks
      >  - are delimited by any number of braces (min 3)

      For this, I think you'll need to compromise and select some maximum
      number of braces to allow highlighting for. You could even make this
      configurable if you use a loop to build a bunch of similar rules
      starting at 4 braces (you get 3 from your existing definition for
      free).

      >  - the code may contain sets of curly braces (they don't need to match)

      I'm not sure what you mean by this. Are you saying {{{ does not always
      start a code block? If so, you'll need to figure out the "real" start
      of a code block and somehow key off of that, possibly using nextgroup.

      >  - the block is closed by the first set of braces that contains the same
      >    number of braces as the opening set

      This makes sense. But can blocks with the same number of braces nest?
      Can groups overlap, e.g. is this valid?

      begin block1 {{{
      code
      begin block2 {{{{
      end block1 }}}
      end block2 }}}}

      If so, I don't think Vim can highlight it. At least, not easily.

      >  - the first code line must be on a new line (not on the same line as
      > the opening braces)
      >

      That should be easy enough with a negative look-ahead assertion (using
      the \@! zero-width match). Just make sure there's nothing but
      whitespace until the end of the line in the start pattern of your
      syntax region.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tarlika Elisabeth Schmitz
      On Fri, 2 Mar 2012 09:24:28 -0800 (PST) ... I can happily settle for 4. ... correct. {{{ does not start a code block if it is inside a code block. Curly braces
      Message 2 of 9 , Mar 2, 2012
        On Fri, 2 Mar 2012 09:24:28 -0800 (PST)
        Ben Fritz <fritzophrenic@...> wrote:

        >> b) multi-line blocks
        >>  - are delimited by any number of braces (min 3)
        >
        >For this, I think you'll need to compromise and select some maximum
        >number of braces to allow highlighting for.

        I can happily settle for 4.

        >>  - the code may contain sets of curly braces (they don't need to
        >> match)
        >
        >I'm not sure what you mean by this. Are you saying {{{ does not always
        >start a code block?

        correct. {{{ does not start a code block if it is inside a code block.
        Curly braces inside a code block are just text.

        >>  - the block is closed by the first set of braces that contains the
        >> same number of braces as the opening set
        >
        >This makes sense. But can blocks with the same number of braces nest?
        >Can groups overlap, e.g. is this valid?
        >
        >begin block1 {{{
        >code
        >begin block2 {{{{
        >end block1 }}}
        >end block2 }}}}

        There is no overlapping. Here, the first set of braces {{{ starts a
        code block, which is terminated by }}}. The text enclosed between those
        two sets of braces is "code". "end block2 }}}}" has no meaning and
        should remain uncoloured.

        Therefore, I would like {{{ and }}} to be highlighted blue and the text
        inbetween green.


        --
        Tarlika

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Tarlika Elisabeth Schmitz
        On Fri, 2 Mar 2012 18:36:26 +0000 ... This virtually does what I want: syn region xyzCode matchgroup=xyzCodeMark start= {{{ end= }}} syn region xyzCode
        Message 3 of 9 , Mar 4, 2012
          On Fri, 2 Mar 2012 18:36:26 +0000
          Tarlika Elisabeth Schmitz <vim@...> wrote:

          >On Fri, 2 Mar 2012 09:24:28 -0800 (PST)
          >Ben Fritz <fritzophrenic@...> wrote:
          >
          >>> b) multi-line blocks
          >>>  - are delimited by any number of braces (min 3)
          >>
          >>For this, I think you'll need to compromise and select some maximum
          >>number of braces to allow highlighting for.
          >
          >I can happily settle for 4.
          >
          >>>  - the code may contain sets of curly braces (they don't need to
          >>> match)
          >>
          >>I'm not sure what you mean by this. Are you saying {{{ does not always
          >>start a code block?
          >
          >correct. {{{ does not start a code block if it is inside a code block.
          >Curly braces inside a code block are just text.
          >
          >>>  - the block is closed by the first set of braces that contains the
          >>> same number of braces as the opening set
          >>
          >>This makes sense. But can blocks with the same number of braces nest?
          >>[...]
          >
          >Therefore, I would like {{{ and }}} to be highlighted blue and the text
          >inbetween green.

          This virtually does what I want:

          syn region xyzCode matchgroup=xyzCodeMark start='{{{' end='}}}'
          syn region xyzCode matchgroup=xyzCodeMark start='{{{{' end='}}}}'

          with one exception:
          When the code block is started with more than 3 braces, the opening set
          of braces must be followed by [spaces] and a new line. The code has to
          be placed on the next line. The closing braces can be on the same line
          as the last code.

          --

          Best Regards,
          Tarlika Elisabeth Schmitz



          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Ben Fritz
          On Mar 4, 10:55 am, Tarlika Elisabeth Schmitz ... As I suggested before, use a zero-width match, or even better a ze: syn region xyzCode
          Message 4 of 9 , Mar 5, 2012
            On Mar 4, 10:55 am, Tarlika Elisabeth Schmitz
            <v...@...> wrote:
            >
            > This virtually does what I want:
            >
            > syn region  xyzCode matchgroup=xyzCodeMark start='{{{' end='}}}'
            > syn region  xyzCode matchgroup=xyzCodeMark start='{{{{' end='}}}}'
            >
            > with one exception:
            > When the code block is started with more than 3 braces, the opening set
            > of braces must be followed by [spaces] and a new line. The code has to
            > be placed on the next line. The closing braces can be on the same line
            > as the last code.
            >

            As I suggested before, use a zero-width match, or even better a \ze:

            syn region xyzCode matchgroup=xyzCodeMark start='{{{{\ze\s*$'
            end='}}}}'

            :he /\ze
            :he zero-width (not used but it could have been)

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Tarlika Elisabeth Schmitz
            On Mon, 5 Mar 2012 07:49:50 -0800 (PST) ... That s great, got that working, also thanks for the help links. Now, I have been trying to match another, more
            Message 5 of 9 , Mar 5, 2012
              On Mon, 5 Mar 2012 07:49:50 -0800 (PST)
              Ben Fritz <fritzophrenic@...> wrote:

              >> This virtually does what I want:
              >>
              >> syn region  xyzCode matchgroup=xyzCodeMark start='{{{' end='}}}'
              >> syn region  xyzCode matchgroup=xyzCodeMark start='{{{{' end='}}}}'
              >>
              >> with one exception:
              >> When the code block is started with more than 3 braces, the opening
              >> set of braces must be followed by [spaces] and a new line.
              >
              >syn region xyzCode matchgroup=xyzCodeMark start='{{{{\ze\s*$'
              >end='}}}}'

              That's great, got that working, also thanks for the help links.

              Now, I have been trying to match another, more complex
              pattern but I don't know how to tackle it:


              [[foo:sometext|somename|someoption]]

              Not all of the elements are necessarily present.
              I would like to colour teach text element differently and the markup
              [[ : | | ]] in blue.

              foo: is optional
              | somename is optional
              | someoption is optional


              Is this a case for nextgroup?


              --

              Best Regards,
              Tarlika Elisabeth Schmitz

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Ben Fritz
              On Mar 5, 7:06 pm, Tarlika Elisabeth Schmitz ... I d probably define a region from [[ to ]]. Depending on what the syntax actually is, you might be able to
              Message 6 of 9 , Mar 6, 2012
                On Mar 5, 7:06 pm, Tarlika Elisabeth Schmitz
                <v...@...> wrote:
                > On Mon, 5 Mar 2012 07:49:50 -0800 (PST)
                >
                > Ben Fritz <fritzophre...@...> wrote:
                > >> This virtually does what I want:
                >
                > >> syn region  xyzCode matchgroup=xyzCodeMark start='{{{' end='}}}'
                > >> syn region  xyzCode matchgroup=xyzCodeMark start='{{{{' end='}}}}'
                >
                > >> with one exception:
                > >> When the code block is started with more than 3 braces, the opening
                > >> set of braces must be followed by [spaces] and a new line.
                >
                > >syn region  xyzCode matchgroup=xyzCodeMark start='{{{{\ze\s*$'
                > >end='}}}}'
                >
                > That's great, got that working, also thanks for the help links.
                >
                > Now, I have  been trying to match another, more complex
                > pattern but I don't know how to tackle it:
                >
                > [[foo:sometext|somename|someoption]]
                >
                > Not all of the elements are necessarily present.
                > I would like to colour teach text element differently and the markup
                > [[ : | | ]] in blue.
                >
                > foo: is optional
                > | somename is optional
                > | someoption is optional
                >
                > Is this a case for nextgroup?
                >

                I'd probably define a region from [[ to ]]. Depending on what the
                syntax actually is, you might be able to get away with just creating
                some contained groups and adding them to the contains= of the region.
                But nextgroup can be very useful, especially if the items need to come
                in some defined order.

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              Your message has been successfully submitted and would be delivered to recipients shortly.