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

Re: Patterns, variables and strange behavior of some thing.

Expand Messages
  • Stahlman Family
    ... Jojahti, I believe you may have uncovered a bug. It can be demonstrated with an even simpler example... (i (. ) ) @
    Message 1 of 12 , Jan 1, 2010
      jojahti wrote:
      > I have tried write highligting pattern, than search variables.
      > "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@
      > ="
      >
      > Then the pattern, that search this variable in other places of the file.
      > "\(\(int\|long\|short\|char\|void\|double\)\([[:space:]]\+\)\([^[:space:]^(^).]\+\)[[:sp
      > ace:]].*\)\@<=\4"
      > But fail.
      >
      > I see, that this thing have very strange behavior.
      > I have made little experiment/
      > I make this string:
      > oo ib b oooooooooo
      >
      > And try serch in it, using this pattern:
      > '\(i\(.\)[[:space:]]*\)\@<=/2'
      > And now i have fail.
      > But if i cut '\@<=' - then all work normal.
      > But I need to use these things.

      Jojahti,
      I believe you may have uncovered a bug. It can be demonstrated with an
      even simpler example...
      \(i\(.\)\)\@<=\2
      ...which will match just after an i followed by any character, even when
      the character following the i is not repeated: e.g., on the following
      line...
      iax ibx ic
      ...the pattern above matches 3 times: on the 2 x's and at the end of the
      line. It shouldn't match at all, since the character captured by the 2nd
      \( ... \) is never repeated.

      It appears to me that the back-reference within the \( ... \)\@<= is
      being cleared when the construct is exited. Since a cleared (empty)
      backreference matches anywhere, the pattern doesn't work as expected.

      To test my theory, I tried moving the \2 inside the \( ... \)\@<= and
      found that it worked as expected:
      \(i\(.\)[[:space:]]*\2\)\@<=

      It's just a hunch, but I suspect that the following thread may be relevant:
      http://old.nabble.com/Subject:-Apparent-regex-bug:-overlapping-text-captured-by-non-overlapping-backrefs-td15945426.html

      Note that as a result of that thread, Bram implemented a fix that caused
      backreferences to be cleared upon backtracking. Perhaps the fix results
      in backreferences sometimes being cleared when they shouldn't be. Just a
      guess...

      Brett Stahlman

      >
      > Why behavior of it is so strange? How to me complete my quest the most
      > adequate way?
      >
      > P.S. it's my first post in English. :thinking:
      > Forums on my native language, where I can ask this question - about zero.
      >
      >

      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... Not a bug, unless I misunderstand. From :help / @
      Message 2 of 12 , Jan 1, 2010
        On Jan 1, 12:28 pm, Stahlman Family <brettstahl...@...> wrote:
        > I believe you may have uncovered a bug. It can be demonstrated with an
        > even simpler example...
        > \(i\(.\)\)\@<=\2
        > ...which will match just after an i followed by any character, even when
        > the character following the i is not repeated: e.g., on the following
        > line...
        > iax ibx ic

        Not a bug, unless I misunderstand. From :help /\@<= you can see:

        The part of the pattern after "\@<=" and "\@<!" are checked for a
        match first, thus things like "\1" don't work to reference \(\)
        inside
        the preceding atom. It does work the other way around:
        Example matches ~
        \1\@<=,\([a-z]\+\) ",abc" in "abc,abc"

        It's documented, which makes it a "quirk" instead :-P

        --
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • Stahlman Family
        ... So it is. I hadn t seen that. So it appears to be a feature, not a bug. Thanks, Brett Stahlman ... -- You received this message from the vim_use
        Message 3 of 12 , Jan 1, 2010
          Ben Fritz wrote:
          >
          > On Jan 1, 12:28 pm, Stahlman Family <brettstahl...@...> wrote:
          >> I believe you may have uncovered a bug. It can be demonstrated with an
          >> even simpler example...
          >> \(i\(.\)\)\@<=\2
          >> ...which will match just after an i followed by any character, even when
          >> the character following the i is not repeated: e.g., on the following
          >> line...
          >> iax ibx ic
          >
          > Not a bug, unless I misunderstand. From :help /\@<= you can see:
          >
          > The part of the pattern after "\@<=" and "\@<!" are checked for a
          > match first, thus things like "\1" don't work to reference \(\)
          > inside
          > the preceding atom. It does work the other way around:
          > Example matches ~
          > \1\@<=,\([a-z]\+\) ",abc" in "abc,abc"
          >
          > It's documented, which makes it a "quirk" instead :-P

          So it is. I hadn't seen that. So it appears to be a feature, not a bug.

          Thanks,
          Brett Stahlman

          >

          --
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
        • Stahlman Family
          ... Jojahti, There s a better way to do what you re trying to do, which uses zs instead of @
          Message 4 of 12 , Jan 2, 2010
            jojahti wrote:
            > I have tried write highligting pattern, than search variables.
            > "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@
            > ="
            >
            > Then the pattern, that search this variable in other places of the file.
            > "\(\(int\|long\|short\|char\|void\|double\)\([[:space:]]\+\)\([^[:space:]^(^).]\+\)[[:sp
            > ace:]].*\)\@<=\4"
            > But fail.
            >
            > I see, that this thing have very strange behavior.
            > I have made little experiment/
            > I make this string:
            > oo ib b oooooooooo
            >
            > And try serch in it, using this pattern:
            > '\(i\(.\)[[:space:]]*\)\@<=/2'
            > And now i have fail.
            > But if i cut '\@<=' - then all work normal.
            > But I need to use these things.

            Jojahti,
            There's a better way to do what you're trying to do, which uses \zs
            instead of \@<=.

            :help \zs

            As Ben Fritz pointed out, the pattern within...
            \( ... \)\@<=
            ...is tried only *after* the actual pattern is matched; i.e., too late
            for the submatches contained by the lookbehind to be used in the actual
            pattern. But what if you changed the pattern above to the following?

            \(i\(.\)[[:space:]]*\)\zs\2

            The \zs ensures that the match begins at the character matched by \2;
            the difference between this and the original pattern is that the portion
            of the pattern before the \zs is tried *first* (as it really must be if
            the \2 backreference is to be useful).

            Out of curiosity, what are you trying to match with [^[:space:]^(^).]?

            Thanks,
            Brett Stahlman



            >
            > Why behavior of it is so strange? How to me complete my quest the most
            > adequate way?


            >
            > P.S. it's my first post in English. :thinking:
            > Forums on my native language, where I can ask this question - about zero.
            >
            >

            --
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
          • Stahlman Family
            ... Now I m confused as to what you re actually attempting to do... The wording above makes it sound as though you re trying to extract a variable name from a
            Message 5 of 12 , Jan 2, 2010
              Stahlman Family wrote:
              >
              > jojahti wrote:
              >> I have tried write highligting pattern, than search variables.
              >> "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@
              >> ="
              >>
              >> Then the pattern, that search this variable in other places of the file.
              >> "\(\(int\|long\|short\|char\|void\|double\)\([[:space:]]\+\)\([^[:space:]^(^).]\+\)[[:sp
              >> ace:]].*\)\@<=\4"
              >> But fail.

              Now I'm confused as to what you're actually attempting to do... The
              wording above makes it sound as though you're trying to extract a
              variable name from a declaration with one pattern, then find its usage
              later in the file with another pattern. The patterns themselves,
              however, aren't consistent with this interpretation, as both match the
              variable type. Perhaps it would help if you clarified exactly how you're
              using the 2 patterns above...

              Thanks,
              Brett Stahlman

              >>
              >> I see, that this thing have very strange behavior.
              >> I have made little experiment/
              >> I make this string:
              >> oo ib b oooooooooo
              >>
              >> And try serch in it, using this pattern:
              >> '\(i\(.\)[[:space:]]*\)\@<=/2'
              >> And now i have fail.
              >> But if i cut '\@<=' - then all work normal.
              >> But I need to use these things.
              >
              > Jojahti,
              > There's a better way to do what you're trying to do, which uses \zs
              > instead of \@<=.
              >
              > :help \zs
              >
              > As Ben Fritz pointed out, the pattern within...
              > \( ... \)\@<=
              > ...is tried only *after* the actual pattern is matched; i.e., too late
              > for the submatches contained by the lookbehind to be used in the actual
              > pattern. But what if you changed the pattern above to the following?
              >
              > \(i\(.\)[[:space:]]*\)\zs\2
              >
              > The \zs ensures that the match begins at the character matched by \2;
              > the difference between this and the original pattern is that the portion
              > of the pattern before the \zs is tried *first* (as it really must be if
              > the \2 backreference is to be useful).
              >
              > Out of curiosity, what are you trying to match with [^[:space:]^(^).]?
              >
              > Thanks,
              > Brett Stahlman
              >
              >
              >
              >>
              >> Why behavior of it is so strange? How to me complete my quest the most
              >> adequate way?
              >
              >
              >>
              >> P.S. it's my first post in English. :thinking:
              >> Forums on my native language, where I can ask this question - about zero.
              >>
              >>
              >

              --
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
            • jojahti
              ... Thanks. Mmmm. But if i use zs instead @
              Message 6 of 12 , Jan 2, 2010
                >There's a better way to do what you're trying to do, which uses \zs
                >instead of \@<=.
                Thanks.
                Mmmm. But if i use "\zs" instead "\@<=" in next example - he not work at
                all.
                "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@="

                But in litle experimental examples this work. But I with it will experiment
                with it.

                >Out of curiosity, what are you trying to match with [^[:space:]^(^).]?
                Word, which does not contained "( )". I finding a variables, but not
                functions, and declarations of classes.
                "int frog" - it will be found. "int frog()" - it will be not found.

                >Now I'm confused as to what you're actually attempting to do...
                I not so understand programming, I study him likely.
                Now i simply learn to work in the editor of a code, and try to do my own
                syntax highlighting.
                In this stage - i try make variables highlighting.

                "(type (name_variables)some_simvols)\@<=(\2)"

                As it not were correctly work in the next example.(this can find only one
                simvols of the word )), but in this variant the example looks easier, and it
                is not similar to spells of severe northern mammoths.)
                string " int d ii iiii ii d"
                pattern '\(int[[:space:]]\+\([^[:space:]]\+\).*\)\zs\2'

                P.S. And one little question.
                This string "oooooooBBoooooooBoooo"
                And patterne '\(B\)\=\1'
                Why this patterne not work? :WALL:
                This is too quirk? )
                --
                View this message in context: http://old.nabble.com/Patterns%2C-variables-and-strange-behavior-of-some-thing.-tp26986520p26994865.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
              • Stahlman Family
                ... Note that the first ^ within the [ ... ] complements the collection; the others are matched literally. If I understand correctly what you re trying to do,
                Message 7 of 12 , Jan 2, 2010
                  jojahti wrote:
                  >> There's a better way to do what you're trying to do, which uses \zs
                  >> instead of \@<=.
                  > Thanks.
                  > Mmmm. But if i use "\zs" instead "\@<=" in next example - he not work at
                  > all.
                  > "\(\(int\|long\|short\|char\|void\|double\)[[:space:]]\+\)\@<=[^[:space:]^(^).]\+\([[:space:]]\)\@="
                  >
                  > But in litle experimental examples this work. But I with it will experiment
                  > with it.
                  >
                  >> Out of curiosity, what are you trying to match with [^[:space:]^(^).]?
                  > Word, which does not contained "( )". I finding a variables, but not
                  > functions, and declarations of classes.
                  > "int frog" - it will be found. "int frog()" - it will be not found.

                  Note that the first ^ within the [ ... ] complements the collection; the
                  others are matched literally. If I understand correctly what you're
                  trying to do, the collection should be defined like this: [^[:space:]().]

                  >
                  >> Now I'm confused as to what you're actually attempting to do...
                  > I not so understand programming, I study him likely.
                  > Now i simply learn to work in the editor of a code, and try to do my own
                  > syntax highlighting.
                  > In this stage - i try make variables highlighting.
                  >
                  > "(type (name_variables)some_simvols)\@<=(\2)"
                  >
                  > As it not were correctly work in the next example.(this can find only one
                  > simvols of the word )), but in this variant the example looks easier, and it
                  > is not similar to spells of severe northern mammoths.)
                  > string " int d ii iiii ii d"
                  > pattern '\(int[[:space:]]\+\([^[:space:]]\+\).*\)\zs\2'
                  >
                  > P.S. And one little question.
                  > This string "oooooooBBoooooooBoooo"
                  > And patterne '\(B\)\=\1'
                  > Why this patterne not work? :WALL:

                  It does work, but it's rather pointless because it matches everywhere.
                  It will match a B followed by another B, but it will also match the
                  empty string, since the \= makes the match with the B optional. Recall
                  that \= matches 0 or 1 of the preceding atom. In your example, when the
                  match is attempted at one of the o's, it succeeds as follows...

                  the B matches 0 times
                  \1 is empty and hence it matches also (since an empty pattern matches
                  everywhere)

                  Brett Stahlman

                  > This is too quirk? )

                  --
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                • jojahti
                  Ааа, has understood. Value of a variable to equally found expression, and not condition? -- View this message in context:
                  Message 8 of 12 , Jan 2, 2010
                    Ааа, has understood. Value of a variable to equally found expression, and not
                    condition?
                    --
                    View this message in context: http://old.nabble.com/Patterns%2C-variables-and-strange-behavior-of-some-thing.-tp26986520p26995295.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
                  • Ben Fritz
                    ... Is there a particular reason you feel the need to make your own syntax highlighting rules? Vim has syntax highlighting defined already for most common
                    Message 9 of 12 , Jan 3, 2010
                      On Jan 2, 11:31 am, jojahti <joja...@...> wrote:
                      > Now i simply learn to work in the editor of a code, and try to do my own
                      > syntax highlighting.

                      Is there a particular reason you feel the need to make your own syntax
                      highlighting rules? Vim has syntax highlighting defined already for
                      most common programming languages. What are you trying to highlight
                      that you need to make up your own rules? Is this something you could
                      share with others once you figure it out?

                      --
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                    • jojahti
                      I so understand that I should generate dynamically filling highlighting groups . For example i have this string: [b]int aa, bb, cc, zz, ee; [ b] And this
                      Message 10 of 12 , Jan 4, 2010
                        I so understand that I should generate dynamically filling highlighting
                        groups .


                        For example i have this string:
                        [b]int aa, bb, cc, zz, ee;
                        [\b]
                        And this pattern:
                        [b]'\(\(int\)\([[:space:]]\+[^[:space:](),;]\+[,]\)\=[[:space:]]\+\)\zs[^[:space:](),;=]\+'[/b]
                        But witch's him i can find only one variables name of some those. Because,
                        that's i mean, two copies of the found expressions cannot begin with the one
                        symbols. It's that?

                        Can i give all variables name from string, of the these vid, which help of
                        only one pattern? And how?



                        >Is there a particular reason you feel the need to make your own syntax
                        >highlighting rules? Vim has syntax highlighting defined already for
                        >most common programming languages. What are you trying to highlight
                        >that you need to make up your own rules?
                        Vim is code editor - constructor.
                        It means that I can make with code editing that, that i want. Or my be my
                        idea not good.
                        Simpe I want create small changed, such as variable highlighting.

                        >Is this something you could share with others once you figure it out?
                        Or my be I have incorrect understood of forum orientation. :blush:
                        --
                        View this message in context: http://old.nabble.com/Patterns%2C-variables-and-strange-behavior-of-some-thing.-tp26986520p27012654.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
                        On 01/01/10 17:42, jojahti wrote: [...] ... Well, I could see that English wasn t your native language; at least you ve made a mighty effort. :-) (I snipped
                        Message 11 of 12 , Mar 6, 2010
                          On 01/01/10 17:42, jojahti wrote:
                          [...]
                          > P.S. it's my first post in English. :thinking:
                          > Forums on my native language, where I can ask this question - about zero.

                          Well, I could see that English wasn't your native language; at least
                          you've made a mighty effort. :-) (I snipped the question because I don't
                          think I can contribute something of value to the answer.)

                          Seeing that you're posting from a .ru address, but with a name which is
                          far from typically Russian, I think that on this list a post in Russian
                          might or might not get an appropriate answer, but it would certainly
                          irritate many non-Russian-speaking regulars; as for Estonian, maybe some
                          vim-list posters (other than you) understands it, but I wouldn't bet on
                          it. Welcome anyway.

                          Best regards,
                          Tony.
                          --
                          "Gee, Mudhead, everyone at More Science High has an
                          extracurricular activity except you."
                          "Well, gee, doesn't Louise count?"
                          "Only to ten, Mudhead."

                          -- Firesign Theater

                          --
                          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.