|
| 1 | +from enum import Enum |
| 2 | + |
| 3 | +class ScadTypes(Enum): |
| 4 | + GLOBAL_VAR = 0 |
| 5 | + MODULE = 1 |
| 6 | + FUNCTION = 2 |
| 7 | + USE = 3 |
| 8 | + INCLUDE = 4 |
| 9 | + PARAMETER = 5 |
| 10 | + |
| 11 | +class ScadObject: |
| 12 | + def __init__(self, scadType): |
| 13 | + self.scadType = scadType |
| 14 | + |
| 15 | + def getType(self): |
| 16 | + return self.scadType |
| 17 | + |
| 18 | +class ScadUse(ScadObject): |
| 19 | + def __init__(self, filename): |
| 20 | + super().__init__(ScadTypes.USE) |
| 21 | + self.filename = filename |
| 22 | + |
| 23 | +class ScadInclude(ScadObject): |
| 24 | + def __init__(self, filename): |
| 25 | + super().__init__(ScadTypes.INCLUDE) |
| 26 | + self.filename = filename |
| 27 | + |
| 28 | +class ScadGlobalVar(ScadObject): |
| 29 | + def __init__(self, name): |
| 30 | + super().__init__(ScadTypes.GLOBAL_VAR) |
| 31 | + self.name = name |
| 32 | + |
| 33 | +class ScadCallable(ScadObject): |
| 34 | + def __init__(self, name, parameters, scadType): |
| 35 | + super().__init__(scadType) |
| 36 | + self.name = name |
| 37 | + self.parameters = parameters |
| 38 | + |
| 39 | + def __repr__(self): |
| 40 | + return f'{self.name} ({self.parameters})' |
| 41 | + |
| 42 | +class ScadModule(ScadCallable): |
| 43 | + def __init__(self, name, parameters): |
| 44 | + super().__init__(name, parameters, ScadTypes.MODULE) |
| 45 | + |
| 46 | +class ScadFunction(ScadCallable): |
| 47 | + def __init__(self, name, parameters): |
| 48 | + super().__init__(name, parameters, ScadTypes.FUNCTION) |
| 49 | + |
| 50 | +class ScadParameter(ScadObject): |
| 51 | + def __init__(self, name, optional=False): |
| 52 | + super().__init__(ScadTypes.PARAMETER) |
| 53 | + self.name = name |
| 54 | + self.optional = optional |
| 55 | + |
| 56 | + def __repr__(self): |
| 57 | + return self.name + "=None" if self.optional else self.name |
| 58 | + |
0 commit comments