Change needed in cobol.vim syntax file.

427 views
Skip to first unread message

john Culleton

unread,
Feb 13, 2012, 7:02:56 PM2/13/12
to vim_use
In the cobol.vim file, something causes all sentences starting
with "if" to be colored red just like an error. The "if" verb is
perfectly legitimate in COBOL, I have used it since 1968.

Will someone who reads and understands vim files please tell me
which line or lines to change? The way it is now I am forced to
turn off syntax checking just to read/edit the file in Gvim.

--
John Culleton
Free list of books for self-publishers:
http://wexfordpress.net/shortlist.html

"Create Book Covers with Scribus"
http://www.booklocker.com/books/4055.html

Andrew Long

unread,
Feb 14, 2012, 3:43:28 AM2/14/12
to vim...@googlegroups.com

On 14 Feb 2012, at 00:02, john Culleton wrote:

> In the cobol.vim file, something causes all sentences starting
> with "if" to be colored red just like an error. The "if" verb is
> perfectly legitimate in COBOL, I have used it since 1968.

I haven't been using it for *quire* that long, but I agree with you that it is perfectly legal!

I have had odd syntax colouring in COBOL files at beginning of lines on occasion, but it always turns out to be the presence of a 'tab' character instead of leading spaces that makes text that *looks* like it is in column 12 actually start to the left of that, in area A, or even in the line number field.

Not saying that is your problem here, but it's worth a look.

Regards, Andy

--
Andrew Long
andrew dot long at mac dot com

PGP.sig

john Culleton

unread,
Feb 14, 2012, 11:59:49 AM2/14/12
to vim...@googlegroups.com

Thanks for your reply. I don't use tabs when writing COBOL for
just that reason. It is only the reserved word "IF" or "if" that causes
the problem. I understand that there was an improved syntax file
from a site belonging to Sitaram but that seems to have been
taken over by someone selling insurance.

I can try hacking the existing cobol.vim file but I don't know
the intricacies of vim syntax files. I thought someone here could
help.

I'll try writing Tim Pope.

John Little

unread,
Feb 14, 2012, 6:39:01 PM2/14/12
to vim_use
On Feb 14, 1:02 pm, john Culleton <J...@wexfordpress.com> wrote:
> In the cobol.vim file, something causes all sentences starting
> with "if" to be colored red just like an error.

Any chance of sending us some valid cobol showing the problem? Or
uploading it somewhere we can get it from? That would multiply
enormously those who cqn help.

I expect that some kind of cobol-85 or cobol-90 mode has been turned
on and the if has no matching end-if.

Regards, John

john Culleton

unread,
Feb 14, 2012, 11:06:53 PM2/14/12
to vim...@googlegroups.com


Well it is both the reserved word IF and the reserved word END that causes the
problem. And to my knowledge END-IF is not required in COBOL 85.

I tried adding an END-IF but the error remained.

Here is a brief program that shows both problems:
----------------------------------

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. utl022.
000030 AUTHOR. JOHN CULLETON.
000040 INSTALLATION. WEXFORDPRESS
000045 Eldersburg MD.
000047*SECURITY. Copyright 2006 John R. Culleton, Jr.
000050*REMARKS. Displays program file..
000070 ENVIRONMENT DIVISION.
000080
000090 CONFIGURATION SECTION.
000100 SOURCE-COMPUTER.
000110 Linux.
000120 OBJECT-COMPUTER.
000230 Linux.
000140
000150 INPUT-OUTPUT SECTION.
000160 FILE-CONTROL.
SELECT PROGFILE ASSIGN TO "prog"
ORGANIZATION IS INDEXED ACCESS IS DYNAMIC
RECORD KEY IS PROGNAME
ALTERNATE RECORD KEY IS PARNAME
WITH DUPLICATES.


