[pypy-svn] r38200 - in pypy/dist/pypy/rlib/parsing: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Feb 8 20:18:14 CET 2007


Author: cfbolz
Date: Thu Feb  8 20:18:05 2007
New Revision: 38200

Modified:
   pypy/dist/pypy/rlib/parsing/test/pygrammar.txt
   pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py
   pypy/dist/pypy/rlib/parsing/test/test_pythonparse.py
   pypy/dist/pypy/rlib/parsing/test/test_regexparse.py
   pypy/dist/pypy/rlib/parsing/tree.py
Log:
small changes I had lying around in my working copy


Modified: pypy/dist/pypy/rlib/parsing/test/pygrammar.txt
==============================================================================
--- pypy/dist/pypy/rlib/parsing/test/pygrammar.txt	(original)
+++ pypy/dist/pypy/rlib/parsing/test/pygrammar.txt	Thu Feb  8 20:18:05 2007
@@ -90,16 +90,16 @@
 expr: xor_expr "|" expr | <xor_expr>;
 xor_expr: and_expr "^" xor_expr | <and_expr>;
 and_expr: shift_expr "&" and_expr | <shift_expr>;
-shift_expr: arith_expr "<<" shift_expr |  # was (("<<"|">>") arith_expr)*
-            arith_expr ">>" shift_expr |
+shift_expr: arith_expr ("<<" arith_expr)+ |  # was (("<<"|">>") arith_expr)*
+            arith_expr (">>" arith_expr)+ |
             <arith_expr>;
-arith_expr: term "+" arith_expr |  # was (("+"|"-") term)*
-            term "-" arith_expr |
+arith_expr: term ("+" term)+ |  # was (("+"|"-") term)*
+            term ("-" term)+ |
             <term>;
