|
| 1 | +This is an experimental alternate Parser implementation, with a view to facilitating the integration |
| 2 | +of Part21 and Part28 exchange structures with other schema (such as AP203, AP214 and AP242). |
| 3 | + |
| 4 | +The idea is to build a base Part21 parser implementation implemented using Ply (such as the one you |
| 5 | +can now find in SCL.Part21 in this branch). |
| 6 | + |
| 7 | +Exp2Python would be enhanced to subclass this parser and implement parser rules based on Part21 |
| 8 | +type / parameter mapping of schemas. |
| 9 | + |
| 10 | +Exp2Python output Entity classes would be minimal, implementing all calculated attributes and |
| 11 | +automatic type conversion from Part21 parameter types to the schema defined types. DERIVED |
| 12 | +attributes would be implemented in the output class (as they are now). |
| 13 | + |
| 14 | +Validating and non-validating versions of the parser would be generated. |
| 15 | + |
| 16 | +For the validating parser all type checking / compatibility would be implemented by parser rules and |
| 17 | +callbacks. Callbacks would be run after the first parser run, or sooner if a way could be found to |
| 18 | +trigger them when appropriate. |
| 19 | + |
| 20 | +Some pseudo code is given below (see comments): |
| 21 | + |
| 22 | +import SCL.Part21 |
| 23 | + |
| 24 | +# entity classes would be fully implemented by exp2python |
| 25 | +class RepresentationItem: |
| 26 | + def __init__(self, name): |
| 27 | + pass |
| 28 | + |
| 29 | +# complete implementation not shown here! |
| 30 | +class GeometricRepresentationItem(RepresentationItem): |
| 31 | + def __init__(self, name): |
| 32 | + RepresentationItem.__init__(self, name) |
| 33 | + |
| 34 | +class Curve(GeometricRepresentationItem): |
| 35 | + def __init__(self, name): |
| 36 | + GeometricRepresentationItem.__init__(self, name) |
| 37 | + |
| 38 | +class Conic(Curve): |
| 39 | + def __init__(self, name, position): |
| 40 | + Curve.__init__(self, name, position) |
| 41 | + |
| 42 | +class Circle(Conic): |
| 43 | + def __init__(self, name, position, radius): |
| 44 | + Conic.__init__(self, name, position, radius) |
| 45 | + |
| 46 | + |
| 47 | +class AP203Parser(SCL.Part21.Parser): |
| 48 | + entities = ['ABSORBED_DOSE_MEASURE_WITH_UNIT', |
| 49 | + 'ABSORBED_DOSE_UNIT', |
| 50 | + ..., |
| 51 | + 'AXIS1_PLACEMENT', |
| 52 | + 'AXIS2_PLACEMENT_2D', |
| 53 | + 'AXIS2_PLACEMENT_3D', |
| 54 | + ..., |
| 55 | + 'CIRCLE', |
| 56 | + 'CIRCULAR_RUNOUT_TOLERANCE', |
| 57 | + 'YEAR_MONTH', |
| 58 | + ..., |
| 59 | + 'ZONE_STRUCTURAL_MAKEUP'] |
| 60 | + |
| 61 | + def __init__(self, ...): |
| 62 | + SCL.Part21.Parser.__init__(self, ...) |
| 63 | + # schema entities would be passed to the underlying lexer to faciliate exact rule matches |
| 64 | + self.register_entities(self.entities) |
| 65 | + |
| 66 | + # validating form |
| 67 | + def p_circle_entity(self, p): |
| 68 | + r"""simple_record : CIRCLE '(' STRING ',' ENTITY_INSTANCE_NAME ',' REAL ')'""" |
| 69 | + p[0] = Circle(p[3], p[5], p[7]) |
| 70 | + self.add_instance_validation(p[5], lambda x: isinstance(x, Axis2Placement)) |
| 71 | + |
| 72 | + # non validating form |
| 73 | + def p_circle_entity(self, p): |
| 74 | + r"""simple_record : CIRCLE '(' parameter_list ')'""" |
| 75 | + p[0] = Circle(*p[3]) |
| 76 | + |
0 commit comments