[pypy-commit] pypy improved_ebnfparse_error: changed assertion to ValueError

nbtaylor noreply at buildbot.pypy.org
Thu Dec 27 23:43:56 CET 2012


Author: Nathan Taylor <nbtaylor at gmail.com>
Branch: improved_ebnfparse_error
Changeset: r59597:2f5063c11b41
Date: 2012-12-27 15:38 -0700
http://bitbucket.org/pypy/pypy/changeset/2f5063c11b41/

Log:	changed assertion to ValueError

diff --git a/pypy/rlib/parsing/ebnfparse.py b/pypy/rlib/parsing/ebnfparse.py
--- a/pypy/rlib/parsing/ebnfparse.py
+++ b/pypy/rlib/parsing/ebnfparse.py
@@ -246,9 +246,10 @@
                     real_expansions.append(expansion)
                     real_changes.append(change)
                     continue
-                assert n != len(expansion), (
-                    "Rule %r's expansion needs at least one "
-                    "symbol with >0 repetitions" % rule.nonterminal)
+                if n == len(expansion):
+                    raise ValueError("Rule %r's expansion needs "
+                        "at least one symbol with >0 repetitions"
+                        % rule.nonterminal)
                 slices = []
                 start = 0
                 for i, (maybe, symbol) in enumerate(
diff --git a/pypy/rlib/parsing/test/test_ebnfparse.py b/pypy/rlib/parsing/test/test_ebnfparse.py
--- a/pypy/rlib/parsing/test/test_ebnfparse.py
+++ b/pypy/rlib/parsing/test/test_ebnfparse.py
@@ -476,5 +476,5 @@
 IGNORE: " ";
 foo: "A"?;
 """
-    excinfo = py.test.raises(AssertionError, parse_ebnf, grammar)
-    assert "Rule 'foo'" in str(excinfo.value)
+    excinfo = py.test.raises(ValueError, parse_ebnf, grammar)
+    assert "foo" in str(excinfo.value)


More information about the pypy-commit mailing list