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?
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)
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.
Here's the definition of COBOL_schemata.
To use a different lexical scanner, this function has to be modified.
Is that really the best approach?
Here's an approach
Here's another approach: fix the COBOL_schemata function to take the lexer class as an argument.
That way the application can parse the copybooks with this:
This might be more what's needed.