[Jython-checkins] jython: Add with_item.
frank.wierzbicki
jython-checkins at python.org
Wed Mar 7 05:24:07 CET 2012
http://hg.python.org/jython/rev/a75007ed1f48
changeset: 6310:a75007ed1f48
parent: 6308:e49a734162b9
user: Frank Wierzbicki <fwierzbicki at gmail.com>
date: Tue Mar 06 11:28:51 2012 -0800
summary:
Add with_item.
files:
grammar/Python.g | 18 +++++++++--
src/org/python/antlr/GrammarActions.java | 7 ++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/grammar/Python.g b/grammar/Python.g
--- a/grammar/Python.g
+++ b/grammar/Python.g
@@ -1171,17 +1171,27 @@
@after {
$with_stmt.tree = stype;
}
- : WITH test[expr_contextType.Load] (with_var)? COLON suite[false]
+ : WITH with_item COLON suite[false]
{
- stype = new With($WITH, actions.castExpr($test.tree), $with_var.etype,
+ stype = new With($WITH, $with_item.item, $with_item.var,
actions.castStmts($suite.stypes));
}
;
-//with_var: ('as' | NAME) expr
+//with_item: test ['as' expr]
+with_item
+ returns [expr item, expr var]
+ : test[expr_contextType.Load] (with_var)?
+ {
+ $item = actions.castExpr($test.tree);
+ $var = $with_var.etype;
+ }
+ ;
+
+//with_var: 'as' expr
with_var
returns [expr etype]
- : (AS | NAME) expr[expr_contextType.Store]
+ : AS expr[expr_contextType.Store]
{
$etype = actions.castExpr($expr.tree);
actions.checkAssign($etype);
diff --git a/src/org/python/antlr/GrammarActions.java b/src/org/python/antlr/GrammarActions.java
--- a/src/org/python/antlr/GrammarActions.java
+++ b/src/org/python/antlr/GrammarActions.java
@@ -41,6 +41,7 @@
import org.python.antlr.ast.Str;
import org.python.antlr.ast.UnaryOp;
import org.python.antlr.ast.While;
+import org.python.antlr.ast.With;
import org.python.antlr.ast.Yield;
import org.python.antlr.base.excepthandler;
import org.python.antlr.base.expr;
@@ -240,6 +241,12 @@
return new While(t, test, b, o);
}
+ stmt makeWith(Token t, List<stmt> withs, List<stmt> body) {
+ With w = (With)withs.get(0);
+ With result = new With(t, w.getInternalContext_expr(), w.getInternalOptional_vars(), w.getInternalBody());
+ return result;
+ }
+
stmt makeFor(Token t, expr target, expr iter, List body, List orelse) {
if (target == null || iter == null) {
return errorHandler.errorStmt(new PythonTree(t));
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list