3 " Maintainer: Tim Pope <vimNOSPAM@tpope.info>
4 " (formerly Davyd Ondrejko <vondraco@columbus.rr.com>)
5 " (formerly Sitaram Chamarty <sitaram@diac.com> and
6 " James Mitchell <james_mitchell@acm.org>)
7 " $Id: cobol.vim,v 1.5 2007/05/12 15:30:10 vimboss Exp $
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
13 elseif exists("b:current_syntax")
17 " MOST important - else most of the keywords wont work!
21 setlocal isk=@,48-57,-
26 syn cluster cobolStart contains=cobolAreaA,cobolAreaB,cobolComment,cobolCompiler
27 syn cluster cobolAreaA contains=cobolParagraph,cobolSection,cobolDivision
28 "syn cluster cobolAreaB contains=
29 syn cluster cobolAreaAB contains=cobolLine
30 syn cluster cobolLine contains=cobolReserved
31 syn match cobolMarker "^\%( \{,5\}[^ ]\)\@=.\{,6}" nextgroup=@cobolStart
32 syn match cobolSpace "^ \{6\}" nextgroup=@cobolStart
33 syn match cobolAreaA " \{1,4\}" contained nextgroup=@cobolAreaA,@cobolAreaAB
34 syn match cobolAreaB " \{5,\}\|- *" contained nextgroup=@cobolAreaB,@cobolAreaAB
35 syn match cobolComment "[/*C].*$" contained
36 syn match cobolCompiler "$.*$" contained
37 syn match cobolLine ".*$" contained contains=cobolReserved,@cobolLine
39 syn match cobolDivision "[A-Z][A-Z0-9-]*[A-Z0-9]\s\+DIVISION\."he=e-1 contained contains=cobolDivisionName
40 syn keyword cobolDivisionName contained IDENTIFICATION ENVIRONMENT DATA PROCEDURE
41 syn match cobolSection "[A-Z][A-Z0-9-]*[A-Z0-9]\s\+SECTION\."he=e-1 contained contains=cobolSectionName
42 syn keyword cobolSectionName contained CONFIGURATION INPUT-OUTPUT FILE WORKING-STORAGE LOCAL-STORAGE LINKAGE
43 syn match cobolParagraph "\a[A-Z0-9-]*[A-Z0-9]\.\|\d[A-Z0-9-]*[A-Z]\."he=e-1 contained contains=cobolParagraphName
44 syn keyword cobolParagraphName contained PROGRAM-ID SOURCE-COMPUTER OBJECT-COMPUTER SPECIAL-NAMES FILE-CONTROL I-O-CONTROL
47 "syn match cobolKeys "^\a\{1,6\}" contains=cobolReserved
48 syn keyword cobolReserved contained ACCEPT ACCESS ADD ADDRESS ADVANCING AFTER ALPHABET ALPHABETIC
49 syn keyword cobolReserved contained ALPHABETIC-LOWER ALPHABETIC-UPPER ALPHANUMERIC ALPHANUMERIC-EDITED ALS
50 syn keyword cobolReserved contained ALTERNATE AND ANY ARE AREA AREAS ASCENDING ASSIGN AT AUTHOR BEFORE BINARY
51 syn keyword cobolReserved contained BLANK BLOCK BOTTOM BY CANCEL CBLL CD CF CH CHARACTER CHARACTERS CLASS
52 syn keyword cobolReserved contained CLOCK-UNITS CLOSE COBOL CODE CODE-SET COLLATING COLUMN COMMA COMMON
53 syn keyword cobolReserved contained COMMUNICATIONS COMPUTATIONAL COMPUTE CONTENT CONTINUE
54 syn keyword cobolReserved contained CONTROL CONVERTING CORR CORRESPONDING COUNT CURRENCY DATE DATE-COMPILED
55 syn keyword cobolReserved contained DATE-WRITTEN DAY DAY-OF-WEEK DE DEBUG-CONTENTS DEBUG-ITEM DEBUG-LINE
56 syn keyword cobolReserved contained DEBUG-NAME DEBUG-SUB-1 DEBUG-SUB-2 DEBUG-SUB-3 DEBUGGING DECIMAL-POINT
57 syn keyword cobolReserved contained DELARATIVES DELETE DELIMITED DELIMITER DEPENDING DESCENDING DESTINATION
58 syn keyword cobolReserved contained DETAIL DISABLE DISPLAY DIVIDE DIVISION DOWN DUPLICATES DYNAMIC EGI ELSE EMI
59 syn keyword cobolReserved contained ENABLE END-ADD END-COMPUTE END-DELETE END-DIVIDE END-EVALUATE END-IF
60 syn keyword cobolReserved contained END-MULTIPLY END-OF-PAGE END-READ END-RECEIVE END-RETURN
61 syn keyword cobolReserved contained END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT END-UNSTRING
62 syn keyword cobolReserved contained END-WRITE EQUAL ERROR ESI EVALUATE EVERY EXCEPTION EXIT
63 syn keyword cobolReserved contained EXTEND EXTERNAL FALSE FD FILLER FINAL FIRST FOOTING FOR FROM
64 syn keyword cobolReserved contained GENERATE GIVING GLOBAL GREATER GROUP HEADING HIGH-VALUE HIGH-VALUES I-O
65 syn keyword cobolReserved contained IN INDEX INDEXED INDICATE INITIAL INITIALIZE
66 syn keyword cobolReserved contained INITIATE INPUT INSPECT INSTALLATION INTO IS JUST
67 syn keyword cobolReserved contained JUSTIFIED KEY LABEL LAST LEADING LEFT LENGTH LOCK MEMORY
68 syn keyword cobolReserved contained MERGE MESSAGE MODE MODULES MOVE MULTIPLE MULTIPLY NATIVE NEGATIVE NEXT NO NOT
69 syn keyword cobolReserved contained NUMBER NUMERIC NUMERIC-EDITED OCCURS OF OFF OMITTED ON OPEN
70 syn keyword cobolReserved contained OPTIONAL OR ORDER ORGANIZATION OTHER OUTPUT OVERFLOW PACKED-DECIMAL PADDING
71 syn keyword cobolReserved contained PAGE PAGE-COUNTER PERFORM PF PH PIC PICTURE PLUS POINTER POSITION POSITIVE
72 syn keyword cobolReserved contained PRINTING PROCEDURES PROCEDD PROGRAM PURGE QUEUE QUOTES
73 syn keyword cobolReserved contained RANDOM RD READ RECEIVE RECORD RECORDS REDEFINES REEL REFERENCE REFERENCES
74 syn keyword cobolReserved contained RELATIVE RELEASE REMAINDER REMOVAL REPLACE REPLACING REPORT REPORTING
75 syn keyword cobolReserved contained REPORTS RERUN RESERVE RESET RETURN RETURNING REVERSED REWIND REWRITE RF RH
76 syn keyword cobolReserved contained RIGHT ROUNDED RUN SAME SD SEARCH SECTION SECURITY SEGMENT SEGMENT-LIMITED
77 syn keyword cobolReserved contained SELECT SEND SENTENCE SEPARATE SEQUENCE SEQUENTIAL SET SIGN SIZE SORT
78 syn keyword cobolReserved contained SORT-MERGE SOURCE STANDARD
79 syn keyword cobolReserved contained STANDARD-1 STANDARD-2 START STATUS STOP STRING SUB-QUEUE-1 SUB-QUEUE-2
80 syn keyword cobolReserved contained SUB-QUEUE-3 SUBTRACT SUM SUPPRESS SYMBOLIC SYNC SYNCHRONIZED TABLE TALLYING
81 syn keyword cobolReserved contained TAPE TERMINAL TERMINATE TEST TEXT THAN THEN THROUGH THRU TIME TIMES TO TOP
82 syn keyword cobolReserved contained TRAILING TRUE TYPE UNIT UNSTRING UNTIL UP UPON USAGE USE USING VALUE VALUES
83 syn keyword cobolReserved contained VARYING WHEN WITH WORDS WRITE
84 syn match cobolReserved contained "\<CONTAINS\>"
85 syn match cobolReserved contained "\<\(IF\|INVALID\|END\|EOP\)\>"
86 syn match cobolReserved contained "\<ALL\>"
88 syn cluster cobolLine add=cobolConstant,cobolNumber,cobolPic
89 syn keyword cobolConstant SPACE SPACES NULL ZERO ZEROES ZEROS LOW-VALUE LOW-VALUES
91 syn match cobolNumber "\<-\=\d*\.\=\d\+\>" contained
92 syn match cobolPic "\<S*9\+\>" contained
93 syn match cobolPic "\<$*\.\=9\+\>" contained
94 syn match cobolPic "\<Z*\.\=9\+\>" contained
95 syn match cobolPic "\<V9\+\>" contained
96 syn match cobolPic "\<9\+V\>" contained
97 syn match cobolPic "\<-\+[Z9]\+\>" contained
98 syn match cobolTodo "todo" contained containedin=cobolComment
100 " For MicroFocus or other inline comments, include this line.
101 " syn region cobolComment start="*>" end="$" contains=cobolTodo,cobolMarker
103 syn match cobolBadLine "[^ D\*$/-].*" contained
104 " If comment mark somehow gets into column past Column 7.
105 syn match cobolBadLine "\s\+\*.*" contained
106 syn cluster cobolStart add=cobolBadLine
109 syn keyword cobolGoTo GO GOTO
110 syn keyword cobolCopy COPY
112 " cobolBAD: things that are BAD NEWS!
113 syn keyword cobolBAD ALTER ENTER RENAMES
115 syn cluster cobolLine add=cobolGoTo,cobolCopy,cobolBAD,cobolWatch,cobolEXECs
117 " cobolWatch: things that are important when trying to understand a program
118 syn keyword cobolWatch OCCURS DEPENDING VARYING BINARY COMP REDEFINES
119 syn keyword cobolWatch REPLACING RUN
120 syn match cobolWatch "COMP-[123456XN]"
122 syn keyword cobolEXECs EXEC END-EXEC
125 syn cluster cobolAreaA add=cobolDeclA
126 syn cluster cobolAreaAB add=cobolDecl
127 syn match cobolDeclA "\(0\=1\|77\|78\) " contained nextgroup=cobolLine
128 syn match cobolDecl "[1-4]\d " contained nextgroup=cobolLine
129 syn match cobolDecl "0\=[2-9] " contained nextgroup=cobolLine
130 syn match cobolDecl "66 " contained nextgroup=cobolLine
132 syn match cobolWatch "88 " contained nextgroup=cobolLine
134 "syn match cobolBadID "\k\+-\($\|[^-A-Z0-9]\)" contained
136 syn cluster cobolLine add=cobolCALLs,cobolString,cobolCondFlow
137 syn keyword cobolCALLs CALL END-CALL CANCEL GOBACK PERFORM END-PERFORM INVOKE
138 syn match cobolCALLs "EXIT \+PROGRAM"
139 syn match cobolExtras /\<VALUE \+\d\+\./hs=s+6,he=e-1
141 syn match cobolString /"[^"]*\("\|$\)/
142 syn match cobolString /'[^']*\('\|$\)/
144 "syn region cobolLine start="^.\{6}[ D-]" end="$" contains=ALL
145 syn match cobolIndicator "\%7c[D-]" contained
147 if exists("cobol_legacy_code")
148 syn region cobolCondFlow contains=ALLBUT,cobolLine start="\<\(IF\|INVALID\|END\|EOP\)\>" skip=/\('\|"\)[^"]\{-}\("\|'\|$\)/ end="\." keepend
151 " many legacy sources have junk in columns 1-6: must be before others
152 " Stuff after column 72 is in error - must be after all other "match" entries
153 if exists("cobol_legacy_code")
154 syn match cobolBadLine "\%73c.*" containedin=ALLBUT,cobolComment
156 syn match cobolBadLine "\%73c.*" containedin=ALL
159 " Define the default highlighting.
160 " For version 5.7 and earlier: only when not done already
161 " For version 5.8 and later: only when an item doesn't have highlighting yet
162 if version >= 508 || !exists("did_cobol_syntax_inits")
164 let did_cobol_syntax_inits = 1
165 command -nargs=+ HiLink hi link <args>
167 command -nargs=+ HiLink hi def link <args>
170 HiLink cobolBAD Error
171 HiLink cobolBadID Error
172 HiLink cobolBadLine Error
173 if exists("g:cobol_legacy_code")
174 HiLink cobolMarker Comment
176 HiLink cobolMarker Error
178 HiLink cobolCALLs Function
179 HiLink cobolComment Comment
180 HiLink cobolKeys Comment
181 HiLink cobolAreaB Special
182 HiLink cobolCompiler PreProc
183 HiLink cobolCondFlow Special
184 HiLink cobolCopy PreProc
185 HiLink cobolDeclA cobolDecl
186 HiLink cobolDecl Type
187 HiLink cobolExtras Special
188 HiLink cobolGoTo Special
189 HiLink cobolConstant Constant
190 HiLink cobolNumber Constant
191 HiLink cobolPic Constant
192 HiLink cobolReserved Statement
193 HiLink cobolDivision Label
194 HiLink cobolSection Label
195 HiLink cobolParagraph Label
196 HiLink cobolDivisionName Keyword
197 HiLink cobolSectionName Keyword
198 HiLink cobolParagraphName Keyword
199 HiLink cobolString Constant
200 HiLink cobolTodo Todo
201 HiLink cobolWatch Special
202 HiLink cobolIndicator Special
207 let b:current_syntax = "cobol"