HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
15 user(s) are online (5 user(s) are browsing Forum)

Members: 0
Guests: 15

more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     Pygments syntax highlighter
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
btiffin
Posted on: 2012/5/20 6:28
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Pygments syntax highlighter
I just added a pull request for the upstream Pygments developers to check out the code I use to highlight the FAQ.

Linking to the SourceForge forum, to get everyone used to the idea.

https://sourceforge.net/apps/phpbb/open-cobol/viewtopic.php?f=5&t=3

And now's the chance to suggest colours / critique the ones used in the FAQ.

Cheers,
Brian
btiffin
Posted on: 2012/8/25 12:21
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: Pygments syntax highlighter
I've been requested to add a tests/examplefiles source code sample that exercises the syntax highlighter.

I'll make one up (well two actually FIXED and FREE), but if anyone has an existent sample that they think would stress test a code highlighter, I'd appreciate seeing it.

Still open to comments on the default colours used (see the FAQ source listings for current scheme, http://opencobol.add1tocobol.com/#how-do-i-use-opencobol-for-cgi for example).

Oh, and ignore that phpbb link in the parent post, as that external app is going to be dumped from the forge in favour of the built in forum features at SourceForge.

Cheers,
Brian
human
Posted on: 2012/8/28 14:57
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: Pygments syntax highlighter
Here you go (was a sample for PSPad, but could be useful for general checking
      * ----------------------------------------------------------------
      * Program PSPSAM showing some stuff for testing COBOL lexers
      * (especially old errors in PSPad COBOL syntax)
      * ----------------------------------------------------------------
       IDENFTIFICATION DIVISION.
       PROGRAM-ID. 'PSPSAM'.
      * ----------------------------------------------------------------
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
       SYSERR IS MY-ERR
           DECIMAL-POINT IS COMMA.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT MY-FILE ASSIGN TO MY-FILE-NAME
               ORGANIZATION IS LINE SEQUENTIAL
               FILE STATUS  IS MY-FILE-STATUS.  
           SELECT MY-INPFILE ASSIGN TO "INPUT.DAT"
               ORGANIZATION IS SEQUENTIAL
               FILE STATUS  IS MY-FILE-STATUS.
       I-O-CONTROL.
       DATA DIVISION.
       FILE SECTION.
       FD MY-FILE.
       01 MY-FILE-REC.
           02 MY-REC.
              03 MY-BIG1    PIC X(32000).  
              03 MY-BIG2    PIC X(32000).  
       FD MY-INPFILE.
       01 MY-INPFILE-REC.
           02 MY-INPREC     PIC X(320).
      * ----------------------------------------------------------------
       WORKING-STORAGE SECTION.       
       78 MY-FILE-NAME   VALUE 'TEST.DAT'. 
       77 MY-FILE-STATUS PIC X(02).     
       01 PARM-1.
          05  PARM-1-1   PIC X(12). 
          05  PARM-1-2   PIC X(10).
       01 PARM-2         PIC X(80).
       77 mycount        pic 9(02) value 0.
       COPY WSCPY.
       77 BVAR           PIC X(650000) BASED.                             
      * ----------------------------------------------------------------
       LOCAL-STORAGE SECTION.
      *>   This var is marked:
       01 local-var                    pic 9 value zero.  
          88  local-var-unchanged       value zero.            
      *>  This var is NOT marked (because of two spaces):
      *>  Either all these vars should be marked or none      
       01  loc2                        PIC X(12) VALUE SPACES.
       77 loc3                         pic 9(05) usage comp-3 value 12.       
       COPY LOCPY.
      * ----------------------------------------------------------------
       LINKAGE SECTION.
       01 some-rec.
          02 some-rec-1                pic 9(04).
          02 some-rec-2                pic x(4096).  
       COPY LICPY.
      * ----------------------------------------------------------------
       PROCEDURE DIVISION USING some-rec.
      *> Declaratives are very special. If they occur, they start with
      *> the "declaratives" keyword and end with "end declaratives" (the
      *> number of spaces between these two words doesn't matter).
      *> They can contain multiple sections/paragraphs.
      *> Check that this is recognized correct as an own area (inside 
      *> working storage), not as an empty paragraph.
       DECLARATIVES.              
      * Error section for MY-FILE:
       DEC-MY SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON MY-FILE.
         DM-BEG.
            display 'ERROR IN MYFILE: "' MY-FILE-STATUS '"'
            end-display 
            accept loc2
            end-accept
            exit program returning 1
         DM-END.
            EXIT SECTION.
      * Error section for all files opened with INPUT: 
       DEC-MYIN SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON INPUT.
         DMI-BEG.
            display 'ERROR IN MYINPFILE: "' MY-FILE-STATUS '"'
            end-display 
            accept loc2
            end-accept
            exit program returning 1
         DMI-END.
            EXIT SECTION.
      *
       end  declaratives.
      * ----------------------------------------------------------------
       MAIN SECTION.
       PARA-1.
           OPEN INPUT MYINPFILE
           READ MYINP-REC END-READ
           OPEN OUTPUT MYFILE 
           perform 2 times
              write MYFILE from myinp-rec
              end-write
           end-perform
      *>   perform and end-perform ^could be shown as belonging together
      *>   but this is a bit tricky as there could be so-called 
      *>   "out-of-line perform" (even within an inline perform) like
           perform varying mycount from 2 by 3 
                   until   mycount > 9       
              perform some    *> out-of-line perform of section
              perform para-2  *> out-of-line perform of paragraph
      *>      here comes an out-of-line perform with additional clauses
      *>      and line brakes (COBOL ignores these as it ignores 
      *>      the position within the correct coding area)
              perform 
                para-2 
                    varying mycount from 2 by 3
                  until mycount > 9
           end-perform 
      *>   Here the hard sample - a dot closes everything within
      *>   the paragraph/section
           perform varying mycount from 2 by 3 
                   until   mycount > 9
              if mycount = 9
                 evaluate PARM-1
                    when 'AAA'
                       continue
                    when 'BBB'
                    when 'CCC'
                       if PARM-2 = 'C'
                          write MYFILE from myinp-rec
                       end-evaluate
                    when other
                       call 'SUBPROG' using PARM-1
                          on exception
                             if PARM-2 = 'C'
                                move PARM-1 to PARM-2.
           
           CLOSE MYFILE 
           CLOSE MYINPFILE
           ALLOCATE BVAR
           MOVE ALL 'A' TO BVAR
           CALL 'SUBMOD' USING PARM-1  
                               BVAR      
                               PARM-2.
           FREE ADDRESS OF BVAR
           go to para-3
           continue.
       PARA-2.   
           continue.
       PARA-3.
           EXIT PROGRAM.  
      * ----------------------------------------------------------------
       SOME SECTION.
           move  PARM-1 to PARM-2 
           EXIT SECTION.    
      * ----------------------------------------------------------------
       SOME2 SECTION.
           move  PARM-2 to PARM-1 
           continue.      
      * ----------------------------------------------------------------


Simon 'human' Sobisch
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net