Commits

Matt Bone committed 3cc83d5

token classes do not mutate values

  • Participants
  • Parent commits f5d6221

Comments (0)

Files changed (1)

in_py/parse_sexp.py

 class symbol_token(token):
     def __add__(self, x):
         if isinstance(x, symbol_token) or isinstance(x, number_token):
-            self.value += x.value
-            return self            
+            return symbol_token(self.value + x.value)          
         else:
             raise next_token_exception()
 
         if isinstance(x, symbol_token):
             raise syntax_exception("symbols cannot start with a number")
         elif isinstance(x, number_token):
-            self.value += x.value
+            return number_token(self.value + x.value)
             return self
         else:
             raise next_token_exception()
 
     def __add__(self, x):
         if(isinstance(x, whitespace_token)):
-            self.value += x.value
-            return self
+            return whitespace_token(self.value + x.value)
         else:
             raise next_token_exception()