000180 DATA DIVISION.
000190
000200 FILE SECTION.
FD PROGFILE.
01 PROGREC.
02 PROGNAME PICTURE X(6).
02 PROGNAMM REDEFINES PROGNAME PICTURE X(6).
02 PARNAME PICTURE X(6).
02 PARNAMM REDEFINES PARNAME PICTURE X(6).
02 LEVNO PICTURE 9.
02 DEFINITION PICTURE X(58).
000220 WORKING-STORAGE SECTION.
000230 77 END-INPUT-FLAG PICTURE X VALUE "N".
88 END-INPUT VALUE "Y".
000230 77 INVALID-FLAG PICTURE X VALUE "N".
88 IND-INPUT VALUE "Y".
01 PRINTLINE.
02 PROGNAMM PICTURE X(6).
02 FILLER PICTURE X VALUE SPACE.
02 PARNAMM PICTURE X(6).
02 FILLER PICTURE X VALUE SPACE.
02 LEVNO PICTURE 9.
02 FILLER PICTURE X VALUE SPACE.
02 DEFINITION PICTURE X(50).

000240 PROCEDURE DIVISION.
000250 001-MAIN-PROCEDURE.
OPEN INPUT PROGFILE.
PERFORM 100-LOOP UNTIL END-INPUT.
CLOSE PROGFILE.
000270 STOP RUN.
100-LOOP.
READ PROGFILE NEXT RECORD AT END MOVE "Y" TO END-INPUT-FLAG.
IF NOT END-INPUT PERFORM 200-PROCESS.
200-PROCESS.
DISPLAY PROGREC.
MOVE CORRESPONDING PROGREC TO PRINTLINE.
DISPLAY PRINTLINE.
---------------------------------------------
Both lines in the paragraph 100-LOOP are highlighted. The first
such line is highlighted from the word END to the period.
The second line is highlighted from the word IF to the period. There
is only one syntax file for COBOL, cobol.vim. There is also an indent
file named cobol.vim but I don't see an indent problem.

sc

unread,
Feb 15, 2012, 12:33:36 AM2/15/12
to vim...@googlegroups.com

i saved this email as utl022.cbl, deleted the parts not cobol,
and the parts you say are flagged as errors are not flagged for
me -- the only thing in mine that's flagged as an error is the
tab character in front of the '02' in the 2nd FILLER field of
PRINTLINE

my syntax module cobol.vim has a 7th line containing:

" $Id: cobol.vim,v 1.2 2007/05/05 18:23:43 vimboss Exp $

is that the same as yours?

sc

Christian Brabandt

unread,
Feb 15, 2012, 2:48:49 AM2/15/12
to vim...@googlegroups.com
Hi john!

Do you have somehow legacy highlighting enabled? This seems only to
happen, if I set in my .vimrc:

:let cobol_legacy_code = 1

See, if this variable exists in your cobol file and enter:

:echo cobol_legacy_code

If you don't get an error, simply unlet that varible:

:unlet cobol_legacy_code

and do a

:filetype detect

The highlighting should than vanish. You then need to find out, where
you set this variable (I suspect either in your .vimrc, in a
ftplugin/cobol.vim or even after/ftplugin/cobol.vim file)

regards,
Christian

john Culleton

unread,
Feb 15, 2012, 4:07:57 PM2/15/12
to vim...@googlegroups.com
On Tue, 14 Feb 2012 23:33:36 -0600
sc <toot...@swbell.net> wrote:
>
> my syntax module cobol.vim has a 7th line containing:
>
> " $Id: cobol.vim,v 1.2 2007/05/05 18:23:43 vimboss Exp $
>
> is that the same as yours?
>
> sc
>

Yes, they are identical. It is possible that my cobol.vim is
corrupt. I will try downloading and reinstalling vim.

john Culleton

unread,
Feb 15, 2012, 4:26:28 PM2/15/12
to vim...@googlegroups.com
On Wed, 15 Feb 2012 08:48:49 +0100 Christian Brabandt
<cbl...@256bit.org> wrote:

> Hi john!


>

