From 481c6165caf81d65773d4ea989c19c7e07e2c5d3 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 17 Mar 2020 11:55:28 +0100 Subject: [PATCH] Parametrize code generation actions from the command line --- src/ifcexpressparser/README.txt | 9 +++++---- src/ifcexpressparser/bootstrap.py | 13 ++++--------- src/ifcexpressparser/definitions.py | 2 ++ src/ifcexpressparser/header.py | 2 ++ src/ifcexpressparser/implementation.py | 3 +++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/ifcexpressparser/README.txt b/src/ifcexpressparser/README.txt index ede43994d3..793b4c9c67 100644 --- a/src/ifcexpressparser/README.txt +++ b/src/ifcexpressparser/README.txt @@ -2,10 +2,11 @@ This folder contains Python code to generate C++ type information based on an Express schema. In particular is has only been tested using recent version of the IFC schema and will most likely fail on any other Express schema. -The code can be invoked in the following way and results in two header files -and a single implementation file named according to the schema name in the -Express file. A python 3 interpreter with the pyparsing [1] library is required. +The code can be invoked in the following way and results in several code outputs +named according to the schema name in the Express file. A python 3 interpreter +with the pyparsing [1] library is required. -$ python bootstrap.py express.bnf > express_parser.py && python express_parser.py IFC2X3_TC1.exp +$ python bootstrap.py express.bnf > express_parser.py +$ python express_parser.py IFC2X3_TC1.exp header implementation schema_class definitions [1] http://pyparsing.wikispaces.com/Download+and+Installation diff --git a/src/ifcexpressparser/bootstrap.py b/src/ifcexpressparser/bootstrap.py index 6c0c6ac5ee..0cbf839d69 100644 --- a/src/ifcexpressparser/bootstrap.py +++ b/src/ifcexpressparser/bootstrap.py @@ -198,15 +198,10 @@ else: with open(cache_file, "wb") as f: pickle.dump(mapping, f, protocol=0) -import header -import implementation -import schema_class -import definitions - -header.Header(mapping).emit() -implementation.Implementation(mapping).emit() -schema_class.SchemaClass(mapping).emit() -definitions.Definitions(mapping).emit() +import importlib +for output in sys.argv[2:]: + mdl = importlib.import_module(output) + mdl.Generator(mapping).emit() sys.stdout.write(schema.name) """%('\n '.join(statements))) diff --git a/src/ifcexpressparser/definitions.py b/src/ifcexpressparser/definitions.py index d4c24a481e..9683c4ffb5 100644 --- a/src/ifcexpressparser/definitions.py +++ b/src/ifcexpressparser/definitions.py @@ -64,3 +64,5 @@ class Definitions(codegen.Base): def __repr__(self): return self.str + +Generator = Definitions diff --git a/src/ifcexpressparser/header.py b/src/ifcexpressparser/header.py index 87090ceace..7b6ae41a59 100644 --- a/src/ifcexpressparser/header.py +++ b/src/ifcexpressparser/header.py @@ -145,3 +145,5 @@ class Header(codegen.Base): def __repr__(self): return self.str + +Generator = Header diff --git a/src/ifcexpressparser/implementation.py b/src/ifcexpressparser/implementation.py index 66da7e7237..e9dab2ae86 100644 --- a/src/ifcexpressparser/implementation.py +++ b/src/ifcexpressparser/implementation.py @@ -257,3 +257,6 @@ class Implementation(codegen.Base): def __repr__(self): return self.str + + +Generator = Implementation