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