@@ -126,8 +126,8 @@ public abstract class AST
             private PythonTuple __attributes = new PythonTuple();   // Genshi assumes _fields in not None
             protected int? _lineno; // both lineno and col_offset are expected to be int, in cpython anything is accepted
             protected int? _col_offset;
-            protected ScopeStatement _parent;
-            protected SourceSpan _span;
+            protected ScopeStatement _parent; // Stores the parent for the span when reverting back to Node objects.
+            protected SourceSpan _span; // Stores the span to attach when reverting back to Node objects.
 
             public PythonTuple _fields {
                 get { return __fields; }
@@ -632,13 +632,13 @@ internal arguments(Parameter[] parameters)
                 int argIdx = args.Count - 1;
                 for (int defIdx = defaults.Count - 1; defIdx >= 0; defIdx--, argIdx--) {
                     Name name = (Name)args[argIdx];
-                    Parameter p = new Parameter(name.id);
+                    Parameter p = name.AttachLoc(new Parameter(name.id));
                     p.DefaultValue = expr.Revert(defaults[defIdx]);
                     parameters.Add(p);
                 }
                 while (argIdx >= 0) {
                     Name name = (Name)args[argIdx--];
-                    parameters.Add(new Parameter(name.id));
+                    parameters.Add(name.AttachLoc(new Parameter(name.id)));
                 }
                 parameters.Reverse();
                 if (vararg != null)
@@ -777,18 +777,23 @@ public abstract class expr : AST
             internal virtual AstExpression Revert() {
                 throw PythonOps.TypeError("Unexpected expr type: {0}", GetType());
             }
+            
+            protected AstExpression AttachLoc(AstExpression other) {
+                other.SetLoc(_parent as PythonAst, _span.Start.Index, _span.End.Index);
+                return other;
+            }
 
             internal static AstExpression Revert(expr ex) {
                 if (ex == null)
                     return null;
-                return ex.Revert();
+                return ex.AttachLoc(ex.Revert());
             }
 
             internal static AstExpression Revert(object ex) {
                 if (ex == null)
                     return null;
                 Debug.Assert(ex is expr);
-                return ((expr)ex).Revert();
+                return Revert((expr)ex);
             }
 
             internal static AstExpression[] RevertExprs(PythonList exprs) {
@@ -881,6 +886,11 @@ public abstract class @operator : AST
         [PythonType]
         public abstract class slice : AST
         {
+            public AstExpression AttachLoc(AstExpression other)
+            {
+                other.SetLoc(_parent as PythonAst, _span.Start.Index, _span.End.Index);
+                return other;
+            }
         }
 
         [PythonType]
@@ -893,6 +903,11 @@ public abstract class stmt : AST
             internal virtual Statement Revert() {
                 throw PythonOps.TypeError("Unexpected statement type: {0}", GetType());
             }
+            
+            protected Statement AttachLoc(Statement other) {
+                other.SetLoc(_parent as PythonAst, _span.Start.Index, _span.End.Index);
+                return other;
+            }
 
             internal static Statement RevertStmts(PythonList stmts) {
                 if (stmts.Count == 1)
@@ -958,7 +973,7 @@ internal Assert(AssertStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new AssertStatement(expr.Revert(test), expr.Revert(msg));
+                return AttachLoc(new AssertStatement(expr.Revert(test), expr.Revert(msg)));
             }
 
             public expr test {
@@ -1000,7 +1015,7 @@ internal Assign(AssignmentStatement stmt)
             }
             
             internal override Statement Revert() {
-                return new AssignmentStatement(expr.RevertExprs(targets), expr.Revert(value));
+                return AttachLoc(new AssignmentStatement(expr.RevertExprs(targets), expr.Revert(value)));
             }
 
             public PythonList targets {
@@ -1043,7 +1058,7 @@ internal Attribute(MemberExpression attr, expr_context ctx)
             }
          
             internal override AstExpression Revert() {
-                return new MemberExpression(expr.Revert(value), attr);
+                return AttachLoc(new MemberExpression(expr.Revert(value), attr));
             }
 
             public expr value {
@@ -1091,7 +1106,7 @@ internal AugAssign(AugmentedAssignStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new AugmentedAssignStatement(op.Revert(), expr.Revert(target), expr.Revert(value));
+                return AttachLoc(new AugmentedAssignStatement(op.Revert(), expr.Revert(target), expr.Revert(value)));
             }
 
             public expr target {
@@ -1154,7 +1169,7 @@ internal BinOp(BinaryExpression expr, @operator op)
             }
 
             internal override AstExpression Revert() {
-                return new BinaryExpression(op.Revert(), expr.Revert(left), expr.Revert(right));
+                return AttachLoc(new BinaryExpression(op.Revert(), expr.Revert(left), expr.Revert(right)));
             }
 
             public expr left {
@@ -1261,7 +1276,7 @@ internal Break()
             }
 
             internal override Statement Revert() {
-                return new BreakStatement();
+                return AttachLoc(new BreakStatement());
             }
         }
 
@@ -1392,7 +1407,7 @@ internal ClassDef(ClassDefinition def)
                 ClassDefinition cd = new ClassDefinition(name, expr.RevertExprs(bases), RevertStmts(body));
                 if (decorator_list.Count != 0) 
                     cd.Decorators = expr.RevertExprs(decorator_list);
-                return cd;
+                return AttachLoc(cd);
             }
 
             public string name {
@@ -1513,7 +1528,7 @@ internal Continue()
             }
 
             internal override Statement Revert() {
-                return new ContinueStatement();
+                return AttachLoc(new ContinueStatement());
             }
         }
 
@@ -1547,7 +1562,7 @@ internal Delete(DelStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new DelStatement(expr.RevertExprs(targets));
+                return AttachLoc(new DelStatement(expr.RevertExprs(targets)));
             }
 
             public PythonList targets {
@@ -1704,9 +1719,14 @@ internal ExceptHandler(TryStatementHandler stmt)
 
                 _body = ConvertStatements(stmt.Body);
             }
+            
+            protected TryStatementHandler AttachLoc(TryStatementHandler other) {
+                other.SetLoc(_parent as PythonAst, _span.Start.Index, _span.End.Index);
+                return other;
+            }
 
             internal TryStatementHandler RevertHandler() {
-                return new TryStatementHandler(expr.Revert(type), expr.Revert(name), stmt.RevertStmts(body));
+                return AttachLoc(new TryStatementHandler(expr.Revert(type), expr.Revert(name), stmt.RevertStmts(body)));
             }
 
             public expr type {
@@ -1756,7 +1776,7 @@ public Exec(ExecStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new ExecStatement(expr.Revert(body), expr.Revert(locals), expr.Revert(globals));
+                return AttachLoc(new ExecStatement(expr.Revert(body), expr.Revert(locals), expr.Revert(globals)));
             }
 
             public expr body {
@@ -1797,7 +1817,7 @@ internal Expr(ExpressionStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new ExpressionStatement(expr.Revert(value));
+                return AttachLoc(new ExpressionStatement(expr.Revert(value)));
             }
 
             public expr value {
@@ -1903,7 +1923,7 @@ internal For(ForStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new ForStatement(expr.Revert(target), expr.Revert(iter), RevertStmts(body), RevertStmts(orelse));
+                return AttachLoc(new ForStatement(expr.Revert(target), expr.Revert(iter), RevertStmts(body), RevertStmts(orelse)));
             }
 
             public expr target {
@@ -1970,7 +1990,7 @@ internal FunctionDef(FunctionDefinition def)
                 _containsYield = false;
                 if (decorator_list.Count != 0)
                     fd.Decorators = expr.RevertExprs(decorator_list);
-                return fd;
+                return AttachLoc(fd);
             }
 
             public string name {
@@ -2148,7 +2168,7 @@ internal Global(GlobalStatement stmt)
                 string[] newNames = new string[names.Count];
                 for (int i = 0; i < names.Count; i++)
                     newNames[i] = (string)names[i];
-                return new GlobalStatement(newNames);
+                return AttachLoc(new GlobalStatement(newNames));
             }
 
             public PythonList names {
@@ -2225,7 +2245,7 @@ internal If(IfStatement stmt)
                     tests.Add(new IfStatementTest(expr.Revert(orelse.test), RevertStmts(orelse.body)));
                     currIf = orelse;
                 }
-                return new IfStatement(tests.ToArray(), RevertStmts(currIf.orelse));
+                return AttachLoc(new IfStatement(tests.ToArray(), RevertStmts(currIf.orelse)));
             }
 
             public expr test {
@@ -2323,7 +2343,7 @@ internal Import(ImportStatement stmt)
                     moduleNames[i] = new ModuleName(alias.name.Split(MODULE_NAME_SPLITTER));
                     asNames[i] = alias.asname;
                 }
-                return new ImportStatement(moduleNames, asNames, false);  // TODO: not so sure about the relative/absolute argument here
+                return AttachLoc(new ImportStatement(moduleNames, asNames, false));  // TODO: not so sure about the relative/absolute argument here
             }
 
             public PythonList names {
@@ -2374,7 +2394,7 @@ public ImportFrom(FromImportStatement stmt)
                     }
 
                 if (names.Count == 1 && ((alias)names[0]).name == "*")
-                    return new FromImportStatement(root, (string[])FromImportStatement.Star, null, false, absolute);
+                    return AttachLoc(new FromImportStatement(root, (string[])FromImportStatement.Star, null, false, absolute));
 
                 String[] newNames = new String[names.Count];
                 String[] asNames = new String[names.Count];
@@ -2383,7 +2403,7 @@ public ImportFrom(FromImportStatement stmt)
                     newNames[i] = alias.name;
                     asNames[i] = alias.asname;
                 }
-                return new FromImportStatement(root, newNames, asNames, false, absolute);
+                return AttachLoc(new FromImportStatement(root, newNames, asNames, false, absolute));
             }
 
             public string module {
@@ -2729,6 +2749,11 @@ internal Name(NameExpression expr, expr_context ctx)
                 : this(expr.Name, ctx) {
                 GetSourceLocation(expr);
             }
+            
+            public Parameter AttachLoc(Parameter other) {
+                other.SetLoc(_parent as PythonAst, _span.Start.Index, _span.End.Index);
+                return other;
+            }
 
             internal override AstExpression Revert() {
                 return new NameExpression(id);
@@ -2818,7 +2843,7 @@ internal Pass()
             }
 
             internal override Statement Revert() {
-                return new EmptyStatement();
+                return AttachLoc(new EmptyStatement());
             }
         }
 