> :let cobol_legacy_code = 1
>
> See, if this variable exists in your cobol file and enter:
>
> :echo cobol_legacy_code
>
> If you don't get an error, simply unlet that varible:
>
> :unlet cobol_legacy_code
>
> and do a
>
> :filetype detect
>
> The highlighting should than vanish. You then need to find out,
> where you set this variable (I suspect either in your .vimrc,
> in a ftplugin/cobol.vim or even after/ftplugin/cobol.vim file)
>
> regards, Christian
>

Well I write in COBOL 85 in the traditional fixed format. See my
previous example.

I started with pre-COBOL 68, in 1968. The IF statement and the
AT END statements were legal then and still are legal in all the
compilers I have used. I am reasonably certain they were legal
in the very first COBOL compiler written by Grace Murray Hopper
and her crew. So there is a fault in cobol.vim. Yes, I
have cobol_legacy_code set. That should not cause IF and END to
be highlighted as errors. There is a problem with cobol.vim, like
it or not.


If I unset cobol_legacy_code, IF no longer causes errors. But line
numbers in columns 1-6 are now highlighted as errors.

I upgraded to vim 7.3 but still have the same error.
I will try disabling my .vimrc file and see if that helps.

Christian Brabandt

unread,
Feb 15, 2012, 5:02:12 PM2/15/12
to vim...@googlegroups.com
Hi john!

On Mi, 15 Feb 2012, john Culleton wrote:

> On Wed, 15 Feb 2012 08:48:49 +0100 Christian Brabandt
> <cbl...@256bit.org> wrote:
>
> > Hi john!
> >
>
> > :let cobol_legacy_code = 1
> >
> > See, if this variable exists in your cobol file and enter:
> >
> > :echo cobol_legacy_code
> >
> > If you don't get an error, simply unlet that varible:
> >
> > :unlet cobol_legacy_code
> >
> > and do a
> >
> > :filetype detect
> >
> > The highlighting should than vanish. You then need to find out,
> > where you set this variable (I suspect either in your .vimrc,
> > in a ftplugin/cobol.vim or even after/ftplugin/cobol.vim file)
> >
> > regards, Christian
> >
> Well I write in COBOL 85 in the traditional fixed format. See my
> previous example.
>
> I started with pre-COBOL 68, in 1968. The IF statement and the
> AT END statements were legal then and still are legal in all the
> compilers I have used. I am reasonably certain they were legal
> in the very first COBOL compiler written by Grace Murray Hopper
> and her crew. So there is a fault in cobol.vim.

Be it a fault or not, it is configurable. As I don't know Cobol, I can't
judge. But I wouldn't call it a bug yet.

> Yes, I have cobol_legacy_code set. That should not cause IF and END to
> be highlighted as errors.

I don't know whether it should or not highlight it as errors and I
really don't care. But this is the way it is in the syntax file and you
*can* configure it.

So maybe, just configure it and don't complain here about IF and END
being allowed in Cobol or not.

> There is a problem with cobol.vim, like it or not.

I couldn't care less. I am just trying to help *you*. Seems, you don't
want my help.

> If I unset cobol_legacy_code, IF no longer causes errors.

See, it works.

> But line numbers in columns 1-6 are now highlighted as errors.

Now this could be an error. I think you want to discuss this with the
maintainer of the syntax file. But also this behaviour can be
configured:

Create a file ~/.vim/after/syntax/cobol and create non-existing
directories and in there put

hi link CobolMarker Comment

Like it or not, it is all configurable and I don't see an error here.

However if you want to complain about something, just discuss this with
the maintainer of the syntax file or simply create your own better
syntax file.

regards,
Christian
--

John Little

unread,
Feb 15, 2012, 7:38:47 PM2/15/12
to vim_use
On Feb 16, 10:26 am, john Culleton <J...@wexfordpress.com> wrote:
>
> I started with pre-COBOL 68, in 1968.  The IF statement and the
> AT END statements were legal then and still are legal in all the
> compilers I have used.  I am reasonably certain they were legal
> in the very first COBOL compiler written by Grace Murray Hopper
> and her crew.   So there is a fault in cobol.vim. Yes, I
> have cobol_legacy_code set. That should not cause IF and END to
> be highlighted as errors. There is a problem with cobol.vim, like
> it or not.

