[pypy-svn] r34868 - pypy/dist/pypy/rlib/parsing/test

radix at codespeak.net radix at codespeak.net
Wed Nov 22 18:20:04 CET 2006


Author: radix
Date: Wed Nov 22 18:20:03 2006
New Revision: 34868

Modified:
   pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py
Log:
at risk of being flamed - a failing (skipped) unit test for buggy auto-generated transformer

The problem is that a rule like:

  list: "(" sexpr* ")";

generates a visit_list method that assumes there will always be three children,
but in reality there can be two or three.



Modified: pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py	(original)
+++ pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py	Wed Nov 22 18:20:03 2006
@@ -260,6 +260,29 @@
     assert [c.symbol for c in t.children[0].children] == ["QUOTED_STRING"] * 2
     t = parse("['a']")
 
+def test_transform_star():
+    py.test.skip("This needs to be fixed - generated transformer is buggy")
+    regexs, rules, transformer = parse_ebnf("""
+    IGNORE: " ";
+    ATOM: "[\+a-zA-Z_][a-zA-Z0-9_]*";
+
+    sexpr: ATOM | list;
+    list: "(" sexpr* ")";
+""")
+    parse = make_parse_function(regexs, rules)
+    tree = parse("()")
+    print transformer
+    ns = {"RPythonVisitor": RPythonVisitor, "Nonterminal": Nonterminal}
+    exec py.code.Source(transformer).compile() in ns
+    ToAST = ns["ToAST"]
+    list_expr = tree.visit(ToAST()).children[0]
+    assert list_expr.symbol == 'list'
+    # should have two children, "(" and ")"
+    assert len(list_expr.children) == 2
+    assert list_expr.children[0].symbol == '('
+    assert list_expr.children[1].symbol == ')'
+
+
 def test_quoting():
     regexs, rules, transformer = parse_ebnf("""
     ATOM: "[a-z]*";



More information about the Pypy-commit mailing list