Author: Alex Gaynor <[email protected]>
Branch: 
Changeset: r59598:9c039c92f0fa
Date: 2012-12-27 14:43 -0800
http://bitbucket.org/pypy/pypy/changeset/9c039c92f0fa/

Log:    Merged in nbtaylor/pypy/improved_ebnfparse_error (pull request #103:
        better message for ebnf empty production error)

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), (
-                    "currently an expansion needs at least one"
-                    "symbol that always has to occur")
+                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
@@ -318,7 +318,7 @@
 """)
     excinfo = py.test.raises(ValueError, make_parse_function, regexs, rules)
     assert "primari" in str(excinfo.value)
- 
+
 def test_starred_star():
     regexs, rules, ToAST = parse_ebnf("""
 IGNORE: " ";
@@ -470,3 +470,11 @@
     t = ToAST().transform(t)
     assert len(t.children) == 6
     excinfo = py.test.raises(ParseError, parse, "a")
+
+def test_zero_repetition_production():
+    grammar = """
+IGNORE: " ";
+foo: "A"?;
+"""
+    excinfo = py.test.raises(ValueError, parse_ebnf, grammar)
+    assert "foo" in str(excinfo.value)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to