cobol.vim 9.7 KB

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