[feaLib.ast] add __str__ to all AST elements
which calls the asFea() method, so one can e.g. print(doc.statements[0])
This commit is contained in:
parent
0ff6be5ff8
commit
fdab63f0b6
@ -47,7 +47,8 @@ def asFea(g):
|
||||
return g
|
||||
|
||||
|
||||
class Statement(object):
|
||||
class Element(object):
|
||||
|
||||
def __init__(self, location):
|
||||
self.location = location
|
||||
|
||||
@ -55,28 +56,25 @@ class Statement(object):
|
||||
pass
|
||||
|
||||
def asFea(self, indent=""):
|
||||
pass
|
||||
raise NotImplementedError
|
||||
|
||||
def __str__(self):
|
||||
return self.asFea()
|
||||
|
||||
|
||||
class Expression(object):
|
||||
def __init__(self, location):
|
||||
self.location = location
|
||||
|
||||
def build(self, builder):
|
||||
pass
|
||||
|
||||
def asFea(self, indent=""):
|
||||
pass
|
||||
class Statement(Element):
|
||||
pass
|
||||
|
||||
|
||||
class Comment(object):
|
||||
class Expression(Element):
|
||||
pass
|
||||
|
||||
|
||||
class Comment(Element):
|
||||
def __init__(self, location, text):
|
||||
self.location = location
|
||||
super(Comment, self).__init__(location)
|
||||
self.text = text
|
||||
|
||||
def build(self, builder):
|
||||
pass
|
||||
|
||||
def asFea(self, indent=""):
|
||||
return self.text
|
||||
|
||||
|
@ -81,6 +81,7 @@ class ParserTest(unittest.TestCase):
|
||||
c2 = doc.statements[1].statements[1]
|
||||
self.assertEqual(type(c1), ast.Comment)
|
||||
self.assertEqual(c1.text, "# Initial")
|
||||
self.assertEqual(str(c1), "# Initial")
|
||||
self.assertEqual(type(c2), ast.Comment)
|
||||
self.assertEqual(c2.text, "# simple")
|
||||
self.assertEqual(doc.statements[1].name, "test")
|
||||
|
Loading…
x
Reference in New Issue
Block a user