Beispiel #1
0
    def __init__(self, token):
        assert isinstance(token, Token)

        if token.token_type in self.token_map.keys():
            self._operation_type = self.token_map[token.token_type]
        else:
            self._operation_type = OperationType.VARIABLE(token.value)
Beispiel #2
0
    def transform(self, expression, pattern=None):
        assert isinstance(expression, Operation)
        if pattern is None:
            assert isinstance(pattern, SubstitutionPattern)

        for k in pattern.keys():
            if type(pattern[k]) == str:
                pattern[k] = Operation(OperationType.VARIABLE(pattern[k]))

        substituted_start = self.try_transform(expression, pattern)

        substituted_end = self._substitute(self._end, pattern)

        return substituted_end