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

syntax region match with braces

Expand Messages
  • Виктор Кожухаров
    Hello, I m working on a syntax file for .edc files. The problem before me is that I want to use a different syntax file for a script part. I ve created the
    Message 1 of 9 , Oct 31, 2006
    • 0 Attachment
      Hello,

      I'm working on a syntax file for .edc files. The problem before me is
      that I want to use a different syntax file for a "script" part. I've
      created the syntax file for the script syntax, and I've read how yto use
      "syn include".

      The real problem is, that in the .edc files, scripts are located within:
      script {
      SCRIPT HERE
      }
      ,however, the scripts themselves can also have {} braces. I've written
      the following, but it only uncludes the script syntax upto the first "}"
      brace, and I have no idea how to make it end on the _matching_ "}" brace
      instead:

      -----------------------------------------------------------------------
      syn include @edcEmbryo syntax/embryo.vim
      unlet b:current_syntax
      syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
      contains=@edcEmbryo,edcScriptTag
      syn keyword edcScriptTag contained script
      -----------------------------------------------------------------------

      So the question is, if I have:
      script {
      if (foo) {
      bar;
      } else {
      baz;
      }
      }
      how do I make vim use the script syntax all the way up to the closing }
      brace for the "script"?

      --
      Виктор Кожухаров /Viktor Kojouharov/
    • Yakov Lerner
      ... 1. Maybe this can fix the problem: namely, using this inclusion method ... , instead of using syn include . Does this help ? If this won t help, how about
      Message 2 of 9 , Oct 31, 2006
      • 0 Attachment
        On 10/31/06, Виктор Кожухаров <vkojouharov@...> wrote:
        > Hello,
        >
        > I'm working on a syntax file for .edc files. The problem before me is
        > that I want to use a different syntax file for a "script" part. I've
        > created the syntax file for the script syntax, and I've read how yto use
        > "syn include".
        >
        > The real problem is, that in the .edc files, scripts are located within:
        > script {
        > SCRIPT HERE
        > }
        > ,however, the scripts themselves can also have {} braces. I've written
        > the following, but it only uncludes the script syntax upto the first "}"
        > brace, and I have no idea how to make it end on the _matching_ "}" brace
        > instead:
        >
        > -----------------------------------------------------------------------
        > syn include @edcEmbryo syntax/embryo.vim
        > unlet b:current_syntax
        > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
        > contains=@edcEmbryo,edcScriptTag
        > syn keyword edcScriptTag contained script
        > -----------------------------------------------------------------------
        >
        > So the question is, if I have:
        > script {
        > if (foo) {
        > bar;
        > } else {
        > baz;
        > }
        > }
        > how do I make vim use the script syntax all the way up to the closing }
        > brace for the "script"?

        1. Maybe this can fix the problem: namely, using this inclusion method
        mentioned in ':help syn-include' :
        :runtime! syntax/embryo.vim
        :unlet b:current_syntax
        , instead of using 'syn include'. Does this help ?

        If this won't help, how about two less probably possiblities:

        2. Just for the sake of experiment, does the problem go away
        when you modify the 'syn region' to this:

        syn region edcScript start="\<script\>\s*\n*\s*{" end="^}" ...

        I realise this is not the proper final fix, but just to see what makes the
        problem. Without (1) and (2), I think vim
        has egg-and-chicken problem trying to determine where
        @edcEmbryo ends.

        3. Does something change if you comment out the 'syn keyword ... script'
        statement ?
        One less probably suspicion is that that 'keyword script' badly interacts with
        pattern containing 'script' with 'region ... start="\<script\>...
        This seems less probale because you say that beginning of edcScript
        region matches correctly.

        Yakov
      • Peter Hodge
        ... Hello, Your syntax file embryo.vim will need regions match up all {} pairs as well. syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/
        Message 3 of 9 , Oct 31, 2006
        • 0 Attachment
          --- ÐикÑоѬ ÐaожђÑ&аѬов <vkojouharov@...> wrote:

          > Hello,
          >
          > I'm working on a syntax file for .edc files. The problem before me is
          > that I want to use a different syntax file for a "script" part. I've
          > created the syntax file for the script syntax, and I've read how yto use
          > "syn include".
          >
          > The real problem is, that in the .edc files, scripts are located within:
          > script {
          > SCRIPT HERE
          > }
          > ,however, the scripts themselves can also have {} braces. I've written
          > the following, but it only uncludes the script syntax upto the first "}"
          > brace, and I have no idea how to make it end on the _matching_ "}" brace
          > instead:
          >
          > -----------------------------------------------------------------------
          > syn include @edcEmbryo syntax/embryo.vim
          > unlet b:current_syntax
          > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
          > contains=@edcEmbryo,edcScriptTag
          > syn keyword edcScriptTag contained script
          > -----------------------------------------------------------------------
          >
          > So the question is, if I have:
          > script {
          > if (foo) {
          > bar;
          > } else {
          > baz;
          > }
          > }
          > how do I make vim use the script syntax all the way up to the closing }
          > brace for the "script"?

          Hello,

          Your syntax file 'embryo.vim' will need regions match up all {} pairs as well.

          syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/ transparent

          regards,
          Peter


          Send instant messages to your online friends http://au.messenger.yahoo.com
        • Виктор Кожухаров
          ... adding an embryoBraces region now makes all the script part highlighted correctly, but it doesn t stop. It continues trying to highlight the rest of the
          Message 4 of 9 , Oct 31, 2006
          • 0 Attachment
            В ср, 2006-11-01 в 10:53 +1100, Peter Hodge написа:
            > --- ÐикÑоѬ ÐaожђÑ&аѬов <vkojouharov@...> wrote:
            >
            > > Hello,
            > >
            > > I'm working on a syntax file for .edc files. The problem before me is
            > > that I want to use a different syntax file for a "script" part. I've
            > > created the syntax file for the script syntax, and I've read how yto use
            > > "syn include".
            > >
            > > The real problem is, that in the .edc files, scripts are located within:
            > > script {
            > > SCRIPT HERE
            > > }
            > > ,however, the scripts themselves can also have {} braces. I've written
            > > the following, but it only uncludes the script syntax upto the first "}"
            > > brace, and I have no idea how to make it end on the _matching_ "}" brace
            > > instead:
            > >
            > > -----------------------------------------------------------------------
            > > syn include @edcEmbryo syntax/embryo.vim
            > > unlet b:current_syntax
            > > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
            > > contains=@edcEmbryo,edcScriptTag
            > > syn keyword edcScriptTag contained script
            > > -----------------------------------------------------------------------
            > >
            > > So the question is, if I have:
            > > script {
            > > if (foo) {
            > > bar;
            > > } else {
            > > baz;
            > > }
            > > }
            > > how do I make vim use the script syntax all the way up to the closing }
            > > brace for the "script"?
            >
            > Hello,
            >
            > Your syntax file 'embryo.vim' will need regions match up all {} pairs as well.
            >
            > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/ transparent
            >
            > regards,
            > Peter
            >

            adding an embryoBraces region now makes all the script part highlighted
            correctly, but it doesn't stop. It continues trying to highlight the
            rest of the .edc file as if it was an embryo file.

            > 1. Maybe this can fix the problem: namely, using this inclusion method
            > mentioned in ':help syn-include' :
            > :runtime! syntax/embryo.vim
            > :unlet b:current_syntax
            > , instead of using 'syn include'. Does this help ?
            >
            > If this won't help, how about two less probably possiblities:
            >
            > 2. Just for the sake of experiment, does the problem go away
            > when you modify the 'syn region' to this:
            >
            > syn region edcScript start="\<script\>\s*\n*\s*{" end="^}" ...
            >
            > I realise this is not the proper final fix, but just to see what makes the
            > problem. Without (1) and (2), I think vim
            > has egg-and-chicken problem trying to determine where
            > @edcEmbryo ends.
            >
            > 3. Does something change if you comment out the 'syn keyword ... script'
            > statement ?
            > One less probably suspicion is that that 'keyword script' badly interacts with
            > pattern containing 'script' with 'region ... start="\<script\>...
            > This seems less probale because you say that beginning of edcScript
            > region matches correctly.
            >
            > Yakov

            1. I've tried that before. doesn't work, as it breaks everything.
            2. the end } for the script is not neceserily at the beginning of the
            line (and it almost never is)
            3. I don't quite understand that point, but the script start is matched
            correctly.

            >
            > Send instant messages to your online friends http://au.messenger.yahoo.com
            --
            Виктор Кожухаров /Viktor Kojouharov/
          • Виктор Кожухаров
            ... actually, after adding this region, what really happens, is that all the } in the script part are of group Delimeter, including the } for the script
            Message 5 of 9 , Oct 31, 2006
            • 0 Attachment
              В ср, 2006-11-01 в 10:53 +1100, Peter Hodge написа:
              > --- ÐикÑоѬ ÐaожђÑ&аѬов <vkojouharov@...> wrote:
              >
              > > Hello,
              > >
              > > I'm working on a syntax file for .edc files. The problem before me is
              > > that I want to use a different syntax file for a "script" part. I've
              > > created the syntax file for the script syntax, and I've read how yto use
              > > "syn include".
              > >
              > > The real problem is, that in the .edc files, scripts are located within:
              > > script {
              > > SCRIPT HERE
              > > }
              > > ,however, the scripts themselves can also have {} braces. I've written
              > > the following, but it only uncludes the script syntax upto the first "}"
              > > brace, and I have no idea how to make it end on the _matching_ "}" brace
              > > instead:
              > >
              > > -----------------------------------------------------------------------
              > > syn include @edcEmbryo syntax/embryo.vim
              > > unlet b:current_syntax
              > > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
              > > contains=@edcEmbryo,edcScriptTag
              > > syn keyword edcScriptTag contained script
              > > -----------------------------------------------------------------------
              > >
              > > So the question is, if I have:
              > > script {
              > > if (foo) {
              > > bar;
              > > } else {
              > > baz;
              > > }
              > > }
              > > how do I make vim use the script syntax all the way up to the closing }
              > > brace for the "script"?
              >
              > Hello,
              >
              > Your syntax file 'embryo.vim' will need regions match up all {} pairs as well.
              >
              > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/ transparent
              >
              > regards,
              > Peter
              >

              actually, after adding this region, what really happens, is that all the
              '}' in the script part are of group Delimeter, including the '}' for the
              'script {' itself. so, if there's another '}' after that, it becomes of
              region edcScript (even though logically it's out of the script's scope).
              There are times however, where a '}' won't follow the script's own
              closing '}', thus the edcScript region will never end, as I observed in
              the first case.

              >
              > Send instant messages to your online friends http://au.messenger.yahoo.com
              --
              Виктор Кожухаров /Viktor Kojouharov/
            • Peter Hodge
              ... try: syn region edcScript matchgroup=edcScriptTag start=
              Message 6 of 9 , Nov 1, 2006
              • 0 Attachment
                --- Виктор Кожухаров <vkojouharov@...> wrote:

                > В ср, 2006-11-01 в 10:53 +1100, Peter Hodge написа:
                > > --- ÐикÑоѬ ÐaожђÑ&аѬов
                > <vkojouharov@...> wrote:
                > >
                > > > Hello,
                > > >
                > > > I'm working on a syntax file for .edc files. The problem before me is
                > > > that I want to use a different syntax file for a "script" part. I've
                > > > created the syntax file for the script syntax, and I've read how yto use
                > > > "syn include".
                > > >
                > > > The real problem is, that in the .edc files, scripts are located within:
                > > > script {
                > > > SCRIPT HERE
                > > > }
                > > > ,however, the scripts themselves can also have {} braces. I've written
                > > > the following, but it only uncludes the script syntax upto the first "}"
                > > > brace, and I have no idea how to make it end on the _matching_ "}" brace
                > > > instead:
                > > >
                > > > -----------------------------------------------------------------------
                > > > syn include @edcEmbryo syntax/embryo.vim
                > > > unlet b:current_syntax
                > > > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
                > > > contains=@edcEmbryo,edcScriptTag
                > > > syn keyword edcScriptTag contained script
                > > > -----------------------------------------------------------------------
                > > >
                > > > So the question is, if I have:
                > > > script {
                > > > if (foo) {
                > > > bar;
                > > > } else {
                > > > baz;
                > > > }
                > > > }
                > > > how do I make vim use the script syntax all the way up to the closing }
                > > > brace for the "script"?
                > >
                > > Hello,
                > >
                > > Your syntax file 'embryo.vim' will need regions match up all {} pairs as
                > well.
                > >
                > > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/
                > transparent
                > >
                > > regards,
                > > Peter
                > >
                >
                > actually, after adding this region, what really happens, is that all the
                > '}' in the script part are of group Delimeter, including the '}' for the
                > 'script {' itself. so, if there's another '}' after that, it becomes of
                > region edcScript (even though logically it's out of the script's scope).
                > There are times however, where a '}' won't follow the script's own
                > closing '}', thus the edcScript region will never end, as I observed in
                > the first case.

                try:

                syn region edcScript matchgroup=edcScriptTag start="\<script\_s*{" end="}"
                keepend contains=@edcEmbryo

                syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/ transparent
                keepend extend

                I'm not sure if 'transparent' is going to mess things up ... if it does, take
                out 'transparent' and use 'contains=@edcEmbryo'

                regards,
                Peter


                Send instant messages to your online friends http://au.messenger.yahoo.com
              • Виктор Кожухаров
                ... that worked almost perfectly. the only problem now, is that if the script part is too long, if I scroll to where it ends, the edc stuff is not highlighted
                Message 7 of 9 , Nov 1, 2006
                • 0 Attachment
                  В ср, 2006-11-01 в 23:26 +1100, Peter Hodge написа:
                  > --- Виктор Кожухаров <vkojouharov@...> wrote:
                  >
                  > > Ð’ ÑÑ€, 2006-11-01 в 10:53 +1100, Peter Hodge напиÑа:
                  > > > --- ÃøúÑþѬ ÃaþöђÑ&ðѬþò
                  > > <vkojouharov@...> wrote:
                  > > >
                  > > > > Hello,
                  > > > >
                  > > > > I'm working on a syntax file for .edc files. The problem before me is
                  > > > > that I want to use a different syntax file for a "script" part. I've
                  > > > > created the syntax file for the script syntax, and I've read how yto use
                  > > > > "syn include".
                  > > > >
                  > > > > The real problem is, that in the .edc files, scripts are located within:
                  > > > > script {
                  > > > > SCRIPT HERE
                  > > > > }
                  > > > > ,however, the scripts themselves can also have {} braces. I've written
                  > > > > the following, but it only uncludes the script syntax upto the first "}"
                  > > > > brace, and I have no idea how to make it end on the _matching_ "}" brace
                  > > > > instead:
                  > > > >
                  > > > > -----------------------------------------------------------------------
                  > > > > syn include @edcEmbryo syntax/embryo.vim
                  > > > > unlet b:current_syntax
                  > > > > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
                  > > > > contains=@edcEmbryo,edcScriptTag
                  > > > > syn keyword edcScriptTag contained script
                  > > > > -----------------------------------------------------------------------
                  > > > >
                  > > > > So the question is, if I have:
                  > > > > script {
                  > > > > if (foo) {
                  > > > > bar;
                  > > > > } else {
                  > > > > baz;
                  > > > > }
                  > > > > }
                  > > > > how do I make vim use the script syntax all the way up to the closing }
                  > > > > brace for the "script"?
                  > > >
                  > > > Hello,
                  > > >
                  > > > Your syntax file 'embryo.vim' will need regions match up all {} pairs as
                  > > well.
                  > > >
                  > > > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/
                  > > transparent
                  > > >
                  > > > regards,
                  > > > Peter
                  > > >
                  > >
                  > > actually, after adding this region, what really happens, is that all the
                  > > '}' in the script part are of group Delimeter, including the '}' for the
                  > > 'script {' itself. so, if there's another '}' after that, it becomes of
                  > > region edcScript (even though logically it's out of the script's scope).
                  > > There are times however, where a '}' won't follow the script's own
                  > > closing '}', thus the edcScript region will never end, as I observed in
                  > > the first case.
                  >
                  > try:
                  >
                  > syn region edcScript matchgroup=edcScriptTag start="\<script\_s*{" end="}"
                  > keepend contains=@edcEmbryo
                  >
                  > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/ transparent
                  > keepend extend
                  >
                  > I'm not sure if 'transparent' is going to mess things up ... if it does, take
                  > out 'transparent' and use 'contains=@edcEmbryo'
                  >
                  that worked almost perfectly. the only problem now, is that if the
                  script part is too long, if I scroll to where it ends, the edc stuff is
                  not highlighted anymore, untill i reload the file, and if i do, they are
                  highlighted, but I have to scroll up until close to the begining of the
                  script, so that the script itself is highlighted. And for small scripts,
                  even reloading the file doesn't return the .edc highlighting, after the
                  script.

                  I'm not sure why that happens, and out of pure guessing, i'd say it's
                  something to do with syn sync, which I got from other syn files. I have
                  both edc and embryo sync with the following line:
                  syn sync ccomment edc(embryo)Comment minlines=50

                  if I make the minlines too big, edc isn't highlighted after a script
                  even after reload. with a value of 1, it exhibits the above behaviour.

                  > regards,
                  > Peter
                  >
                  >
                  > Send instant messages to your online friends http://au.messenger.yahoo.com
                  --
                  Виктор Кожухаров /Viktor Kojouharov/
                • Peter Hodge
                  Hello, I have the same problem with large PHP files, Vim gets confused in the midst of all the curly braces ... :-S Unfortunately I m not yet familiar with
                  Message 8 of 9 , Nov 1, 2006
                  • 0 Attachment
                    Hello,

                    I have the same problem with large PHP files, Vim gets confused in the midst of
                    all the curly braces ... :-S Unfortunately I'm not yet familiar with the 'syn
                    sync' commands, partly because they're so hard to test.

                    You can use a command like ':syn on' to refresh the syntax, and that should
                    make everything match up properly again. Also, make sure you don't have the
                    'display' option added to the wrong syntax items, that can also mess up
                    matching of { and }.

                    regards,
                    Peter




                    --- Виктор Кожухаров <vkojouharov@...> wrote:

                    > В ср, 2006-11-01 в 23:26 +1100, Peter Hodge написа:
                    > > --- Виктор Кожухаров
                    > <vkojouharov@...> wrote:
                    > >
                    > > > Ð’ ÑÑ€, 2006-11-01 в 10:53 +1100, Peter Hodge
                    > напиÑа:
                    > > > > --- ÃøúÑþѬ
                    > ÃaþöђÑ&ðѬþò
                    > > > <vkojouharov@...> wrote:
                    > > > >
                    > > > > > Hello,
                    > > > > >
                    > > > > > I'm working on a syntax file for .edc files. The problem before me is
                    > > > > > that I want to use a different syntax file for a "script" part. I've
                    > > > > > created the syntax file for the script syntax, and I've read how yto
                    > use
                    > > > > > "syn include".
                    > > > > >
                    > > > > > The real problem is, that in the .edc files, scripts are located
                    > within:
                    > > > > > script {
                    > > > > > SCRIPT HERE
                    > > > > > }
                    > > > > > ,however, the scripts themselves can also have {} braces. I've
                    > written
                    > > > > > the following, but it only uncludes the script syntax upto the first
                    > "}"
                    > > > > > brace, and I have no idea how to make it end on the _matching_ "}"
                    > brace
                    > > > > > instead:
                    > > > > >
                    > > > > >
                    > -----------------------------------------------------------------------
                    > > > > > syn include @edcEmbryo syntax/embryo.vim
                    > > > > > unlet b:current_syntax
                    > > > > > syn region edcScript start="\<script\>\s*\n*\s*{" end="}"
                    > > > > > contains=@edcEmbryo,edcScriptTag
                    > > > > > syn keyword edcScriptTag contained script
                    > > > > >
                    > -----------------------------------------------------------------------
                    > > > > >
                    > > > > > So the question is, if I have:
                    > > > > > script {
                    > > > > > if (foo) {
                    > > > > > bar;
                    > > > > > } else {
                    > > > > > baz;
                    > > > > > }
                    > > > > > }
                    > > > > > how do I make vim use the script syntax all the way up to the closing
                    > }
                    > > > > > brace for the "script"?
                    > > > >
                    > > > > Hello,
                    > > > >
                    > > > > Your syntax file 'embryo.vim' will need regions match up all {} pairs
                    > as
                    > > > well.
                    > > > >
                    > > > > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/
                    > > > transparent
                    > > > >
                    > > > > regards,
                    > > > > Peter
                    > > > >
                    > > >
                    > > > actually, after adding this region, what really happens, is that all the
                    > > > '}' in the script part are of group Delimeter, including the '}' for the
                    > > > 'script {' itself. so, if there's another '}' after that, it becomes of
                    > > > region edcScript (even though logically it's out of the script's scope).
                    > > > There are times however, where a '}' won't follow the script's own
                    > > > closing '}', thus the edcScript region will never end, as I observed in
                    > > > the first case.
                    > >
                    > > try:
                    > >
                    > > syn region edcScript matchgroup=edcScriptTag start="\<script\_s*{"
                    > end="}"
                    > > keepend contains=@edcEmbryo
                    > >
                    > > syn region embryoBraces matchgroup=Delimiter start=/{/ end=/}/
                    > transparent
                    > > keepend extend
                    > >
                    > > I'm not sure if 'transparent' is going to mess things up ... if it does,
                    > take
                    > > out 'transparent' and use 'contains=@edcEmbryo'
                    > >
                    > that worked almost perfectly. the only problem now, is that if the
                    > script part is too long, if I scroll to where it ends, the edc stuff is
                    > not highlighted anymore, untill i reload the file, and if i do, they are
                    > highlighted, but I have to scroll up until close to the begining of the
                    > script, so that the script itself is highlighted. And for small scripts,
                    > even reloading the file doesn't return the .edc highlighting, after the
                    > script.
                    >
                    > I'm not sure why that happens, and out of pure guessing, i'd say it's
                    > something to do with syn sync, which I got from other syn files. I have
                    > both edc and embryo sync with the following line:
                    > syn sync ccomment edc(embryo)Comment minlines=50
                    >
                    > if I make the minlines too big, edc isn't highlighted after a script
                    > even after reload. with a value of 1, it exhibits the above behaviour.
                    >
                    > > regards,
                    > > Peter
                    > >
                    > >
                    > > Send instant messages to your online friends http://au.messenger.yahoo.com
                    > --
                    > Виктор Кожухаров /Viktor Kojouharov/
                    >


                    Send instant messages to your online friends http://au.messenger.yahoo.com
                  • Ilya Sher
                    ... Haven t followed the thread but ... usually works fine for me [snip] -- For robots (please don t mail me there): part-maps@sshoverpci.com My real email is
                    Message 9 of 9 , Nov 1, 2006
                    • 0 Attachment
                      Peter Hodge wrote:
                      > Hello,
                      >
                      > I have the same problem with large PHP files, Vim gets confused in the midst of
                      > all the curly braces ... :-S Unfortunately I'm not yet familiar with the 'syn
                      > sync' commands, partly because they're so hard to test.
                      >
                      Haven't followed the thread but

                      :syntax sync fromstart

                      usually works fine for me

                      [snip]

                      --
                      For robots (please don't mail me there): part-maps@...
                      My real email is ilya @ same domain
                    Your message has been successfully submitted and would be delivered to recipients shortly.