[pypy-svn] r42654 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Fri May 4 01:31:25 CEST 2007
Author: santagada
Date: Fri May 4 01:31:24 2007
New Revision: 42654
Modified:
pypy/dist/pypy/lang/js/jsgrammar.txt
pypy/dist/pypy/lang/js/newparser.py
pypy/dist/pypy/lang/js/test/test_new_parser.py
Log:
testing almost everything of the parser.... should start the trasition to this parser tomorrow
Modified: pypy/dist/pypy/lang/js/jsgrammar.txt
==============================================================================
--- pypy/dist/pypy/lang/js/jsgrammar.txt (original)
+++ pypy/dist/pypy/lang/js/jsgrammar.txt Fri May 4 01:31:24 2007
@@ -22,11 +22,11 @@
| <continuestatement> [";"]
| <breakstatement> [";"]
| <returnstatement> [";"]
- | <withstatement> [";"]
+ | <withstatement>
| <labelledstatement>
- | <switchstatement>
+ | <switchstatement> [";"]?
| <throwstatement> [";"]
- | <trystatement> [";"]
+ | <trystatement>
;
block : ["{"] statementlist? ["}"]
@@ -96,7 +96,7 @@
# CaseClauses :
# CaseClause
# CaseClauses CaseClause
-caseclauses : caseclause+
+caseclauses : >caseclause<+
;
caseclause : ["case"] expression [":"] statementlist?
@@ -174,14 +174,14 @@
;
objectliteral : ["{"] ["}"]
- | ["{"] propertynameandvaluelist ["}"]
+ | ["{"] >propertynameandvaluelist< ["}"]
;
-propertynameandvaluelist : hpropertynameandvaluelist* propertyname ":" assignmentexpression
+propertynameandvaluelist : propertynameandvalue ([","] propertynameandvalue)*
;
-hpropertynameandvaluelist : propertyname ":" assignmentexpression ","
- ;
+propertynameandvalue : propertyname [":"] assignmentexpression
+ ;
propertyname : <identifier>
| <stringliteral>
Modified: pypy/dist/pypy/lang/js/newparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/newparser.py (original)
+++ pypy/dist/pypy/lang/js/newparser.py Fri May 4 01:31:24 2007
@@ -15,8 +15,10 @@
newrules = [Rule("hacked_first_symbol", [[start, "EOF"]])] + rules
return newrules
-parse = make_parse_function(regexs, rules, eof=True)
-#parse = make_parse_function(regexs, rules)
+if len(sys.argv) == 1:
+ parse = make_parse_function(regexs, rules, eof=True)
+else:
+ parse = make_parse_function(regexs, setstartrule(rules,sys.argv[1]), eof=True)
print rules[2].nonterminal
source = raw_input()
Modified: pypy/dist/pypy/lang/js/test/test_new_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_new_parser.py (original)
+++ pypy/dist/pypy/lang/js/test/test_new_parser.py Fri May 4 01:31:24 2007
@@ -168,7 +168,23 @@
"2 << 4 << 4",
"30 | 3 & 5",
])
-
+
+ def test_primary(self):
+ self.parse('this')
+ self.parse('(x)')
+ self.parse('((((x))))')
+ self.parse('(x * (x * x)) + x - x')
+
+ def test_array_literal(self):
+ self.parse('[1,2,3,4]')
+ self.parse('[1,2,]')
+ self.parse('[1]')
+
+ def test_object_literal(self):
+ self.parse('{}')
+ self.parse('{x:1}') #per spec {x:1,} should not be supported
+ self.parse('{x:1,y:2}')
+
class TestStatements(BaseGrammarTest):
def setup_class(cls):
cls.parse = parse_func('statement')
@@ -216,16 +232,41 @@
self.parse('while(1);')
self.parse('do ; while(1)')
- def test_continue_return_break(self):
+ def test_continue_return_break_throw(self):
self.parse('return;')
self.parse('return x+y;')
self.parse('break;')
self.parse('continue;')
self.parse('break label;')
self.parse('continue label;')
+ self.parse('throw (5+5);')
+ def test_with(self):
+ self.parse('with(x);')
+
def test_labeled(self):
self.parse('label: x+y;')
+
+ def test_switch(self):
+ self.parse("""switch(x) {
+ case 1: break;
+ case 2: break;
+ default: ;
+ }
+
+ """)
+ self.parse("""switch(x) {
+ case 1: break;
+ case 2: break;
+ default: ;
+ case 3: break;
+ }
+
+ """)
+ def test_try(self):
+ self.parse('try {x;} catch (e) {x;}')
+ self.parse('try {x;} catch (e) {x;} finally {x;}')
+ self.parse('try {x;} finally {x;}')
class TestFunctionDeclaration(BaseGrammarTest):
def setup_class(cls):
More information about the Pypy-commit
mailing list