Skip to content
This repository was archived by the owner on Mar 29, 2019. It is now read-only.

Commit f30a0dc

Browse files
committed
repr format is consistent
1 parent 90bde37 commit f30a0dc

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

mamba/ast.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __iter__(self):
1515
return iter(self.children)
1616

1717
def __repr__(self):
18-
return '<Instruction list: {0}>'.format(self.children)
18+
return '<InstructionList {0}>'.format(self.children)
1919

2020
def eval(self):
2121
"""
@@ -79,7 +79,7 @@ def __init__(self, value):
7979
self.value = value
8080

8181
def __repr__(self):
82-
return '<Primitive: "{0}"({1})>'.format(self.value, self.value.__class__)
82+
return '<Primitive "{0}"({1})>'.format(self.value, self.value.__class__)
8383

8484
def eval(self):
8585
return self.value
@@ -92,7 +92,7 @@ def __init__(self, name):
9292
self.name = name
9393

9494
def __repr__(self):
95-
return '<Identifier: {0}>'.format(self.name)
95+
return '<Identifier {0}>'.format(self.name)
9696

9797
def assign(self, val):
9898
if self.is_function:
@@ -112,7 +112,7 @@ def __init__(self, values: InstructionList):
112112
self.values = values
113113

114114
def __repr__(self):
115-
return '<Array len={0} [{1}]>'.format(len(self.values.children), self.values)
115+
return '<Array len={0} items={1}>'.format(len(self.values.children), self.values)
116116

117117
def eval(self):
118118
return self.values.eval()
@@ -137,7 +137,7 @@ def __init__(self, array: Identifier, index: BaseExpression, value: BaseExpressi
137137
self.value = value
138138

139139
def __repr__(self):
140-
return '<Array arr={0}; index={1}; value={2}>'.format(self.array, self.index, self.value)
140+
return '<Array arr={0} index={1} value={2}>'.format(self.array, self.index, self.value)
141141

142142
def eval(self):
143143
self.array.eval()[self.index.eval()] = self.value.eval()
@@ -150,7 +150,7 @@ def __init__(self, array: Identifier, start: BaseExpression=None, end: BaseExpre
150150
self.end = end
151151

152152
def __repr__(self):
153-
return '<ArraySlice array={0}; start={1}; end={2}>'.format(self.array, self.start, self.end)
153+
return '<ArraySlice array={0} start={1} end={2}>'.format(self.array, self.start, self.end)
154154

155155
def eval(self):
156156
if self.start is not None and self.end is not None:
@@ -174,7 +174,7 @@ def __init__(self, identifier: Identifier, val):
174174
self.val = val
175175

176176
def __repr__(self):
177-
return '<Assignment: sym = {0}; val = {1}>'.format(self.identifier, self.val)
177+
return '<Assignment sym={0}; val={1}>'.format(self.identifier, self.val)
178178

179179
def eval(self):
180180
if self.identifier.is_function:
@@ -210,7 +210,7 @@ class BinaryOperation(BaseExpression):
210210
}
211211

212212
def __repr__(self):
213-
return '<Binary operation: left = {0}; right = {1}; operation={2}>'.format(self.left, self.right, self.op)
213+
return '<BinaryOperation left ={0} right={1} operation="{2}">'.format(self.left, self.right, self.op)
214214

215215
def __init__(self, left, right, op):
216216
self.left = left
@@ -244,8 +244,8 @@ def __init__(self, identifier: Identifier, modifier: BaseExpression, operation:
244244
self.operation = operation
245245

246246
def __repr__(self):
247-
return '<Compound identifier={0}; mod={1}; operation={2}>'.format(self.identifier, self.modifier,
248-
self.operation)
247+
fmt = '<Compound identifier={0} mod={1} operation={2}>'
248+
return fmt.format(self.identifier, self.modifier, self.operation)
249249

250250
def eval(self):
251251
# Express the compound operation as a 'simplified' binary op
@@ -288,7 +288,7 @@ def __init__(self, condition: BaseExpression, truepart: InstructionList, elsepar
288288
self.elsepart = elsepart
289289

290290
def __repr__(self):
291-
return '<If condition={0}; then={1}>'.format(self.condition, self.truepart)
291+
return '<If condition={0} then={1} else={2}>'.format(self.condition, self.truepart, self.elsepart)
292292

293293
def eval(self):
294294
if self.condition.eval():
@@ -310,7 +310,7 @@ def __init__(self, variable: Identifier, start: Primitive, end: Primitive, asc:
310310

311311
def __repr__(self):
312312
fmt = '<For start={0} direction={1} end={2} body={3}>'
313-
return fmt.format(self.start, '->' if self.asc else '<-', self.end, self.body)
313+
return fmt.format(self.start, 'asc' if self.asc else 'desc', self.end, self.body)
314314

315315
def eval(self):
316316
if self.asc:
@@ -337,7 +337,7 @@ def __init__(self, variable: Identifier, sequence: BaseExpression, body: Instruc
337337
self.body = body
338338

339339
def __repr__(self):
340-
return '<ForIn {0} in {1} do {2}>'.format(self.variable, self.sequence, self.body)
340+
return '<ForIn var={0} in iterable={1} do body={2}>'.format(self.variable, self.sequence, self.body)
341341

342342
def eval(self):
343343
for i in self.sequence.eval():
@@ -365,7 +365,7 @@ def __init__(self, items: InstructionList):
365365
self.items = items
366366

367367
def __repr__(self):
368-
return '<Print: {0}>'.format(self.items)
368+
return '<Print {0}>'.format(self.items)
369369

370370
def eval(self):
371371
print(*self.items.eval(), end='', sep='')
@@ -466,7 +466,7 @@ def __init__(self, cond: BaseExpression, trueval: BaseExpression, falseval: Base
466466
self.falseval = falseval
467467

468468
def __repr__(self):
469-
return '<Ternary cond: {0} true:{1} false:{2}>'.format(self.cond, self.trueval, self.falseval)
469+
return '<Ternary cond={0} true={1} false={2}>'.format(self.cond, self.trueval, self.falseval)
470470

471471
def eval(self):
472472
return self.trueval.eval() if self.cond.eval() else self.falseval.eval()

0 commit comments

Comments
 (0)