SyntaxWarning: tuple not recommended as grammar of attribute

Issue #13 resolved
Anonymous created an issue

hello, i just started playing with PyPEG2, so please bear with me.

from pypeg2 import *

F = K('F')
T = K('T')
fts = maybe_some([F, T])

class Chatty(Concat):
  grammar = attr('a', fts), attr('b', F)

class FTs(List):
  grammar = fts

class Silent(Concat):
  grammar = attr('x', FTs), attr('y', F)

generates

/usr/local/lib/python2.7/site-packages/pypeg2/__init__.py:131: SyntaxWarning: tuple not recommended as grammar of attribute 'a'
  + repr(name), SyntaxWarning)

i have a few issues with that:

  • the message does not point to the source location. it's easy to derive in this instance (only one a attribute in the whole file), but that's a special case.
  • the message does not tell me why it's bad
  • the message does not tell me how to make the tool happy

Comments (7)

  1. Volker Birk repo owner

    Hello, Roman,

    pyPEG is a parser, but it is a composer, too. That means it's like a text template language. pyPEG is a model parser in a way that makes it possible to revert the parsing process and compose(). This reverting thing is somewhat experimental yet. That's the reason why the compose() algorithm will change with the next version. For parsing alone you can safely ignore the warnings. And yes, you're right, they're not very expressive. But I think they will be removed completely. I will not need them any more.

    You asked that, so I'm assuming you're interested in some details ;-) I'm trying to explain that in short words:

    There is a problem with polymorphy for grammar types (non-terminal symbols). Usually, grammar languages don't support something like that. pyPEG does. In the actual version, polymorphy makes problems when parsing into attributes (and at other places, too). Because I need that for the project I'm developing pyPEG for, I created that warning message. Grammar polymorphy will be fully supported in the next release, the warning will disappear anyways.

  2. Anonymous

    thanks a lot for the quick reply!

    how far ahead is the new version? unless it's going to get released in a few days (really, next week max), the documentation could use a short note about the warning. it could save someone an hour of their time.

    regarding grammar polymorphism: what does it do? this part of your reply raises more questions than it answers. :)

  3. Volker Birk repo owner

    I hope, the new version is some days away.

    As you may notice, non-terminal symbols are classes in pyPEG. Well, polymorphism means, there are more possibilities at a decent point in the grammar than just one class, i.e. for an attribute. That can be expressed with an option list, but it can be expressed with a base class, too.

  4. Log in to comment