cobol.vim 13 KB

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