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

how to match a "," that IS NOT in comment

Expand Messages
  • aj3423
    var a = { b: 20, c: 30, //d:45, /*e:70, */ } ... this can match all the 4 commas, how can I exclude the comma in comment(start with // or wrapped in /* */ )?
    Message 1 of 6 , Dec 12, 2009
    • 0 Attachment
      var a = {
      b: 20,
      c: 30,
      //d:45,
      /*e:70,

      */
      }

      :match Error /,/
      this can match all the 4 commas, how can I exclude the comma in
      comment(start with // or wrapped in /* */ )?
      Thanks.

      --
      View this message in context: http://old.nabble.com/how-to-match-a-%22%2C%22-that-IS-NOT-in-comment-tp26756853p26756853.html
      Sent from the Vim - General mailing list archive at Nabble.com.

      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • aj3423
      Oh I found this pattern in vim document ( / /.* ) @
      Message 2 of 6 , Dec 13, 2009
      • 0 Attachment
        Oh I found this pattern in vim document
        \(\/\/.*\)\@<!,
        witch can exclude the comma after "//" , then how to exclude comma wrapped
        in /* */

        --
        View this message in context: http://old.nabble.com/how-to-match-a-%22%2C%22-that-IS-NOT-in-comment-tp26756853p26764606.html
        Sent from the Vim - General mailing list archive at Nabble.com.

        --
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • Gary
        By the fact that you mention :match ... , may I assume you re defining rules in a syntax file? If so, you should be able to do what you want using contained
        Message 3 of 6 , Dec 14, 2009
        • 0 Attachment
          By the fact that you mention ":match ...", may I assume you're
          defining rules in a syntax file?
          If so, you should be able to do what you want using 'contained' --
          i.e., make sure that "match Error" is flagged with "contained", and
          not contained in the comment group, but is contained in other(s);
          possibly using ALLBUT.

          -gary

          On Dec 12, 3:38 am, aj3423 <aj3...@...> wrote:
          > var a = {
          >         b: 20,
          >         c: 30,
          >         //d:45,
          >         /*e:70,
          >
          >         */
          >
          > }
          >
          > :match Error /,/
          > this can match all the 4 commas, how can I exclude the comma in
          > comment(start with // or wrapped in /* */ )?
          > Thanks.
          >
          > --
          > View this message in context:http://old.nabble.com/how-to-match-a-%22%2C%22-that-IS-NOT-in-comment...
          > Sent from the Vim - General mailing list archive at Nabble.com.

          --
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
        • aj3423
          Thanks for your reply. I m trying to write a vim plugin that checks trailing comma for .js file, I m using match Error when the buffer saves, but there ...
          Message 4 of 6 , Dec 14, 2009
          • 0 Attachment
            Thanks for your reply. I'm trying to write a vim plugin that checks trailing
            comma for .js file, I'm using "match Error" when the buffer saves, but there
            is another function in the plugin:
            :vimgrep /the regex/ **/*.js

            so there should be a regex to fit these 2 functions.

            //Brs
            --
            View this message in context: http://old.nabble.com/how-to-match-a-%22%2C%22-that-IS-NOT-in-comment-tp26756853p26785785.html
            Sent from the Vim - General mailing list archive at Nabble.com.

            --
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
          • Tony Mechelynck
            ... The problem here is that there can be any number of lines between /* and */ -- for example, you might have /* at the start of line 1, then a copyright
            Message 5 of 6 , Jan 29, 2010
            • 0 Attachment
              On 15/12/09 03:15, aj3423 wrote:
              >
              > Thanks for your reply. I'm trying to write a vim plugin that checks trailing
              > comma for .js file, I'm using "match Error" when the buffer saves, but there
              > is another function in the plugin:
              > :vimgrep /the regex/ **/*.js
              >
              > so there should be a regex to fit these 2 functions.
              >
              > //Brs

              The problem here is that there can be any number of lines between /* and
              */ -- for example, you might have /* at the start of line 1, then a
              copyright statement and license agreement (in lawyers' English with
              plenty of commas in it), then the closing */ on line 450; or the
              description of a function (in programmers' English this time, but again
              with plenty of commas in it), again occupying any number of lines with
              /* on the first of them and */ on the last.

              I don't see how to search any number of lines backwards and forwards for
              /* and */ (aven assuming that you won't have such niceties as

              function(arg1, "/*", arg2, "*/", arg3)

              where the commas around arg2 are *not* in a comment), unless your script
              can make good use of syntax functions such as synID(), synIDattr() and
              synIDtrans() (q.v.).


              Best regards,
              Tony.
              --
              If this fortune didn't exist, somebody would have invented it.

              --
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
            • Gary
              I don t think it s possible with a regexp (due to the examples given previously). However, inside a function, you should be able to search for a comma, then
              Message 6 of 6 , Feb 1, 2010
              • 0 Attachment
                I don't think it's possible with a regexp (due to the examples given
                previously).
                However, inside a function, you should be able to search for a comma,
                then check to see what syntax group it belongs to; if it's
                "javaComment" (and probably some others) with something like this:

                synIDattr(synID(line("."), col("."), 1), "name")

                -gary

                On Jan 29, 9:14 pm, Tony Mechelynck <antoine.mechely...@...>
                wrote:
                > On 15/12/09 03:15, aj3423 wrote:
                >
                >
                >
                > > Thanks for your reply. I'm trying to write a vim plugin that checks trailing
                > > comma for .js file, I'm using "match Error" when the buffer saves, but there
                > > is another function in the plugin:
                > > :vimgrep /the regex/ **/*.js
                >
                > > so there should be a regex to fit these 2 functions.
                >
                > > //Brs
                >
                > The problem here is that there can be any number of lines between /* and
                > */ -- for example, you might have /* at the start of line 1, then a
                > copyright statement and license agreement (in lawyers' English with
                > plenty of commas in it), then the closing */ on line 450; or the
                > description of a function (in programmers' English this time, but again
                > with plenty of commas in it), again occupying any number of lines with
                > /* on the first of them and */ on the last.
                >
                > I don't see how to search any number of lines backwards and forwards for
                > /* and */ (aven assuming that you won't have such niceties as
                >
                >         function(arg1, "/*", arg2, "*/", arg3)
                >
                > where the commas around arg2 are *not* in a comment), unless your script
                > can make good use of syntax functions such as synID(), synIDattr() and
                > synIDtrans() (q.v.).
                >
                > Best regards,
                > Tony.
                > --
                > If this fortune didn't exist, somebody would have invented it.

                --
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
              Your message has been successfully submitted and would be delivered to recipients shortly.