License New BSD license
Lines 86
Keywords
COBOL (5) lexer (6) pygments (6)
Included in this Library
Permissions
Owner: Theodore Test
Viewable by Everyone
Editable by All Siafoo Users

Standard COBOL Pygments Lexer Atom Feed 0

In Brief A Pygments lexer for the generic modern COBOL language implementation. This is the ILE COBOL lexer used by Siafoo.
# 's
 1import re
2
3from pygments.lexer import RegexLexer, include, bygroups, using, this
4from pygments.token import Error, Punctuation, Text, Comment, Operator, Keyword, Name, String, Number
5
6class COBOLLexer(RegexLexer):
7 name = 'COBOL'
8 aliases = ['cobol', 'COBOL']
9 filenames = ['*.cbl', '*.CBL']
10 mimetypes = []
11
12
13 # Really only five major sorts of highlighting --
14 # Reserved Words, Comments, Numbers, Strings, and Punctuation
15 # Due to COBOL implementation details, even what modern languages consider 'operators'
16 # are treated as Reserved Words.
17
18 tokens = {
19 'root': [
20 (r'\*.*\n', Comment),
21 include('strings'),
22 include('core'),
23 include('nums'),
24 (r'[\s]+', Text)
25 ],
26 'core':[(r'\b(PAGE-COUNTER|TEST|END-UNSTRING|REPLACING|SEGMENT-LIMIT|END-PERFORM|FROM|'
27 r'RIGHT|RESERVE|ESI|COPY|END-START|ALPHANUMERIC-EDITED|START|'
28 r'TIMES|VALUE|INTO|SUPPRESS|SPACE|STRING|DIVISION|'
29 r'STATUS|END-ADD|DAY|=|THAN|COMP|SUB-QUEUE-2|'
30 r'COMMA|TO|FINAL|-|\*\*|END-EVALUATE|INSTALLATION|'
31 r'PICTURE|TRAILING|SPACES|DEBUG-CONTENTS|REMOVAL|NUMBER|CHARACTER|'
32 r'DE|DEPENDING|USE|ZEROES|OBJECT-COMPUTER|>|USING|'
33 r'KEY|IDENTIFICATION|REWRITE|GREATER|FALSE|PROGRAM-ID|TRUE|'
34 r'CONVERTING|DEBUG-SUB-1|CORR|ADD|END-DIVIDE|WRITE|USAGE|'
35 r'EMI|DUPLICATES|PLUS|CONFIGURATION|CLOSE|DISABLE|INDICATE|'
36 r'REPLACE|SUB-QUEUE-3|COLUMN|AREA|REFERENCE|SET|DEBUGGING|'
37 r'DISPLAY|ORDER|ASCENDING|OVERFLOW|GROUP|REFERENCES|PROGRAM|'
38 r'NO|REPORTS|STOP|SECTION|EVALUATE|INDEX|DEBUG-LINE|'
39 r'>=|DATE-COMPILED|AT|TIME|THROUGH|CONTINUE|INITIATE|'
40 r'SUB-QUEUE-1|I-O|UP|TERMINATE|LOW-VALUES|QUOTES|SIZE|'
41 r'RELEASE|ERROR|QUEUE|SYMBOLIC|ALTERNATE|JUST|END|'
42 r'ALSO|CODE-SET|ADVANCING|I-O-CONTROL|TAPE|BLANK|ALPHABETIC-UPPER|'
43 r'/|DECIMAL-POINT|DYNAMIC|REPORTING|OPEN|FILLER|END-IF|'
44 r'PROCEED|BLOCK|HIGH-VALUE|REPORT|DOWN|ACCEPT|MODULES|'
45 r'DELETE|OR|OUTPUT|VARYING|END-REWRITE|LENGTH|CLASS|'
46 r'CONTAINS|OF|ON|END-CALL|FIRST|DELIMITER|MERGE|'
47 r'INVALID|END-READ|DECLARATIVES|REVERSED|BINARY|RENAMES|DELIMITED|'
48 r'GLOBAL|LINKAGE|<|\*|BEFORE|END-OF-PAGE|EVERY|'
49 r'RF|SOURCE|RD|DESTINATION|PIC|BOTTOM|TABLE|'
50 r'COMMUNICATION|ALTER|REEL|JUSTIFIED|INITIALIZE|FILE|LIMIT|'
51 r'EGI|END-RECEIVE|MOVE|WHEN|LESS|DEBUG-NAME|MULTIPLE|'
52 r'RESET|POINTER|MESSAGE|MEMORY|ARE|CALL|ACCESS|'
53 r'SAME|NEGATIVE|ALPHABETIC-LOWER|IF|ROUNDED|CANCEL|IN|'
54 r'ZEROS|OTHER|IS|LEADING|SORT-MERGE|RANDOM|END-SUBTRACT|'
55 r'SEGMENT|MODE|SEQUENTIAL|RECORD|OMITTED|CONTROL|DATA|'
56 r'COMPUTE|LINAGE|CHARACTERS|CONTROLS|DATE|PURGE|LINES|'
57 r'<=|TOP|DAY-OF-WEEK|EXCEPTION|SD|PAGE|TYPE|'
58 r'POSITION|REWIND|CD|RECEIVE|INSPECT|SUM|RH|'
59 r'HIGH-VALUES|RUN|ALL|DESCENDING|ZERO|CONTENT|STANDARD|'
60 r'CF|LOCK|CLOCK-UNITS|SORT|LEFT|OCCURS|DEBUG-SUB-3|'
61 r'DEBUG-SUB-2|ORGANIZATION|WORDS|COLLATING|UNTIL|ALPHABET|PACKED-DECIMAL|'
62 r'END-COMPUTE|NATIVE|WITH|LINE-COUNTER|ASSIGN|FD|STANDARD-1|'
63 r'END-STRING|STANDARD-2|NUMERIC-EDITED|WORKING-STORAGE|READ|END-WRITE|THEN|'
64 r'ANY|REMAINDER|DETAIL|RERUN|NOT|TERMINAL|INPUT-OUTPUT|'
65 r'POSITIVE|GIVING|SPECIAL-NAMES|MULTIPLY|AND|UNIT|GENERATE|'
66 r'OPTIONAL|TALLYING|INPUT|INDEXED|EXTERNAL|END-MULTIPLY|ALPHANUMERIC|'
67 r'ELSE|END-DELETE|SEQUENCE|FOR|DIVIDE|REDEFINES|COUNT|'
68 r'SECURITY|EXIT|DEBUG-ITEM|PF|FILE-CONTROL|RECORDS|BY|'
69 r'SOURCE-COMPUTER|\+|SUBTRACT|AUTHOR|END-SEARCH|SEARCH|COBOL|'
70 r'LINAGE-COUNTER|SELECT|LINE|PROCEDURES|CURRENCY|LABEL|SYNC|'
71 r'UPON|INITIAL|SYNCHRONIZED|RETURN|CODE|FUNCTION|AREAS|'
72 r'ALPHABETIC|VALUES|PADDING|LOW-VALUE|SEND|AFTER|COMPUTATIONAL|'
73 r'PROCEDURE|PH|CORRESPONDING|GO|ENTER|RELATIVE|SIGN|'
74 r'FOOTING|NATIONAL|EQUAL|SENTENCE|OFF|END-RETURN|COMMON|'
75 r'THRU|PRINTING|NEXT|NUMERIC|SEPARATE|QUOTE|LIMITS|'
76 r'LAST|DATE-WRITTEN|HEADING|UNSTRING|EOP|ENVIRONMENT|CH|'
77 r'TEXT|PERFORM|EXTEND|ENABLE)\s*\b', Keyword),
78 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
79 (r'(\.)',Punctuation)],
80
81 'strings': [
82 (r'"(\\|\[0-7]+|\.|[^"])*"', String.Double),
83 (r"'(\\|\[0-7]+|\.|[^'])*'", String.Single),
84 ],
85
86 'nums': [
87 (r'\d+(?![.Ee])', Number.Integer),
88 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
89 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float)
90 ],
91 }

A Pygments lexer for the generic modern COBOL language implementation. This is the ILE COBOL lexer used by Siafoo.