diff --git a/adia/class_.py b/adia/class_.py index 250a7e7..05f71c4 100644 --- a/adia/class_.py +++ b/adia/class_.py @@ -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): @@ -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') @@ -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), diff --git a/tests/test_class_interpreter.py b/tests/test_class_interpreter.py index 620f13d..804f003 100644 --- a/tests/test_class_interpreter.py +++ b/tests/test_class_interpreter.py @@ -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)