using COBOL_schemata and Lexer_Long_Lines

2014-06-05
2014-06-07
  • Steven F. Lott

    Steven F. Lott - 2014-06-05

    Here's the definition of COBOL_schemata.

    def COBOL_schemata( source, replacing=None ):
        lexer= Lexer( replacing )
        parser= RecordFactory()
        dde_list= list( parser.makeRecord( lexer.scan(source) ) )
        schema_list= list( make_schema( dde ) for dde in dde_list )
        return dde_list, schema_list
    

    To use a different lexical scanner, this function has to be modified.

    def COBOL_schemata( source, replacing=None ):
        lexer= stingray.cobol.loader.Lexer_Long_Lines( replacing )
        parser= RecordFactory()
        dde_list= list( parser.makeRecord( lexer.scan(source) ) )
        schema_list= list( make_schema( dde ) for dde in dde_list )
        return dde_list, schema_list
    

    Is that really the best approach?

     
  • Steven F. Lott

    Steven F. Lott - 2014-06-06

    Here's an approach

    250     with tempfile.TemporaryFile(mode='w+') as stripped_copybook:
    251         with open(args.copybook, "r") as cobol_copybook:
    252             for line in cobol_copybook:
    253                 if len(line) > 72:
    254                     line = line[0:72] + '\n'
    255                 stripped_copybook.write(line)
    256         stripped_copybook.seek(0)
    257         dde_list, schema_list = stingray.cobol.loader.COBOL_schemata( stripped_copybook, replacing=args.replacestring)
    
     
  • Steven F. Lott

    Steven F. Lott - 2014-06-07

    Here's another approach: fix the COBOL_schemata function to take the lexer class as an argument.

    def COBOL_schemata( source, replacing=None, lexer_class=Lexer ):
        lexer= lexer_class( replacing )
        parser= RecordFactory()
        dde_list= list( parser.makeRecord( lexer.scan(source) ) )
        schema_list= list( make_schema( dde ) for dde in dde_list )
        return dde_list, schema_list
    

    That way the application can parse the copybooks with this:

    with open(args.copybook, "r") as cobol_copybook:
        dde_list, schema_list= COBOL_schemata( cobol_copybook, lexer_class=cobol.loader.Lexer_Long_Lines, replace=('THIS','THAT') )
    

    This might be more what's needed.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks