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

Re: Using + in Perl embedded in Vim functions

Expand Messages
  • 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 1 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 2 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 3 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 4 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.