Composing assignment expression

Issue #2 new
Anonymous created an issue

When running the following code:

p = parse("a = 2 + 3", Expression)
print(compose(p))

On output I erroneously get : a = 2
When I print the XML dump of the instance p, everything seems allright.

On the other hand, if I parse expression: "a = (2 + 3)", I get: a = 2 + 3

Am I missing something?

Comments (2)

  1. Volker Birk repo owner

    Yes and no ;-)

    That's a bug with compose() and this grammar obviously. But this grammar is still pre-alpha. Hadn't any time to work on it, sorry.

    The only reason why it is published in such an early state is that I was asked to do that – just to give an example for pyPEG, even if it's incomplete.

  2. Bogdan Vukobratovic

    The following change seems to have fixed the problem.

    At line 1385 of init.py of pyPEG module, i changed the elif branch to:

    elif isinstance(g, attr.Class):
        t = getattr(thing, g.name)
        if (not ("grammar" in dir(t))):
            text.append(self.compose(t, g.thing, attr_of=thing))
        else:
            text.append(self.compose(t, attr_of=thing))
    
        if card < 1:
            break
    
  3. Log in to comment