(Hey, we're friendlier than that here. Such belaboured sarcasm may
not be appreciated.)

I'm not an expert at syntax files, but I've hacked a few...

The vim command

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

show the lines in question being highlighted as the "group name"
cobolBadLine, which appears to me to have nothing to do with the lines
in question.

I suggest copying $VIMRUNTIME/syntax/cobol.vim to $HOME/.vim/syntax
(or whatever your system has) and change the line 148 that starts

syn region cobolCondFlow contains=ALLBUT,cobolLine start=...

to

syn region cobolCondFlow contains=ALLBUT,cobolLine,cobolBadLine
start=...

to stop cobolBadLine being recognized there.

(Syntax gurus, I understand why there is

syn match cobolBadLine "\s\+\*.*" contained

but what

syn match cobolBadLine "[^ D\*$/-].*" contained

is for or what it does I've no idea.)

Regards, John

john Culleton

unread,
Feb 16, 2012, 4:58:20 PM2/16/12
to vim...@googlegroups.com
On Wed, 15 Feb 2012 16:38:47 -0800 (PST)
John Little <john.b...@gmail.com> wrote:

> On Feb 16, 10:26 am, john Culleton <J...@wexfordpress.com> wrote:
> >
> > I started with pre-COBOL 68, in 1968.  The IF statement and the
> > AT END statements were legal then and still are legal in all the
> > compilers I have used.  I am reasonably certain they were legal
> > in the very first COBOL compiler written by Grace Murray Hopper
> > and her crew.   So there is a fault in cobol.vim. Yes, I
> > have cobol_legacy_code set. That should not cause IF and END to
> > be highlighted as errors. There is a problem with cobol.vim, like
> > it or not.
>
> (Hey, we're friendlier than that here. Such belaboured sarcasm may
> not be appreciated.)

Well I did what I swore I wouldn't do, hacked the cobol.vim file
blindly. I inserted the keywords IF and END in the big list of
COBOL reserved words. Now it works, at least enough to satisfy me.
I left in the line:

syn match cobolReserved contained "\<\(IF\|INVALID\|END\|EOP\)\>"

I have no idea what it does, but apparently it does no harm.

Thanks to all who replied. If anyone wants a copy of my hacked
cobol.vim just drop me a line.
--
John Culleton

Christian Brabandt

unread,
Feb 17, 2012, 1:21:05 AM2/17/12
to vim...@googlegroups.com
Hi john!

On Do, 16 Feb 2012, john Culleton wrote:

> On Wed, 15 Feb 2012 16:38:47 -0800 (PST)
> John Little <john.b...@gmail.com> wrote:
>
> > On Feb 16, 10:26�am, john Culleton <J...@wexfordpress.com> wrote:
> > >
> > > I started with pre-COBOL 68, in 1968. �The IF statement and the
> > > AT END statements were legal then and still are legal in all the
> > > compilers I have used. �I am reasonably certain they were legal
> > > in the very first COBOL compiler written by Grace Murray Hopper
> > > and her crew. � So there is a fault in cobol.vim. Yes, I
> > > have cobol_legacy_code set. That should not cause IF and END to
> > > be highlighted as errors. There is a problem with cobol.vim, like
> > > it or not.
> >
> > (Hey, we're friendlier than that here. Such belaboured sarcasm may
> > not be appreciated.)
>
> Well I did what I swore I wouldn't do, hacked the cobol.vim file
> blindly. I inserted the keywords IF and END in the big list of
> COBOL reserved words. Now it works, at least enough to satisfy me.
> I left in the line:

You wouldn't have to. I told you, how to configure it properly. I hope,
you didn't modify the file in $VIMRUNTIME directly:
http://vimhelp.appspot.com/vim_faq.txt.html#faq-36.11


regards,
Christian
--

Reply all
Reply to author
Forward
0 new messages