Commits

Anonymous committed eeb4fc7

BUG: usage of how_many() function in tuple/Concat parsing missing

  • Participants
  • Parent commits 16f726c

Comments (0)

Files changed (2)

File pypeg2/__init__.py

             else:
                 result = text, syntax_error("expecting " + repr(thing))
 
-        elif _issubclass(thing, Symbol) and not has_grammar(thing):
+        elif _issubclass(thing, Symbol):
             m = thing.regex.match(text)
             if m:
                 result = None
                 except AttributeError:
                     pass
                 else:
-                    if isinstance(thing.grammar, Enum):
+                    if thing.grammar is None:
+                        pass
+                    elif isinstance(thing.grammar, Enum):
                         if not m.group(0) in thing.grammar:
                             result = text, syntax_error(repr(m.group(0))
                                 + " is not a member of " + repr(thing.grammar))
+                    else:
+                        raise GrammarValueError(
+                                "Symbol " + type(thing).__name__
+                                + " has a grammar which is not an Enum: "
+                                + repr(thing.grammar))
                 if not result:
                     t, r = text[len(m.group(0)):], thing(m.group(0))
                     t = self._skip(t)
                     break
                 _min, _max = 1, 1
             if flag:
-                result = t, L
+                if len(L) == 0:
+                    return t, None
+                elif len(L) > 1 or how_many(thing) > 1:
+                    result = t, L
+                else:
+                    result = t, L[0]
             else:
                 result = text, r
 

File pypeg2/test/test_pyPEG2.py

     def runTest(self):
         parser = pypeg2.Parser()
         r = parser.parse("hello, world", pypeg2.maybe_some(re.compile(r"\d")))
-        self.assertEqual(r, ('hello, world', []))
+        self.assertEqual(r, ('hello, world', None))
 
 class ParseCardinalityTestCase1(ParserTestCase):
     def runTest(self):