def __init__(self, variable): if re.match(r'^((GF|TF|LF)@[a-zA-Z_\-$&%*!?][a-zA-Z0-9_\-$&%*!?]*)$', variable) is None: raise error.StructureError_32(variable) frame, name = variable.split('@', 2) self.frame = frame self.name = name
def boolean(self): """ Creates bool and returns it """ if self.value == 'true': return True elif self.value == 'false': return False else: raise error.StructureError_32(self.value)
def string(self): """ Creates str and returns it """ if self.value is None: self.value = '' if re.match(r'^(\\[0-9]{3}|[^\\#\s])*$', self.value) is None: # TODO raise error.StructureError_32(self.value) escape = re.findall(r'\\[0-9]{3}', self.value) not_escape = re.split(r'\\[0-9]{3}', self.value) final_string = '' for not_esc, esc in zip(not_escape, escape): final_string += not_esc + chr(int(esc[1:])) final_string += not_escape[-1] return str(final_string)
def integer(self): """ Creates int and returns it """ try: return int(self.value) except ValueError: raise error.StructureError_32(self.value)
def __init__(self, text): if text != 'nil': raise error.StructureError_32(text) self._nil = None
def __init__(self, name): if re.match(r'^([a-zA-Z_\-$&%*!?][a-zA-Z0-9_\-$&%*!?]*)$', name) is None: raise error.StructureError_32(name) self._name = name
def __init__(self, typ): if typ not in {'int', 'bool', 'string'}: raise error.StructureError_32(typ) self._type = typ