Skip to content

Commit

Permalink
Class multiple inheritance: #41.
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Aug 31, 2021
1 parent 8c15ef1 commit 631ede7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 18 additions & 1 deletion adia/class_.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Class_(Interpreter):

def __init__(self, *args, **kw):
self.members = []
self.parents = []
super().__init__('start', *args, **kw)

def _set_name(self, title):
Expand All @@ -61,6 +62,9 @@ def dumps(self):
f = StringIO()
f.write(self.title)

if self.parents:
f.write(f'({", ".join(self.parents)})')

if self.members:
f.write('\n')

Expand All @@ -73,11 +77,24 @@ def _new_attr(self, *args):
attr = Attr.parse(*args)
self.members.append(attr)

def _add_parent(self, name):
self.parents.append(name)

statemap = {
'start': {
NAME: {NEWLINE: GoTo(' attr', cb=_set_name)},
NAME: GoTo('name+', cb=_set_name),
NEWLINE: GoTo('start', ignore=True)
},
'name+': {
NEWLINE: GoTo(' attr'),
LPAR: GoTo('('),
},
'(': {
NAME: {
RPAR: GoTo('name+', cb=_add_parent),
COMMA: GoTo('(', cb=_add_parent)
}
},
' attr': {
NEWLINE: GoTo(' attr', ignore=True),
NAME: Terminate(reuse=True),
Expand Down
13 changes: 13 additions & 0 deletions tests/test_class_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ def test_class_reference():
bar -> baz
''')
assert len(d) == 1


def test_class_inheritance():
s = '''
class: Foo
foo(bar)
int bar(a, *b, c)
*Bar bar(int *a)
bar(baz, qux)
'''
eqrepr(s)

0 comments on commit 631ede7

Please sign in to comment.