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

Using + in Perl embedded in Vim functions

Expand Messages
  • Colin Keith
    Okay this is really stupid and I can t fathom what causes this. It seems that the Vim parser gets upset at the presence of + symbols in Perl blocks. Strangely
    Message 1 of 5 , Sep 2, 2002
    • 0 Attachment
      Okay this is really stupid and I can't fathom what causes this. It seems
      that the Vim parser gets upset at the presence of + symbols in Perl blocks.
      Strangely it only does it if they're in a function though. I.e.


      This works as expected:

      perl <<EOF
      my $i = 0;
      $i++;
      VIM::Msg("i = $i");
      EOF

      This causes the parser to fall over and claim that there is no endfunction.

      function! Test()
      perl <<EOF
      my $i = 0;
      $i++;
      VIM::Msg("i = $i");
      EOF
      endfunction


      $i+=1 causes the same error message.

      What is even stranger is that if you enclose your variable names in braces,
      it works fine:

      function! Test()
      perl <<EOF
      my $i = 1;
      ${i}++;
      VIM::Msg("i = $i");
      EOF
      endfunction


      ... having just worked out the answer myself I don't need to ask for an
      answer, but if anyone has any ideas why this happens I'd be interested to
      hear them.

      Tested on gvim/win32 v6.1 (2002 Mar 24) and vim 6.1.154 on unix (freebsd
      and linux) compiled against Perl versions 5.6.1 and 5.00503 on unix and I
      think the Win32 binaries use perl 5.6.1 as well.

      Col.


      --
      First Name: Colin, one 'ell', not two. Increase your font size if you
      thought it had two. Pronounced: Col-in, not Cooo-lin
      Surname: Keith. Yes surname, not forename. Its the name of a Scottish clan
      that once owned half of Scotland...
    • Bram Moolenaar
      ... The code that checks for the endfunction doesn t know about Perl commands. It recognizes the $i as the start of an :insert command on the last line.
      Message 2 of 5 , Sep 2, 2002
      • 0 Attachment
        Colin Keith wrote:

        > Okay this is really stupid and I can't fathom what causes this. It seems
        > that the Vim parser gets upset at the presence of + symbols in Perl blocks.
        > Strangely it only does it if they're in a function though. I.e.
        >
        >
        > This works as expected:
        >
        > perl <<EOF
        > my $i = 0;
        > $i++;
        > VIM::Msg("i = $i");
        > EOF
        >
        > This causes the parser to fall over and claim that there is no endfunction.
        >
        > function! Test()
        > perl <<EOF
        > my $i = 0;
        > $i++;
        > VIM::Msg("i = $i");
        > EOF
        > endfunction
        >
        >
        > $i+=1 causes the same error message.

        The code that checks for the "endfunction" doesn't know about Perl
        commands. It recognizes the "$i" as the start of an ":insert" command
        on the last line. This continues until a "." on a line by itself. This
        is accepted (although the Perl code won't work):

        function! Test()
        perl <<EOF
        my $i = 0;
        $i++;
        VIM::Msg("i = $i");
        .
        EOF
        endfunction

        > What is even stranger is that if you enclose your variable names in braces,
        > it works fine:
        >
        > function! Test()
        > perl <<EOF
        > my $i = 1;
        > ${i}++;
        > VIM::Msg("i = $i");
        > EOF
        > endfunction

        "${i" is not a recognized command.

        Recognizing these Perl commands and skipping them would be possible, but
        it also should be implemented for other languages then.

        --
        [clop clop]
        ARTHUR: Old woman!
        DENNIS: Man!
        ARTHUR: Man, sorry. What knight lives in that castle over there?
        DENNIS: I'm thirty seven.
        ARTHUR: What?
        DENNIS: I'm thirty seven -- I'm not old!
        The Quest for the Holy Grail (Monty Python)

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
        \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
        \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
      • Colin Keith
        ... Ahhh. I assumed that when it saw a perl command (even if its a
        Message 3 of 5 , Sep 2, 2002
        • 0 Attachment
          On Mon, Sep 02, 2002 at 09:10:36PM +0200, Bram Moolenaar wrote:
          > The code that checks for the "endfunction" doesn't know about Perl
          > commands. It recognizes the "$i" as the start of an ":insert" command
          > on the last line. This continues until a "." on a line by itself. This


          Ahhh. I assumed that when it saw a perl command (even if its a << block)
          it would just skip it. That makes complete sense though. I guess its also a
          side effect of having crappy variable names like $i and $a :)

          Thanks.

          Colin.
        • Benji Fisher
          ... Wouldn t it be simpler (and less language-specific) for the Vim parser to ignore everything from perl
          Message 4 of 5 , Sep 2, 2002
          • 0 Attachment
            Bram Moolenaar wrote:
            >
            > The code that checks for the "endfunction" doesn't know about Perl
            > commands. It recognizes the "$i" as the start of an ":insert" command
            > on the last line. This continues until a "." on a line by itself. This
            > is accepted (although the Perl code won't work):
            >
            > function! Test()
            > perl <<EOF
            > my $i = 0;
            > $i++;
            > VIM::Msg("i = $i");
            > .
            > EOF
            > endfunction
            >
            > Recognizing these Perl commands and skipping them would be possible, but
            > it also should be implemented for other languages then.

            Wouldn't it be simpler (and less language-specific) for the Vim parser to
            ignore everything from "perl <<EOF" to "EOF"? To the uneducated (me) it does
            not seem any more complicated than ignoring everything from "$i" to ".".

            HTH --Benji Fisher
          • Bram Moolenaar
            ... Yeah, but this requires the code to check for the
            Message 5 of 5 , Sep 3, 2002
            • 0 Attachment
              Benji Fisher wrote:

              > Bram Moolenaar wrote:
              > >
              > > The code that checks for the "endfunction" doesn't know about Perl
              > > commands. It recognizes the "$i" as the start of an ":insert" command
              > > on the last line. This continues until a "." on a line by itself. This
              > > is accepted (although the Perl code won't work):
              > >
              > > function! Test()
              > > perl <<EOF
              > > my $i = 0;
              > > $i++;
              > > VIM::Msg("i = $i");
              > > .
              > > EOF
              > > endfunction
              > >
              > > Recognizing these Perl commands and skipping them would be possible, but
              > > it also should be implemented for other languages then.
              >
              > Wouldn't it be simpler (and less language-specific) for the Vim
              > parser to ignore everything from "perl <<EOF" to "EOF"? To the
              > uneducated (me) it does not seem any more complicated than ignoring
              > everything from "$i" to ".".

              Yeah, but this requires the code to check for the "<<EOF". It just
              isn't there yet. Note that the "EOF" could be something else.

              --
              A mathematician is a device for turning coffee into theorems.
              Paul Erdos
              A computer programmer is a device for turning coffee into bugs.
              Bram Moolenaar

              /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
              /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
              \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
              \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
            Your message has been successfully submitted and would be delivered to recipients shortly.