@@ -2862,7 +2887,7 @@ internal Print(PrintStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new PrintStatement(expr.Revert(dest), expr.RevertExprs(values), !nl);
+                return AttachLoc(new PrintStatement(expr.Revert(dest), expr.RevertExprs(values), !nl));
             }
 
             public expr dest {
@@ -2913,7 +2938,7 @@ internal Raise(RaiseStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new RaiseStatement(expr.Revert(type), expr.Revert(inst), expr.Revert(tback));
+                return AttachLoc(new RaiseStatement(expr.Revert(type), expr.Revert(inst), expr.Revert(tback)));
             }
 
             public expr type {
@@ -2990,7 +3015,7 @@ public Return(ReturnStatement statement)
             }
 
             internal override Statement Revert() {
-                return new ReturnStatement(expr.Revert(value));
+                return AttachLoc(new ReturnStatement(expr.Revert(value)));
             }
 
             public expr value {
@@ -3236,7 +3261,7 @@ internal Subscript(IndexExpression expr, expr_context ctx)
                 } else {
                     Debug.Assert(false, "Unexpected type when converting Subscript: " + slice.GetType());
                 }
-                return new IndexExpression(expr.Revert(value), index);
+                return new IndexExpression(expr.Revert(value), slice.AttachLoc(index));
             }
 
             public expr value {
@@ -3323,7 +3348,7 @@ internal TryExcept(TryStatement stmt)
                 for (int i = 0; i < handlers.Count; i++) {
                     tshs[i] = ((ExceptHandler)handlers[i]).RevertHandler();
                 }
-                return new TryStatement(RevertStmts(body), tshs, RevertStmts(orelse), null);
+                return AttachLoc(new TryStatement(RevertStmts(body), tshs, RevertStmts(orelse), null));
             }
 
             public PythonList body {
@@ -3375,9 +3400,9 @@ internal TryFinally(PythonList body, PythonList finalbody)
                     for (int i = 0; i < te.handlers.Count; i++) {
                         tshs[i] = ((ExceptHandler)te.handlers[i]).RevertHandler();
                     }
-                    return new TryStatement(RevertStmts(te.body), tshs, RevertStmts(te.orelse), RevertStmts(finalbody));
+                    return AttachLoc(new TryStatement(RevertStmts(te.body), tshs, RevertStmts(te.orelse), RevertStmts(finalbody)));
                 }
-                return new TryStatement(RevertStmts(body), null, null, RevertStmts(finalbody));
+                return AttachLoc(new TryStatement(RevertStmts(body), null, null, RevertStmts(finalbody)));
             }
 
             public PythonList body {
@@ -3553,7 +3578,7 @@ internal While(WhileStatement stmt)
             }
 
             internal override Statement Revert() {
-                return new WhileStatement(expr.Revert(test), RevertStmts(body), RevertStmts(orelse));
+                return AttachLoc(new WhileStatement(expr.Revert(test), RevertStmts(body), RevertStmts(orelse)));
             }
 
             public expr test {
@@ -3603,7 +3628,7 @@ internal With(WithStatement with)
             }
 
             internal override Statement Revert() {
-                return new WithStatement(expr.Revert(context_expr), expr.Revert(optional_vars), RevertStmts(body));
+                return AttachLoc(new WithStatement(expr.Revert(context_expr), expr.Revert(optional_vars), RevertStmts(body)));
             }
 
             public expr context_expr {