55from dice_notation .dice import RollableDice , Rollable
66
77"""
8- Dice notation nodes .
8+ Dice notation classes .
99
10- Used to generate the parsed tree from a dice notation expression.
10+ Used to generate the parsed tree from a dice notation expression. These
11+ expressions will be nodes in that tree.
1112
12- All the nodes are rollable, to allow generating a roll from any point of the
13+ All the classes are rollable, to allow generating a roll from any point of the
1314expression.
1415"""
1516
1617
17- class ConstantNode (Rollable ):
18+ class ConstantExpression (Rollable ):
1819 """
19- Node containing a constant value.
20+ Expression for a constant value.
2021
2122 It just wraps any value, allowing it to interface with the other nodes.
2223
@@ -25,30 +26,30 @@ class ConstantNode(Rollable):
2526 """
2627
2728 def __init__ (self , constant ):
28- super (ConstantNode , self ).__init__ ()
29+ super (ConstantExpression , self ).__init__ ()
2930 self ._constant = constant
3031 # If it received a constant node this is unwrapped
31- # TODO: Maybe the problem should be fixed somewhere else
32- while isinstance (self ._constant , ConstantNode ):
32+ # TODO: Maybe this problem should be fixed somewhere else
33+ while isinstance (self ._constant , ConstantExpression ):
3334 self ._constant = constant .constant
3435
3536 def __add__ (self , other ):
36- return ConstantNode (other + self .constant )
37+ return ConstantExpression (other + self .constant )
3738
3839 def __sub__ (self , other ):
39- return ConstantNode (self .constant - other )
40+ return ConstantExpression (self .constant - other )
4041
4142 def __radd__ (self , other ):
42- return ConstantNode (self .constant + other )
43+ return ConstantExpression (self .constant + other )
4344
4445 def __rsub__ (self , other ):
45- return ConstantNode (other - self .constant )
46+ return ConstantExpression (other - self .constant )
4647
4748 def __lt__ (self , other ):
4849 return self .constant < other
4950
5051 def __le__ (self , other ):
51- if isinstance (other , ConstantNode ):
52+ if isinstance (other , ConstantExpression ):
5253 return self .constant <= other .constant
5354 elif isinstance (other , (int , float )):
5455 return self .constant <= other
@@ -65,7 +66,7 @@ def __gt__(self, other):
6566 return self .constant > other
6667
6768 def __ge__ (self , other ):
68- if isinstance (other , ConstantNode ):
69+ if isinstance (other , ConstantExpression ):
6970 return self .constant >= other .constant
7071 elif isinstance (other , (int , float )):
7172 return self .constant >= other
@@ -101,25 +102,27 @@ def roll(self):
101102 return self .constant
102103
103104
104- class DiceNode (RollableDice ):
105+ class DiceExpression (RollableDice ):
105106 """
106- Node containing a dice.
107+ Expression for a dice.
108+
109+ It is mostly just its parent class, only adding comparison methods.
107110 """
108111
109112 def __init__ (self , quantity , sides ):
110- super (DiceNode , self ).__init__ (quantity = quantity , sides = sides )
113+ super (DiceExpression , self ).__init__ (quantity = quantity , sides = sides )
111114
112115 def __add__ (self , other ):
113- return ConstantNode (other + self .roll ())
116+ return ConstantExpression (other + self .roll ())
114117
115118 def __sub__ (self , other ):
116- return ConstantNode (self .roll () - other )
119+ return ConstantExpression (self .roll () - other )
117120
118121 def __radd__ (self , other ):
119- return ConstantNode (self .roll () + other )
122+ return ConstantExpression (self .roll () + other )
120123
121124 def __rsub__ (self , other ):
122- return ConstantNode (other - self .roll ())
125+ return ConstantExpression (other - self .roll ())
123126
124127 def __str__ (self ):
125128 return '%sd%s' % (self .quantity , self .sides )
@@ -129,15 +132,15 @@ def __repr__(self):
129132 (self .__class__ .__name__ , self .quantity , self .sides )
130133
131134
132- class BinaryOperationNode (Rollable ):
135+ class BinaryOperationExpression (Rollable ):
133136 """
134- Node for a binary operation.
137+ Exprssion for a binary operation.
135138
136139 Acquiring its value will execute a function with two parameters.
137140 """
138141
139142 def __init__ (self , function , left , right ):
140- super (BinaryOperationNode , self ).__init__ ()
143+ super (BinaryOperationExpression , self ).__init__ ()
141144 self ._logger = logging .getLogger (self .__class__ .__name__ )
142145 self ._function = function
143146 self ._left = left
@@ -146,28 +149,28 @@ def __init__(self, function, left, right):
146149 def __add__ (self , other ):
147150 value = self .operate ()
148151 self ._logger .debug ("%s + %s" , value , other )
149- return ConstantNode (other + value )
152+ return ConstantExpression (other + value )
150153
151154 def __sub__ (self , other ):
152155 value = self .operate ()
153156 self ._logger .debug ("%s - %s" , other , value )
154- return ConstantNode (value - other )
157+ return ConstantExpression (value - other )
155158
156159 def __radd__ (self , other ):
157160 value = self .operate ()
158161 self ._logger .debug ("(rear) %s + %s" , value , other )
159- return ConstantNode (value + other )
162+ return ConstantExpression (value + other )
160163
161164 def __rsub__ (self , other ):
162165 value = self .operate ()
163166 self ._logger .debug ("(rear) %s - %s" , other , value )
164- return ConstantNode (other - value )
167+ return ConstantExpression (other - value )
165168
166169 def __lt__ (self , other ):
167170 return self .operate () < other
168171
169172 def __le__ (self , other ):
170- if isinstance (other , ConstantNode ):
173+ if isinstance (other , ConstantExpression ):
171174 return self .operate () <= other .constant
172175 elif isinstance (other , (int , float )):
173176 return self .operate () <= other
@@ -184,7 +187,7 @@ def __gt__(self, other):
184187 return self .operate () > other
185188
186189 def __ge__ (self , other ):
187- if isinstance (other , ConstantNode ):
190+ if isinstance (other , ConstantExpression ):
188191 return self .operate () >= other .constant
189192 elif isinstance (other , (int , float )):
190193 return self .operate () >= other
0 commit comments