Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install pygments-ibm-cobol-lexer

How to install pygments_ibm_cobol_lexer

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pygments-ibm-cobol-lexer
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
1.1 Available View build log
Linux (64-bit)
1.1 Available View build log
Lastest release
version 1.1 on Nov 28th, 2012

This package contains a Pygments Lexer for cobol (db2, cics and dli embedded).

The lexer parses the Enterprise Cobol for z/os (V3R4) dialect, including utilizing embedded Db2/Sql, Cics and DLi

mainframe cobol coding form

Many early programming languages, including PL/1, Fortran, Cobol and the various IBM assembler languages, used only the first 7-72 columns of a 80-column card

1- 6 Tags, Remarks or Sequence numbers identifying pages or lines of a program
  • * (asterisk) designates entire line as comment
  • / (slash) forces page break when printing source listing
  • - (dash) to indicate continuation of nonnumeric literal
8 - 72
COBOL program statements, divided into two areas :
  • Area A : columns 8 to 11
  • Area B : columns 12 to 72
73 - 80 Tags, Remarks or Sequence numbers (often garbage...)

Division, section and paragraph-names must all begin in Area A and end with a period.

CBL/PROCESS directives statement can start in columns 1 through 70


The lexer is available as a Pip package:

$ sudo pip install pygments_ibm_cobol_lexer

Or using easy_install:

$ sudo easy_install pygments_ibm_cobol_lexer


After installation the ibmcobol Lexer and ibmcobol Style automatically registers itself for files with the ".cbl" extensions.

  • Therefore, cmdline usage is easy:
Ascii input :

pygmentize -O full,style=ibmcobol,encoding=latin1 -o HORREUR.html HORREUR.ascii.cbl

Ebcdic input (in this case it's necessary to specify outencoding value):

pygmentize -O full,style=ibmcobol,encoding=cp1147,outencoding=latin1 -o COB001.html COB001.cp1147.cbl

  • As library :
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments_ibm_cobol_lexer import IBMCOBOLLexer, IBMCOBOLStyle
my_code = open("cobol_ebcdic.cbl",'rb').read()
          HtmlFormatter(style=IBMCOBOLStyle, full=True),

Also see the pygments_ibm_cobol_lexer-1.1/pygments_tests/ directory

About cp1147

I have files coded IBM1147 (EBCDIC french + euro sign), I was forced to write my own codec cp1147, very close to the cp500 (Canada, Belgium), it diverges on the characters "@°{}§ùµ£à[€`¨#]~éè¦ç" :

from pygments_ibm_cobol_lexer import cp1147

print "euro sign ?",chr(159).decode('cp1147')
print ''.join([ chr(i).decode('cp1147') for i in range(0,256)
          if chr(i).decode('cp1147') != chr(i).decode('cp500')])

I have added this import in IBMCOBOLLexer init method :

if self.encoding == 'cp1147':
    import cp1147


1.1 - (2012-11-19) Minor Fix + EBCDIC enhancements:

  • Fix : float regex detection before integer detection
  • Add inline-commentaire *> (not the IBM default)
  • Change cics/dli keywords color...
  • Extend CICS_KEYWORDS, remove EJECT/SKIP from COBOL_KEYWORDS (treated as comments)
  • each ASCII input lines is padded to 80 columns
  • Add EBCDIC features:
    • add my own french codec cp1147
    • if EBCDIC encoding is passed (cp500,cp1140,...) or detected, convert the binary input raw text in 80 columns fixed lines
    • encoding=chardet (slowly) does not detect EBCDIC chart, it's override with encoding=guess
    • "guess EBCDIC" is defaulted to self.encoding='cp500'

1.0 - (2012-11-12) Initial release.

Subscribe to package updates

Last updated Nov 28th, 2012

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.