-term: factor "*" term |  # was (("*"|"/"|"%"|"//") factor)*
-      factor "/" term |
-      factor "%" term |
-      factor "//" term |
+term: factor ("*" term)+ |  # was (("*"|"/"|"%"|"//") factor)*
+      factor ("/" term)+ |
+      factor ("%" term)+ |
+      factor ("//" term)+ |
       <factor>;
 factor: "+" factor | "-" factor | "~" factor | <power>;
 power: atom trailer+ ("**" factor)? | atom "**" factor | <atom>;

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	Thu Feb  8 20:18:05 2007
@@ -181,60 +181,69 @@
 """)
     py.test.raises(AssertionError, make_parse_function, regexs, rules, True)
 
-def test_dictparse():
-    regexs, rules, ToAST = parse_ebnf("""
-    QUOTED_STRING: "'[^\\']*'";
+def test_jsonparse():
+    source = """
+    STRING: "\\"[^\\\\"]*\\"";
+    NUMBER: "\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][\+\-]?[0-9]+)?";
     IGNORE: " |\n";
-    data: <dict> | <QUOTED_STRING> | <list>;
-    dict: ["{"] (dictentry [","])* dictentry ["}"];
-    dictentry: QUOTED_STRING [":"] data;
-    list: ["["] (data [","])* data ["]"];
-""")
+    value: <STRING> | <NUMBER> | <object> | <array> | <"null"> |
+           <"true"> | <"false">;
+    object: ["{"] (entry [","])* entry ["}"];
+    array: ["["] (value [","])* value ["]"];
+    entry: STRING [":"] value;
+"""
+    regexs, rules, ToAST = parse_ebnf(source)
     parse = make_parse_function(regexs, rules, eof=True)
     t = parse("""
 {
-    'type': 'SCRIPT',
-    '0': {
-        'type': 'SEMICOLON',
-        'end': '5',
-        'expression': {
-            'type': 'ASSIGN',
-            '0': {
-                'type': 'IDENTIFIER',
-                'assignOp': 'null',
-                'end': '1',
-                'lineno': '1',
-                'start': '0',
-                'tokenizer': '[object Object]',
-                'value': 'x'
+    "type": "SCRIPT",
+    "0": {
+        "type": "SEMICOLON",
+        "end": "5",
+        "expression": {
+            "type": "ASSIGN",
+            "0": {
+                "type": "IDENTIFIER",
+                "assignOp": "null",
+                "end": "1",
+                "lineno": "1",
+                "start": "0",
+                "tokenizer": "[object Object]",
+                "value": "x"
             } ,
-            '1': {
-                'type': 'NUMBER',
-                'end': '5',
-                'lineno': '1',
-                'start': '4',
-                'tokenizer': '[object Object]',
-                'value': '1'
+            "1": {
+                "type": "NUMBER",
+                "end": "5",
+                "lineno": "1",
+                "start": "4",
+                "tokenizer": "[object Object]",
+                "value": "1"
             } ,
-            'end': '5',
-            'length': '2',
-            'lineno': '1',
-            'start': '0',
-            'tokenizer': '[object Object]',
-            'value': '='
+            "end": "5",
+            "length": "2",
+            "lineno": "1",
+            "start": "0",
+            "tokenizer": "[object Object]",
+            "value": "="
         } ,
-        'lineno': '1',
-        'start': '0',
-        'tokenizer': '[object Object]',
-        'value': 'x'
+        "lineno": "1",
+        "start": "0",
+        "tokenizer": "[object Object]",
+        "value": "x"
     } ,
-    'funDecls': '',
-    'length': '1',
-    'lineno': '1',
-    'tokenizer': '[object Object]',
-    'varDecls': ''
+    "funDecls": "",
+    "length": "1",
+    "lineno": "1",
+    "tokenizer": "[object Object]",
+    "varDecls": ""
 }""")
     t = ToAST().transform(t)
+    t = parse('{"a": "5", "b": [1, null, 3, true, {"f": "g", "h": 6}]}')
+    print "".join(list(t.dot()))
+    t.view()
+    t = ToAST().transform(t)
+    print "\n".join(list(t.dot()))
+    t.view()
 
 def test_starparse():
     regexs, rules, ToAST = parse_ebnf("""

Modified: pypy/dist/pypy/rlib/parsing/test/test_pythonparse.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/test/test_pythonparse.py	(original)
+++ pypy/dist/pypy/rlib/parsing/test/test_pythonparse.py	Thu Feb  8 20:18:05 2007
@@ -231,6 +231,14 @@
         error = excinfo.value.errorinformation
         msg = excinfo.value.nice_error_message("<stdin>", source)
 
+    def test_precedence(self):
+        source = """
+a = 1 - 2 - 3
+"""
+        t = self.parse(source)
+        t = self.ToAST.transform(t)
+        t.view()
+
     def test_parse_this(self):
         s = py.magic.autopath().read()
         t = self.parse(s)

Modified: pypy/dist/pypy/rlib/parsing/test/test_regexparse.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/test/test_regexparse.py	(original)
+++ pypy/dist/pypy/rlib/parsing/test/test_regexparse.py	Thu Feb  8 20:18:05 2007
@@ -138,3 +138,9 @@
     assert r.recognize(r'"a\"b"')
     assert r.recognize(r'"\\\""')
     assert not r.recognize(r'"\\""')
+
+def test_number():
+    r = make_runner(r"\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][\+\-]?[0-9]+)?")
+    assert r.recognize("-0.912E+0001")
+    assert not r.recognize("-0.a912E+0001")
+    assert r.recognize("5")

Modified: pypy/dist/pypy/rlib/parsing/tree.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/tree.py	(original)
+++ pypy/dist/pypy/rlib/parsing/tree.py	Thu Feb  8 20:18:05 2007
@@ -24,7 +24,7 @@
         addinfo = str(self.additional_info).replace('"', "'") or "_"
         yield ('"%s" [shape=box,label="%s\\n%s"];' % (
             id(self), self.symbol.replace("\\", "\\\\"),
-            repr(addinfo).replace("\\", "\\\\")))
+            repr(addinfo).replace('"', '').replace("\\", "\\\\")))
 
     def visit(self, visitor):
         "NOT_RPYTHON"



More information about the Pypy-commit mailing list