mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-27 13:54:55 +00:00
Add end locations to all nodes (#4192)
This commit is contained in:
parent
519718e65d
commit
1cc342e4ed
61 changed files with 3157 additions and 144 deletions
|
@ -304,7 +304,7 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
|
|||
depth,
|
||||
)
|
||||
self.emit(
|
||||
"Ok(Located { custom: folder.map_user(node.custom)?, location: node.location, node: f(folder, node.node)? })",
|
||||
"Ok(Located { custom: folder.map_user(node.custom)?, location: node.location, end_location: node.end_location, node: f(folder, node.node)? })",
|
||||
depth + 1,
|
||||
)
|
||||
self.emit("}", depth)
|
||||
|
@ -617,9 +617,6 @@ class TraitImplVisitor(EmitVisitor):
|
|||
column = self.decode_field(asdl.Field("int", "col_offset"), typename)
|
||||
self.emit(f"let _location = ast::Location::new({row}, {column});", depth)
|
||||
|
||||
def wrap_located_node(self, depth):
|
||||
self.emit(f"let node = ast::Located::new(_location, node);", depth)
|
||||
|
||||
def decode_field(self, field, typename):
|
||||
name = json.dumps(field.name)
|
||||
if field.opt and not field.seq:
|
||||
|
@ -658,13 +655,14 @@ def write_ast_def(mod, typeinfo, f):
|
|||
"""
|
||||
pub struct Located<T, U = ()> {
|
||||
pub location: Location,
|
||||
pub end_location: Option<Location>,
|
||||
pub custom: U,
|
||||
pub node: T,
|
||||
}
|
||||
|
||||
impl<T> Located<T> {
|
||||
pub fn new(location: Location, node: T) -> Self {
|
||||
Self { location, custom: (), node }
|
||||
pub fn new(location: Location, end_location: Location, node: T) -> Self {
|
||||
Self { location, end_location: Some(end_location), custom: (), node }
|
||||
}
|
||||
}
|
||||
\n
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue