Commits

Volker Birk  committed bbd958e

bugfix: composing if grammar is default grammar

  • Participants
  • Parent commits 5426438

Comments (0)

Files changed (4)

File docs/heading.en.yinc2

 div id="headline" {
     p > pyPEG – a PEG Parser-Interpreter in Python
     div class="small" {
-        "pyPEG 2.6.1 of Th Jun 21 2012 – Copyleft 2009-2012, "
+        "pyPEG 2.7.0 of We Jun 27 2012 – Copyleft 2009-2012, "
         a "http://fdik.org", "Volker Birk";
     }
     div id=python1 p

File pypeg2/__init__.py

     pass
 
 
-__version__ = 2.6
+__version__ = 2.7
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
     """
     if __debug__:
         if isinstance(thing, tuple):
-            warnings.warn(type(thing).__name__ + " not recommended as grammar of attribute "
+            warnings.warn(type(thing).__name__
+                    + " not recommended as grammar of attribute "
                     + repr(name), SyntaxWarning)
     return attr.Class(name, thing, subtype)
 
 
     def __repr__(self):
         if isinstance(self, Literal._basic_types):
-            return type(self).__name__ + "(" + super(Literal, self).__repr__() + ")"
+            return type(self).__name__ + "(" + \
+                    super(Literal, self).__repr__() + ")"
         else:
             return type(self).__name__ + "(" + repr(self.value) + ")"
 
 
     def __repr__(self):
         """x.__repr__() <==> repr(x)"""
-        return ''.join((type(self).__name__, "(", super(List, self).__repr__(), ")"))
+        return ''.join((type(self).__name__, "(", super(List, self).__repr__(),
+            ")"))
 
 
 class _UserDict(object):
         return length
 
     elif isinstance(grammar, list):
-        return reduce(lambda a, b: max(how_many(a), how_many(b)), grammar)
+        m = 0
+        for e in grammar:
+            m = max(m, how_many(e))
+            if m == 2:
+                return m
+        return m
 
     elif _issubclass(grammar, object):
         return 1
                 if isinstance(r, thing):
                     result = t, r
                 else:
-                    if type(r) == list:
-                        L, a = [], []
-                        for e in r:
-                            if type(e) == attr.Class:
-                                a.append(e)
+                    try:
+                        if type(r) == list:
+                            L, a = [], []
+                            for e in r:
+                                if type(e) == attr.Class:
+                                    a.append(e)
+                                else:
+                                    L.append(e)
+                            if L:
+                                lg = how_many(thing.grammar)
+                                if lg == 0:
+                                    obj = None
+                                elif lg == 1:
+                                    obj = thing(L[0])
+                                else:
+                                    obj = thing(L)
                             else:
-                                L.append(e)
-                        if L:
-                            lg = how_many(thing.grammar)
-                            if lg == 0:
-                                obj = None
-                            elif lg == 1:
-                                obj = thing(L[0])
+                                obj = thing()
+                            for e in a:
+                                setattr(obj, e.name, e.thing)
+                        else:
+                            if type(r) == attr.Class:
+                                obj = thing()
+                                setattr(obj, r.name, r.thing)
                             else:
-                                obj = thing(L)
-                        else:
-                            obj = thing()
-                        for e in a:
-                            setattr(obj, e.name, e.thing)
-                    else:
-                        if type(r) == attr.Class:
-                            obj = thing()
-                            setattr(obj, r.name, r.thing)
-                        else:
-                            if r is None:
-                                obj = thing()
-                            else:
-                                obj = thing(r)
+                                if r is None:
+                                    obj = thing()
+                                else:
+                                    obj = thing(r)
+                    except TypeError as t:
+                        L = list(t.args)
+                        L[0] = thing.__name__ + ": " + L[0]
+                        t.args = tuple(L)
+                        raise t
                     try:
                         obj.polish()
                     except AttributeError:
                             if grammar contains an illegal cardinality value
         """
         if __debug__:
-            # make sure that we're not having this type error
+            # make sure that we're not having this typing error
             compose = None
 
         def terminal_indent(do_blank=False):
                     elif type(g) == int:
                         if g < -5:
                             raise GrammarValueError(
-                                "illegal cardinality value in grammar: " +
-                                str(g)
-                            )
+                                "illegal cardinality value in grammar: "
+                                + str(g))
                         card = g
                         if g in (-2, -1):
                             multiple = sys.maxsize
                 else:
                     result = self.compose(thing, grammar.grammar)
             else:
-                raise ValueError(repr(thing) + " is not a " + repr(grammar))
+                if grammar == Symbol and isinstance(thing, str):
+                    result = self.compose(str(thing), Symbol.regex)
+                else:
+                    raise ValueError(repr(thing) + " is not a " + repr(grammar))
 
         else:
             raise GrammarTypeError("in grammar: " + repr(grammar))

File pypeg2/xmlast.py

     pass
 
 
-__version__ = 2.6
+__version__ = 2.7
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
 
 setup(
     name='pyPEG2',
-    version='2.6.1',
+    version='2.7.0',
     author='Volker Birk',
     author_email='vb@dingens.org',
     packages=['pypeg2', 'pypeg2.test'],