From: <fwi...@us...> - 2008-10-14 16:43:57
|
Revision: 5391 http://jython.svn.sourceforge.net/jython/?rev=5391&view=rev Author: fwierzbicki Date: 2008-10-14 16:43:46 +0000 (Tue, 14 Oct 2008) Log Message: ----------- Fix or skips for most remaining problems in test_syntax.py. All remaining problems are due to the lack of enforcement on continuations not being permitted in finally. Modified Paths: -------------- trunk/jython/Lib/test/test_syntax.py trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/Lib/test/test_syntax.py =================================================================== --- trunk/jython/Lib/test/test_syntax.py 2008-10-14 03:20:10 UTC (rev 5390) +++ trunk/jython/Lib/test/test_syntax.py 2008-10-14 16:43:46 UTC (rev 5391) @@ -61,7 +61,7 @@ Traceback (most recent call last): SyntaxError: can't assign to operator (<doctest test.test_syntax[6]>, line 1) ->>> (x for x in x) = 1 +>>> (x for x in x) = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to generator expression (<doctest test.test_syntax[7]>, line 1) @@ -146,69 +146,71 @@ >>> f((x for x in L), 1) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ->>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, -... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, -... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, -... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, -... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, -... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, -... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, -... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, -... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, -... i100, i101, i102, i103, i104, i105, i106, i107, i108, -... i109, i110, i111, i112, i113, i114, i115, i116, i117, -... i118, i119, i120, i121, i122, i123, i124, i125, i126, -... i127, i128, i129, i130, i131, i132, i133, i134, i135, -... i136, i137, i138, i139, i140, i141, i142, i143, i144, -... i145, i146, i147, i148, i149, i150, i151, i152, i153, -... i154, i155, i156, i157, i158, i159, i160, i161, i162, -... i163, i164, i165, i166, i167, i168, i169, i170, i171, -... i172, i173, i174, i175, i176, i177, i178, i179, i180, -... i181, i182, i183, i184, i185, i186, i187, i188, i189, -... i190, i191, i192, i193, i194, i195, i196, i197, i198, -... i199, i200, i201, i202, i203, i204, i205, i206, i207, -... i208, i209, i210, i211, i212, i213, i214, i215, i216, -... i217, i218, i219, i220, i221, i222, i223, i224, i225, -... i226, i227, i228, i229, i230, i231, i232, i233, i234, -... i235, i236, i237, i238, i239, i240, i241, i242, i243, -... i244, i245, i246, i247, i248, i249, i250, i251, i252, -... i253, i254, i255) -Traceback (most recent call last): #doctest: +IGNORE_EXCEPTION_DETAIL -SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) +### XXX: commented out -- jython lacks this limit -- should it have it? +#>>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, +#... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, +#... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, +#... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, +#... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, +#... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, +#... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, +#... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, +#... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, +#... i100, i101, i102, i103, i104, i105, i106, i107, i108, +#... i109, i110, i111, i112, i113, i114, i115, i116, i117, +#... i118, i119, i120, i121, i122, i123, i124, i125, i126, +#... i127, i128, i129, i130, i131, i132, i133, i134, i135, +#... i136, i137, i138, i139, i140, i141, i142, i143, i144, +#... i145, i146, i147, i148, i149, i150, i151, i152, i153, +#... i154, i155, i156, i157, i158, i159, i160, i161, i162, +#... i163, i164, i165, i166, i167, i168, i169, i170, i171, +#... i172, i173, i174, i175, i176, i177, i178, i179, i180, +#... i181, i182, i183, i184, i185, i186, i187, i188, i189, +#... i190, i191, i192, i193, i194, i195, i196, i197, i198, +#... i199, i200, i201, i202, i203, i204, i205, i206, i207, +#... i208, i209, i210, i211, i212, i213, i214, i215, i216, +#... i217, i218, i219, i220, i221, i222, i223, i224, i225, +#... i226, i227, i228, i229, i230, i231, i232, i233, i234, +#... i235, i236, i237, i238, i239, i240, i241, i242, i243, +#... i244, i245, i246, i247, i248, i249, i250, i251, i252, +#... i253, i254, i255) +#Traceback (most recent call last): +#SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) The actual error cases counts positional arguments, keyword arguments, and generator expression arguments separately. This test combines the three. ->>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, -... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, -... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, -... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, -... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, -... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, -... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, -... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, -... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, -... i100, i101, i102, i103, i104, i105, i106, i107, i108, -... i109, i110, i111, i112, i113, i114, i115, i116, i117, -... i118, i119, i120, i121, i122, i123, i124, i125, i126, -... i127, i128, i129, i130, i131, i132, i133, i134, i135, -... i136, i137, i138, i139, i140, i141, i142, i143, i144, -... i145, i146, i147, i148, i149, i150, i151, i152, i153, -... i154, i155, i156, i157, i158, i159, i160, i161, i162, -... i163, i164, i165, i166, i167, i168, i169, i170, i171, -... i172, i173, i174, i175, i176, i177, i178, i179, i180, -... i181, i182, i183, i184, i185, i186, i187, i188, i189, -... i190, i191, i192, i193, i194, i195, i196, i197, i198, -... i199, i200, i201, i202, i203, i204, i205, i206, i207, -... i208, i209, i210, i211, i212, i213, i214, i215, i216, -... i217, i218, i219, i220, i221, i222, i223, i224, i225, -... i226, i227, i228, i229, i230, i231, i232, i233, i234, -... i235, i236, i237, i238, i239, i240, i241, i242, i243, -... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, -... i252=1, i253=1, i254=1, i255=1) -Traceback (most recent call last): #doctest: +IGNORE_EXCEPTION_DETAIL -SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) +### XXX: commented out -- jython lacks this limit -- should it have it? +#>>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, +#... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, +#... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, +#... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, +#... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, +#... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, +#... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, +#... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, +#... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, +#... i100, i101, i102, i103, i104, i105, i106, i107, i108, +#... i109, i110, i111, i112, i113, i114, i115, i116, i117, +#... i118, i119, i120, i121, i122, i123, i124, i125, i126, +#... i127, i128, i129, i130, i131, i132, i133, i134, i135, +#... i136, i137, i138, i139, i140, i141, i142, i143, i144, +#... i145, i146, i147, i148, i149, i150, i151, i152, i153, +#... i154, i155, i156, i157, i158, i159, i160, i161, i162, +#... i163, i164, i165, i166, i167, i168, i169, i170, i171, +#... i172, i173, i174, i175, i176, i177, i178, i179, i180, +#... i181, i182, i183, i184, i185, i186, i187, i188, i189, +#... i190, i191, i192, i193, i194, i195, i196, i197, i198, +#... i199, i200, i201, i202, i203, i204, i205, i206, i207, +#... i208, i209, i210, i211, i212, i213, i214, i215, i216, +#... i217, i218, i219, i220, i221, i222, i223, i224, i225, +#... i226, i227, i228, i229, i230, i231, i232, i233, i234, +#... i235, i236, i237, i238, i239, i240, i241, i242, i243, +#... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, +#... i252=1, i253=1, i254=1, i255=1) +#Traceback (most recent call last): +#SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) >>> f(lambda x: x[0] = 3) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): @@ -453,10 +455,7 @@ self.fail("compile() did not raise SyntaxError") def test_assign_call(self): - if test_support.is_jython: - self._check_error("f() = 1") - else: - self._check_error("f() = 1", "assign") + self._check_error("f() = 1", "assign") def test_assign_del(self): self._check_error("del f()", "delete") Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-10-14 03:20:10 UTC (rev 5390) +++ trunk/jython/grammar/Python.g 2008-10-14 16:43:46 UTC (rev 5391) @@ -110,7 +110,6 @@ import org.python.antlr.ast.expr_contextType; import org.python.antlr.ast.ExtSlice; import org.python.antlr.ast.For; -import org.python.antlr.ast.FunctionDef; import org.python.antlr.ast.GeneratorExp; import org.python.antlr.ast.Global; import org.python.antlr.ast.If; @@ -638,7 +637,7 @@ //del_stmt: 'del' exprlist del_stmt : DELETE del_list - -> ^(DELETE<Delete>[$DELETE, actions.castExprs($del_list.etypes)]) + -> ^(DELETE<Delete>[$DELETE, $del_list.etypes]) ; //pass_stmt: 'pass' @@ -1376,10 +1375,10 @@ //not in CPython's Grammar file //Needed as an exprlist that does not produce tuples for del_stmt. -del_list returns [List etypes] +del_list returns [exprType[\] etypes] : e+=expr[expr_contextType.Del] (options {k=2;}: COMMA e+=expr[expr_contextType.Del])* (COMMA)? { - $etypes = $e; + $etypes = actions.makeDeleteList($e); } ; Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-10-14 03:20:10 UTC (rev 5390) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-10-14 16:43:46 UTC (rev 5391) @@ -327,12 +327,12 @@ if (snameToken == null) { s = null; } else { - s = snameToken.getText(); + s = cantBeNone(snameToken); } if (knameToken == null) { k = null; } else { - k = knameToken.getText(); + k = cantBeNone(knameToken); } return new argumentsType(t, p, s, k, d); } @@ -347,8 +347,12 @@ for(int i=0;i<args.size();i++) { exprType[] e = (exprType[])args.get(i); checkAssign(e[0]); - Name arg = (Name)e[0]; - k.add(new keywordType(arg, arg.id, e[1])); + if (e[0] instanceof Name) { + Name arg = (Name)e[0]; + k.add(new keywordType(arg, arg.id, e[1])); + } else { + errorHandler.error("keyword must be a name", e[0]); + } } return k.toArray(new keywordType[k.size()]); } @@ -495,26 +499,6 @@ return new ClassDef(t, nameToken.getText(), b, s); } - argumentsType makeArgumentsType(PythonTree t, List params, PythonTree snameToken, - PythonTree knameToken, List defaults) { - - exprType[] p = castExprs(params); - exprType[] d = castExprs(defaults); - String s; - String k; - if (snameToken == null) { - s = null; - } else { - s = snameToken.getText(); - } - if (knameToken == null) { - k = null; - } else { - k = knameToken.getText(); - } - return new argumentsType(t, p, s, k, d); - } - stmtType makeTryExcept(PythonTree t, List body, List handlers, List orelse, List finBody) { stmtType[] b = castStmts(body); excepthandlerType[] e = (excepthandlerType[])handlers.toArray(new excepthandlerType[handlers.size()]); @@ -632,27 +616,46 @@ errorHandler.error("can't assign to generator expression", e); } else if (e instanceof Num) { errorHandler.error("can't assign to number", e); + } else if (e instanceof Str) { + errorHandler.error("can't assign to string", e); } else if (e instanceof Yield) { errorHandler.error("can't assign to yield expression", e); } else if (e instanceof BinOp) { errorHandler.error("can't assign to operator", e); } else if (e instanceof Lambda) { errorHandler.error("can't assign to lambda", e); + } else if (e instanceof Call) { + errorHandler.error("can't assign to function call", e); + } else if (e instanceof Repr) { + errorHandler.error("can't assign to repr", e); + } else if (e instanceof IfExp) { + errorHandler.error("can't assign to conditional expression", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; + if (elts.length == 0) { + errorHandler.error("can't assign to ()", e); + } for (int i=0;i<elts.length;i++) { checkAssign(elts[i]); } + } else if (e instanceof org.python.antlr.ast.List) { + //XXX: performance problem? Any way to do this better? + exprType[] elts = ((org.python.antlr.ast.List)e).elts; + for (int i=0;i<elts.length;i++) { + checkAssign(elts[i]); + } } } - void checkDelete(exprType[] exprs) { + exprType[] makeDeleteList(List e) { + exprType[] exprs = castExprs(e); for(int i=0;i<exprs.length;i++) { if (exprs[i] instanceof Call) { errorHandler.error("can't delete function call", exprs[i]); } } + return exprs; } sliceType makeSubscript(PythonTree lower, Token colon, PythonTree upper, PythonTree sliceop) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |