Merge pull request #13 from youknowone/locator

Python location transform and related refactoring
This commit is contained in:
Jeong, YunWon 2023-05-10 17:04:30 +09:00 committed by GitHub
commit 5cf85f0b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
150 changed files with 16253 additions and 27605 deletions

View file

@ -12,14 +12,18 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
resolver = "2"
members = [
"ast", "core", "literal", "parser",
"ruff_text_size", "ruff_source_location",
]
[workspace.dependencies]
rustpython-ast = { path = "ast", version = "0.2.0" }
rustpython-parser-core = { path = "core", version = "0.2.0" }
rustpython-literal = { path = "literal", version = "0.2.0" }
ruff_text_size = { path = "ruff_text_size" }
ruff_source_location = { path = "ruff_source_location" }
ahash = "0.7.6"
anyhow = "1.0.45"
ascii = "1.0"
bitflags = "1.3.2"
bstr = "0.2.17"
cfg-if = "1.0"
insta = "1.14.0"
itertools = "0.10.3"
@ -30,6 +34,7 @@ num-traits = "0.2"
rand = "0.8.5"
serde = "1.0"
static_assertions = "1.1"
once_cell = "1.17.1"
unicode_names2 = { version = "0.6.0", git = "https://github.com/youknowone/unicode_names2.git", rev = "4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" }
[profile.dev.package."*"]

View file

@ -8,13 +8,14 @@ repository = "https://github.com/RustPython/RustPython"
license = "MIT"
[features]
default = ["constant-optimization", "fold"]
default = ["constant-optimization", "fold", "source-code"]
constant-optimization = ["fold"]
source-code = ["fold"]
fold = []
unparse = ["rustpython-literal"]
[dependencies]
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
rustpython-literal = { path = "../literal", version = "0.2.0", optional = true }
rustpython-parser-core = { workspace = true }
rustpython-literal = { workspace = true, optional = true }
num-bigint = { workspace = true }

View file

@ -7,6 +7,7 @@ import textwrap
from argparse import ArgumentParser
from pathlib import Path
from typing import Optional, Dict
import asdl
@ -16,7 +17,7 @@ AUTOGEN_MESSAGE = "// File automatically generated by {}.\n"
builtin_type_mapping = {
"identifier": "Ident",
"string": "String",
"int": "usize",
"int": "u32",
"constant": "Constant",
}
assert builtin_type_mapping.keys() == asdl.builtin_types
@ -62,38 +63,62 @@ def asdl_of(name, obj):
return "{} = {}".format(name, types)
class EmitVisitor(asdl.VisitorBase):
"""Visit that emits lines"""
def __init__(self, file):
self.file = file
self.identifiers = set()
super(EmitVisitor, self).__init__()
def emit_identifier(self, name):
name = str(name)
if name in self.identifiers:
return
self.emit("_Py_IDENTIFIER(%s);" % name, 0)
self.identifiers.add(name)
def emit(self, line, depth):
if line:
line = (" " * TABSIZE * depth) + line
self.file.write(line + "\n")
class TypeInfo:
name: str
enum_name: Optional[str]
has_userdata: Optional[bool]
has_attributes: bool
children: set
boxed: bool
product: bool
has_expr: bool = False
def __init__(self, name):
self.name = name
self.enum_name = None
self.has_userdata = None
self.has_attributes = False
self.children = set()
self.boxed = False
self.product = False
self.product_has_expr = False
def __repr__(self):
return f"<TypeInfo: {self.name}>"
@property
def rust_name(self):
return get_rust_type(self.name)
@property
def sum_name(self):
if self.enum_name is None:
return self.name
else:
return f"{self.enum_name}_{self.name}"
@property
def rust_sum_name(self):
rust_name = get_rust_type(self.name)
if self.enum_name is None:
return rust_name
else:
name = get_rust_type(self.enum_name) + rust_name
return name
@property
def rust_suffix(self):
if self.product:
if self.has_attributes:
return "Data"
else:
return ""
else:
if self.has_attributes:
return "Kind"
else:
return ""
def determine_userdata(self, typeinfo, stack):
if self.name in stack:
return None
@ -110,6 +135,41 @@ class TypeInfo:
return self.has_userdata
class TypeInfoMixin:
typeinfo: Dict[str, TypeInfo]
def has_userdata(self, typ):
return self.typeinfo[typ].has_userdata
def get_generics(self, typ, *generics):
if self.has_userdata(typ):
return [f"<{g}>" for g in generics]
else:
return ["" for g in generics]
class EmitVisitor(asdl.VisitorBase, TypeInfoMixin):
"""Visit that emits lines"""
def __init__(self, file, typeinfo):
self.file = file
self.typeinfo = typeinfo
self.identifiers = set()
super(EmitVisitor, self).__init__()
def emit_identifier(self, name):
name = str(name)
if name in self.identifiers:
return
self.emit("_Py_IDENTIFIER(%s);" % name, 0)
self.identifiers.add(name)
def emit(self, line, depth):
if line:
line = (" " * TABSIZE * depth) + line
self.file.write(line + "\n")
class FindUserdataTypesVisitor(asdl.VisitorBase):
def __init__(self, typeinfo):
self.typeinfo = typeinfo
@ -132,21 +192,29 @@ class FindUserdataTypesVisitor(asdl.VisitorBase):
info.has_userdata = False
else:
for t in sum.types:
self.typeinfo[t.name] = TypeInfo(t.name)
if not t.fields:
continue
t_info = TypeInfo(t.name)
t_info.enum_name = name
self.typeinfo[t.name] = t_info
self.add_children(t.name, t.fields)
if len(sum.types) > 1:
info.boxed = True
if sum.attributes:
# attributes means Located, which has the `custom: U` field
# attributes means located, which has the `custom: U` field
info.has_userdata = True
info.has_attributes = True
for variant in sum.types:
self.add_children(name, variant.fields)
def visitProduct(self, product, name):
info = self.typeinfo[name]
if product.attributes:
# attributes means Located, which has the `custom: U` field
# attributes means located, which has the `custom: U` field
info.has_userdata = True
info.has_attributes = True
info.has_expr = product_has_expr(product)
if len(product.fields) > 2:
info.boxed = True
info.product = True
@ -163,24 +231,17 @@ def rust_field(field_name):
return field_name
class TypeInfoEmitVisitor(EmitVisitor):
def __init__(self, file, typeinfo):
self.typeinfo = typeinfo
super().__init__(file)
def has_userdata(self, typ):
return self.typeinfo[typ].has_userdata
def get_generics(self, typ, *generics):
if self.has_userdata(typ):
return [f"<{g}>" for g in generics]
else:
return ["" for g in generics]
def product_has_expr(product):
return any(f.type != "identifier" for f in product.fields)
class StructVisitor(TypeInfoEmitVisitor):
class StructVisitor(EmitVisitor):
"""Visitor to generate typedefs for AST."""
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.rust_type_defs = []
def visitModule(self, mod):
for dfn in mod.dfns:
self.visit(dfn)
@ -208,57 +269,56 @@ class StructVisitor(TypeInfoEmitVisitor):
def sum_with_constructors(self, sum, name, depth):
typeinfo = self.typeinfo[name]
enumname = rustname = get_rust_type(name)
suffix = typeinfo.rust_suffix
rustname = get_rust_type(name)
# all the attributes right now are for location, so if it has attrs we
# can just wrap it in Located<>
if sum.attributes:
enumname = rustname + "Kind"
# can just wrap it in Attributed<>
for t in sum.types:
if not t.fields:
continue
self.emit_attrs(depth)
self.typeinfo[t] = TypeInfo(t)
t_generics, t_generics_applied = self.get_generics(t.name, "U = ()", "U")
payload_name = f"{rustname}{t.name}"
self.emit(f"pub struct {payload_name}{t_generics} {{", depth)
for f in t.fields:
self.visit(f, typeinfo, "pub ", depth + 1, t.name)
self.emit("}", depth)
self.emit(
textwrap.dedent(
f"""
impl{t_generics_applied} From<{payload_name}{t_generics_applied}> for {enumname}{t_generics_applied} {{
fn from(payload: {payload_name}{t_generics_applied}) -> Self {{
{enumname}::{t.name}(payload)
}}
}}
"""
),
depth,
)
self.sum_subtype_struct(typeinfo, t, rustname, depth)
generics, generics_applied = self.get_generics(name, "U = ()", "U")
self.emit_attrs(depth)
self.emit(f"pub enum {enumname}{generics} {{", depth)
self.emit(f"pub enum {rustname}{suffix}{generics} {{", depth)
for t in sum.types:
if t.fields:
t_generics, t_generics_applied = self.get_generics(
t.name, "U = ()", "U"
)
(t_generics_applied,) = self.get_generics(t.name, "U")
self.emit(
f"{t.name}({rustname}{t.name}{t_generics_applied}),", depth + 1
)
else:
self.emit(f"{t.name},", depth + 1)
self.emit("}", depth)
if sum.attributes:
if typeinfo.has_attributes:
self.emit(
f"pub type {rustname}<U = ()> = Located<{enumname}{generics_applied}, U>;",
f"pub type {rustname}<U = ()> = Attributed<{rustname}{suffix}{generics_applied}, U>;",
depth,
)
self.emit("", depth)
def sum_subtype_struct(self, sum_typeinfo, t, rustname, depth):
self.emit_attrs(depth)
generics, generics_applied = self.get_generics(t.name, "U = ()", "U")
payload_name = f"{rustname}{t.name}"
self.emit(f"pub struct {payload_name}{generics} {{", depth)
for f in t.fields:
self.visit(f, sum_typeinfo, "pub ", depth + 1, t.name)
self.emit("}", depth)
self.emit(
textwrap.dedent(
f"""
impl{generics_applied} From<{payload_name}{generics_applied}> for {rustname}{sum_typeinfo.rust_suffix}{generics_applied} {{
fn from(payload: {payload_name}{generics_applied}) -> Self {{
{rustname}{sum_typeinfo.rust_suffix}::{t.name}(payload)
}}
}}
"""
),
depth,
)
def visitConstructor(self, cons, parent, depth):
if cons.fields:
self.emit(f"{cons.name} {{", depth)
@ -300,7 +360,7 @@ class StructVisitor(TypeInfoEmitVisitor):
if product.attributes:
dataname = rustname + "Data"
self.emit_attrs(depth)
has_expr = any(f.type != "identifier" for f in product.fields)
has_expr = product_has_expr(product)
if has_expr:
datadef = f"{dataname}{generics}"
else:
@ -314,20 +374,35 @@ class StructVisitor(TypeInfoEmitVisitor):
if not has_expr:
generics_applied = ""
self.emit(
f"pub type {rustname}<U = ()> = Located<{dataname}{generics_applied}, U>;",
f"pub type {rustname}<U = ()> = Attributed<{dataname}{generics_applied}, U>;",
depth,
)
self.emit("", depth)
class FoldTraitDefVisitor(TypeInfoEmitVisitor):
class FoldTraitDefVisitor(EmitVisitor):
def visitModule(self, mod, depth):
self.emit("pub trait Fold<U> {", depth)
self.emit("type TargetU;", depth + 1)
self.emit("type Error;", depth + 1)
self.emit(
"fn map_user(&mut self, user: U) -> Result<Self::TargetU, Self::Error>;",
depth + 2,
depth + 1,
)
self.emit(
"""
fn map_attributed<T>(&mut self, attributed: Attributed<T, U>) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
let custom = self.map_user(attributed.custom)?;
Ok(Attributed { range: attributed.range, custom, node: attributed.node })
}""",
depth + 1,
)
self.emit(
"""
fn fold<X: Foldable<U, Self::TargetU>>(&mut self, node: X) -> Result<X::Mapped, Self::Error> {
node.fold(self)
}""",
depth + 1,
)
for dfn in mod.dfns:
self.visit(dfn, depth + 2)
@ -345,14 +420,14 @@ class FoldTraitDefVisitor(TypeInfoEmitVisitor):
self.emit("}", depth)
class FoldImplVisitor(TypeInfoEmitVisitor):
class FoldImplVisitor(EmitVisitor):
def visitModule(self, mod, depth):
self.emit(
"fn fold_located<U, F: Fold<U> + ?Sized, T, MT>(folder: &mut F, node: Located<T, U>, f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>) -> Result<Located<MT, F::TargetU>, F::Error> {",
"fn fold_attributed<U, F: Fold<U> + ?Sized, T, MT>(folder: &mut F, node: Attributed<T, U>, f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>) -> Result<Attributed<MT, F::TargetU>, F::Error> {",
depth,
)
self.emit(
"Ok(Located { custom: folder.map_user(node.custom)?, location: node.location, end_location: node.end_location, node: f(folder, node.node)? })",
"let node = folder.map_attributed(node)?; Ok(Attributed { custom: node.custom, range: node.range, node: f(folder, node.node)? })",
depth + 1,
)
self.emit("}", depth)
@ -363,11 +438,11 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
self.visit(type.value, type.name, depth)
def visitSum(self, sum, name, depth):
typeinfo = self.typeinfo[name]
apply_t, apply_u, apply_target_u = self.get_generics(
name, "T", "U", "F::TargetU"
)
enumname = get_rust_type(name)
is_located = bool(sum.attributes)
self.emit(f"impl<T, U> Foldable<T, U> for {enumname}{apply_t} {{", depth)
self.emit(f"type Mapped = {enumname}{apply_u};", depth + 1)
@ -383,15 +458,13 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
f"pub fn fold_{name}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {enumname}{apply_u}) -> Result<{enumname}{apply_target_u}, F::Error> {{",
depth,
)
if is_located:
self.emit("fold_located(folder, node, |folder, node| {", depth)
rustname = enumname + "Kind"
else:
rustname = enumname
if typeinfo.has_attributes:
self.emit("fold_attributed(folder, node, |folder, node| {", depth)
self.emit("match node {", depth + 1)
for cons in sum.types:
fields_pattern = self.make_pattern(
enumname, rustname, cons.name, cons.fields
enumname, typeinfo.rust_suffix, cons.name, cons.fields
)
self.emit(
f"{fields_pattern[0]} {{ {fields_pattern[1]} }} {fields_pattern[2]} => {{",
@ -402,7 +475,7 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
)
self.emit("}", depth + 2)
self.emit("}", depth + 1)
if is_located:
if typeinfo.has_attributes:
self.emit("})", depth)
self.emit("}", depth)
@ -411,7 +484,7 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
name, "T", "U", "F::TargetU"
)
structname = get_rust_type(name)
is_located = bool(product.attributes)
has_attributes = bool(product.attributes)
self.emit(f"impl<T, U> Foldable<T, U> for {structname}{apply_t} {{", depth)
self.emit(f"type Mapped = {structname}{apply_u};", depth + 1)
@ -427,24 +500,24 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
f"pub fn fold_{name}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {structname}{apply_u}) -> Result<{structname}{apply_target_u}, F::Error> {{",
depth,
)
if is_located:
self.emit("fold_located(folder, node, |folder, node| {", depth)
if has_attributes:
self.emit("fold_attributed(folder, node, |folder, node| {", depth)
rustname = structname + "Data"
else:
rustname = structname
fields_pattern = self.make_pattern(rustname, structname, None, product.fields)
self.emit(f"let {rustname} {{ {fields_pattern[1]} }} = node;", depth + 1)
self.gen_construction(rustname, product.fields, "", depth + 1)
if is_located:
if has_attributes:
self.emit("})", depth)
self.emit("}", depth)
def make_pattern(self, rustname, pyname, fieldname, fields):
def make_pattern(self, rustname, suffix, fieldname, fields):
if fields:
header = f"{pyname}::{fieldname}({rustname}{fieldname}"
header = f"{rustname}{suffix}::{fieldname}({rustname}{fieldname}"
footer = ")"
else:
header = f"{pyname}::{fieldname}"
header = f"{rustname}{suffix}::{fieldname}"
footer = ""
body = ",".join(rust_field(f.name) for f in fields)
@ -458,7 +531,7 @@ class FoldImplVisitor(TypeInfoEmitVisitor):
self.emit(f"}}{footer})", depth)
class FoldModuleVisitor(TypeInfoEmitVisitor):
class FoldModuleVisitor(EmitVisitor):
def visitModule(self, mod):
depth = 0
self.emit('#[cfg(feature = "fold")]', depth)
@ -576,10 +649,10 @@ class TraitImplVisitor(EmitVisitor):
if sum.attributes:
rustname = enumname + "Kind"
self.emit(f"impl NamedNode for ast::{rustname} {{", depth)
self.emit(f"impl NamedNode for ast::located::{rustname} {{", depth)
self.emit(f"const NAME: &'static str = {json.dumps(name)};", depth + 1)
self.emit("}", depth)
self.emit(f"impl Node for ast::{rustname} {{", depth)
self.emit(f"impl Node for ast::located::{rustname} {{", depth)
self.emit(
"fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef {", depth + 1
)
@ -597,10 +670,12 @@ class TraitImplVisitor(EmitVisitor):
self.emit("}", depth)
def constructor_to_object(self, cons, enumname, rustname, depth):
self.emit(f"ast::{rustname}::{cons.name}", depth)
self.emit(f"ast::located::{rustname}::{cons.name}", depth)
if cons.fields:
fields_pattern = self.make_pattern(cons.fields)
self.emit(f"( ast::{enumname}{cons.name} {{ {fields_pattern} }} )", depth)
self.emit(
f"( ast::located::{enumname}{cons.name} {{ {fields_pattern} }} )", depth
)
self.emit(" => {", depth)
self.make_node(cons.name, cons.fields, depth + 1)
self.emit("}", depth)
@ -610,15 +685,17 @@ class TraitImplVisitor(EmitVisitor):
if product.attributes:
structname += "Data"
self.emit(f"impl NamedNode for ast::{structname} {{", depth)
self.emit(f"impl NamedNode for ast::located::{structname} {{", depth)
self.emit(f"const NAME: &'static str = {json.dumps(name)};", depth + 1)
self.emit("}", depth)
self.emit(f"impl Node for ast::{structname} {{", depth)
self.emit(f"impl Node for ast::located::{structname} {{", depth)
self.emit(
"fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef {", depth + 1
)
fields_pattern = self.make_pattern(product.fields)
self.emit(f"let ast::{structname} {{ {fields_pattern} }} = self;", depth + 2)
self.emit(
f"let ast::located::{structname} {{ {fields_pattern} }} = self;", depth + 2
)
self.make_node(name, product.fields, depth + 2)
self.emit("}", depth + 1)
self.emit(
@ -648,19 +725,22 @@ class TraitImplVisitor(EmitVisitor):
return ",".join(rust_field(f.name) for f in fields)
def gen_sum_fromobj(self, sum, sumname, enumname, rustname, depth):
if sum.attributes:
self.extract_location(sumname, depth)
# if sum.attributes:
# self.extract_location(sumname, depth)
self.emit("let _cls = _object.class();", depth)
self.emit("Ok(", depth)
for cons in sum.types:
self.emit(f"if _cls.is(Node{cons.name}::static_type()) {{", depth)
if cons.fields:
self.emit(f"ast::{rustname}::{cons.name} (ast::{enumname}{cons.name} {{", depth + 1)
self.emit(
f"ast::located::{rustname}::{cons.name} (ast::located::{enumname}{cons.name} {{",
depth + 1,
)
self.gen_construction_fields(cons, sumname, depth + 1)
self.emit("})", depth + 1)
else:
self.emit(f"ast::{rustname}::{cons.name}", depth + 1)
self.emit(f"ast::located::{rustname}::{cons.name}", depth + 1)
self.emit("} else", depth)
self.emit("{", depth)
@ -669,8 +749,8 @@ class TraitImplVisitor(EmitVisitor):
self.emit("})", depth)
def gen_product_fromobj(self, product, prodname, structname, depth):
if product.attributes:
self.extract_location(prodname, depth)
# if product.attributes:
# self.extract_location(prodname, depth)
self.emit("Ok(", depth)
self.gen_construction(structname, product, prodname, depth + 1)
@ -684,14 +764,22 @@ class TraitImplVisitor(EmitVisitor):
)
def gen_construction(self, cons_path, cons, name, depth):
self.emit(f"ast::{cons_path} {{", depth)
self.emit(f"ast::located::{cons_path} {{", depth)
self.gen_construction_fields(cons, name, depth + 1)
self.emit("}", depth)
def extract_location(self, typename, depth):
row = self.decode_field(asdl.Field("int", "lineno"), typename)
column = self.decode_field(asdl.Field("int", "col_offset"), typename)
self.emit(f"let _location = ast::Location::new({row}, {column});", depth)
self.emit(
f"""
let _location = {{
let row = {row};
let column = {column};
try_location(row, column)
}};""",
depth,
)
def decode_field(self, field, typename):
name = json.dumps(field.name)
@ -711,56 +799,15 @@ class ChainOfVisitors:
v.emit("", 0)
def write_ast_def(mod, typeinfo, f):
def write_generic_def(mod, typeinfo, f):
f.write(
textwrap.dedent(
"""
#![allow(clippy::derive_partial_eq_without_eq)]
pub use crate::constant::*;
pub use crate::Location;
pub use crate::{Attributed, constant::*};
type Ident = String;
\n
"""
)
)
StructVisitor(f, typeinfo).emit_attrs(0)
f.write(
textwrap.dedent(
"""
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, end_location: Location, node: T) -> Self {
Self { location, end_location: Some(end_location), custom: (), node }
}
pub const fn start(&self) -> Location {
self.location
}
/// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if
/// [`end_location`](Located::end_location) is `None`.
pub fn end(&self) -> Location {
self.end_location.unwrap_or(self.location)
}
}
impl<T, U> std::ops::Deref for Located<T, U> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.node
}
}
\n
""".lstrip()
"""
)
)
@ -768,24 +815,59 @@ def write_ast_def(mod, typeinfo, f):
c.visit(mod)
def write_ast_mod(mod, f):
def write_located_def(typeinfo, f):
f.write(
textwrap.dedent(
"""
#![allow(clippy::all)]
use rustpython_parser_core::source_code::SourceRange;
use super::*;
use crate::common::ascii;
pub type Located<T> = super::generic::Attributed<T, SourceRange>;
"""
)
)
for info in typeinfo.values():
if info.has_userdata:
generics = "::<SourceRange>"
else:
generics = ""
f.write(
f"pub type {info.rust_sum_name} = super::generic::{info.rust_sum_name}{generics};\n"
)
if info.rust_suffix:
if info.rust_suffix == "Data" and not info.has_expr:
generics = ""
f.write(
f"pub type {info.rust_sum_name}{info.rust_suffix} = super::generic::{info.rust_sum_name}{info.rust_suffix}{generics};\n"
)
"""
def write_ast_mod(mod, typeinfo, f):
f.write(
textwrap.dedent(
"""
#![allow(clippy::all)]
use super::*;
use crate::common::ascii;
"""
)
)
c = ChainOfVisitors(ClassDefVisitor(f), TraitImplVisitor(f), ExtendModuleVisitor(f))
c = ChainOfVisitors(
ClassDefVisitor(f, typeinfo),
TraitImplVisitor(f, typeinfo),
ExtendModuleVisitor(f, typeinfo),
)
c.visit(mod)
def main(input_filename, ast_mod_filename, ast_def_filename, dump_module=False):
def main(
input_filename,
generic_filename,
located_filename,
module_filename,
dump_module=False,
):
auto_gen_msg = AUTOGEN_MESSAGE.format("/".join(Path(__file__).parts[-2:]))
mod = asdl.parse(input_filename)
if dump_module:
@ -797,22 +879,34 @@ def main(input_filename, ast_mod_filename, ast_def_filename, dump_module=False):
typeinfo = {}
FindUserdataTypesVisitor(typeinfo).visit(mod)
with ast_def_filename.open("w") as def_file, ast_mod_filename.open("w") as mod_file:
def_file.write(auto_gen_msg)
write_ast_def(mod, typeinfo, def_file)
with generic_filename.open("w") as generic_file, located_filename.open(
"w"
) as located_file:
generic_file.write(auto_gen_msg)
write_generic_def(mod, typeinfo, generic_file)
located_file.write(auto_gen_msg)
write_located_def(typeinfo, located_file)
mod_file.write(auto_gen_msg)
write_ast_mod(mod, mod_file)
with module_filename.open("w") as module_file:
module_file.write(auto_gen_msg)
write_ast_mod(mod, typeinfo, module_file)
print(f"{ast_def_filename}, {ast_mod_filename} regenerated.")
print(f"{generic_filename}, {located_filename}, {module_filename} regenerated.")
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("input_file", type=Path)
parser.add_argument("-M", "--mod-file", type=Path, required=True)
parser.add_argument("-D", "--def-file", type=Path, required=True)
parser.add_argument("-G", "--generic-file", type=Path, required=True)
parser.add_argument("-L", "--located-file", type=Path, required=True)
parser.add_argument("-M", "--module-file", type=Path, required=True)
parser.add_argument("-d", "--dump-module", action="store_true")
args = parser.parse_args()
main(args.input_file, args.mod_file, args.def_file, args.dump_module)
main(
args.input_file,
args.generic_file,
args.located_file,
args.module_file,
args.dump_module,
)

76
ast/src/attributed.rs Normal file
View file

@ -0,0 +1,76 @@
use rustpython_parser_core::{
source_code::{SourceLocation, SourceRange},
text_size::{TextRange, TextSize},
};
#[derive(Clone, Debug, PartialEq)]
pub struct Attributed<T, U = ()> {
pub range: TextRange,
pub custom: U,
pub node: T,
}
impl<T, U> Attributed<T, U> {
/// Returns the node
#[inline]
pub fn node(&self) -> &T {
&self.node
}
/// Returns the `range` of the node. The range offsets are absolute to the start of the document.
#[inline]
pub const fn range(&self) -> TextRange {
self.range
}
/// Returns the absolute start position of the node from the beginning of the document.
#[inline]
pub const fn start(&self) -> TextSize {
self.range.start()
}
/// Returns the absolute position at which the node ends in the source document.
#[inline]
pub const fn end(&self) -> TextSize {
self.range.end()
}
}
impl<T> Attributed<T, ()> {
/// Creates a new node that spans the position specified by `range`.
pub fn new(range: impl Into<TextRange>, node: T) -> Self {
Self {
range: range.into(),
custom: (),
node,
}
}
/// Consumes self and returns the node.
#[inline]
pub fn into_node(self) -> T {
self.node
}
}
impl<T> Attributed<T, SourceRange> {
/// Returns the absolute start position of the node from the beginning of the document.
#[inline]
pub const fn location(&self) -> SourceLocation {
self.custom.start
}
/// Returns the absolute position at which the node ends in the source document.
#[inline]
pub const fn end_location(&self) -> Option<SourceLocation> {
self.custom.end
}
}
impl<T, U> std::ops::Deref for Attributed<T, U> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.node
}
}

View file

@ -1,5 +1,4 @@
use num_bigint::BigInt;
pub use rustpython_compiler_core::ConversionFlag;
#[derive(Clone, Debug, PartialEq)]
pub enum Constant {
@ -126,8 +125,7 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
Ok(crate::Expr {
node: expr,
custom: node.custom,
location: node.location,
end_location: node.end_location,
range: node.range,
})
}
_ => crate::fold::fold_expr(self, node),
@ -138,25 +136,24 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
#[cfg(test)]
mod tests {
use super::*;
use rustpython_parser_core::text_size::TextRange;
#[cfg(feature = "constant-optimization")]
#[test]
fn test_constant_opt() {
use crate::{fold::Fold, *};
let start = Default::default();
let end = None;
let range = TextRange::default();
#[allow(clippy::let_unit_value)]
let custom = ();
let ast = Located {
location: start,
end_location: end,
let ast = Attributed {
range,
custom,
node: ExprTuple {
ctx: ExprContext::Load,
elts: vec![
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: BigInt::from(1).into(),
@ -164,9 +161,8 @@ mod tests {
}
.into(),
},
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: BigInt::from(2).into(),
@ -174,16 +170,14 @@ mod tests {
}
.into(),
},
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprTuple {
ctx: ExprContext::Load,
elts: vec![
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: BigInt::from(3).into(),
@ -191,9 +185,8 @@ mod tests {
}
.into(),
},
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: BigInt::from(4).into(),
@ -201,9 +194,8 @@ mod tests {
}
.into(),
},
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: BigInt::from(5).into(),
@ -224,9 +216,8 @@ mod tests {
.unwrap_or_else(|e| match e {});
assert_eq!(
new_ast,
Located {
location: start,
end_location: end,
Attributed {
range,
custom,
node: ExprConstant {
value: Constant::Tuple(vec![

View file

@ -1,6 +1,6 @@
use crate::{constant, fold::Fold};
pub(crate) trait Foldable<T, U> {
pub trait Foldable<T, U> {
type Mapped;
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
self,
@ -62,4 +62,4 @@ macro_rules! simple_fold {
};
}
simple_fold!(usize, String, bool, constant::Constant);
simple_fold!(u32, String, bool, constant::Constant);

View file

@ -1,49 +1,9 @@
// File automatically generated by ast/asdl_rs.py.
#![allow(clippy::derive_partial_eq_without_eq)]
pub use crate::constant::*;
pub use crate::Location;
pub use crate::{constant::*, Attributed};
type Ident = String;
#[derive(Clone, Debug, PartialEq)]
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, end_location: Location, node: T) -> Self {
Self {
location,
end_location: Some(end_location),
custom: (),
node,
}
}
pub const fn start(&self) -> Location {
self.location
}
/// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if
/// [`end_location`](Located::end_location) is `None`.
pub fn end(&self) -> Location {
self.end_location.unwrap_or(self.location)
}
}
impl<T, U> std::ops::Deref for Located<T, U> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.node
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ModModule<U = ()> {
pub body: Vec<Stmt<U>>,
@ -198,7 +158,7 @@ pub struct StmtAnnAssign<U = ()> {
pub target: Box<Expr<U>>,
pub annotation: Box<Expr<U>>,
pub value: Option<Box<Expr<U>>>,
pub simple: usize,
pub simple: u32,
}
impl<U> From<StmtAnnAssign<U>> for StmtKind<U> {
@ -368,7 +328,7 @@ impl<U> From<StmtImport<U>> for StmtKind<U> {
pub struct StmtImportFrom<U = ()> {
pub module: Option<Ident>,
pub names: Vec<Alias<U>>,
pub level: Option<usize>,
pub level: Option<u32>,
}
impl<U> From<StmtImportFrom<U>> for StmtKind<U> {
@ -440,7 +400,7 @@ pub enum StmtKind<U = ()> {
Break,
Continue,
}
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
pub type Stmt<U = ()> = Attributed<StmtKind<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct ExprBoolOp<U = ()> {
@ -650,7 +610,7 @@ impl<U> From<ExprCall<U>> for ExprKind<U> {
#[derive(Clone, Debug, PartialEq)]
pub struct ExprFormattedValue<U = ()> {
pub value: Box<Expr<U>>,
pub conversion: usize,
pub conversion: u32,
pub format_spec: Option<Box<Expr<U>>>,
}
@ -800,7 +760,7 @@ pub enum ExprKind<U = ()> {
Tuple(ExprTuple<U>),
Slice(ExprSlice<U>),
}
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
pub type Expr<U = ()> = Attributed<ExprKind<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub enum ExprContext {
@ -859,7 +819,7 @@ pub struct Comprehension<U = ()> {
pub target: Expr<U>,
pub iter: Expr<U>,
pub ifs: Vec<Expr<U>>,
pub is_async: usize,
pub is_async: u32,
}
#[derive(Clone, Debug, PartialEq)]
@ -879,7 +839,7 @@ impl<U> From<ExcepthandlerExceptHandler<U>> for ExcepthandlerKind<U> {
pub enum ExcepthandlerKind<U = ()> {
ExceptHandler(ExcepthandlerExceptHandler<U>),
}
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
pub type Excepthandler<U = ()> = Attributed<ExcepthandlerKind<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct Arguments<U = ()> {
@ -898,21 +858,21 @@ pub struct ArgData<U = ()> {
pub annotation: Option<Box<Expr<U>>>,
pub type_comment: Option<String>,
}
pub type Arg<U = ()> = Located<ArgData<U>, U>;
pub type Arg<U = ()> = Attributed<ArgData<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct KeywordData<U = ()> {
pub arg: Option<Ident>,
pub value: Expr<U>,
}
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
pub type Keyword<U = ()> = Attributed<KeywordData<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct AliasData {
pub name: Ident,
pub asname: Option<Ident>,
}
pub type Alias<U = ()> = Located<AliasData, U>;
pub type Alias<U = ()> = Attributed<AliasData, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct Withitem<U = ()> {
@ -1032,11 +992,11 @@ pub enum PatternKind<U = ()> {
MatchAs(PatternMatchAs<U>),
MatchOr(PatternMatchOr<U>),
}
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
pub type Pattern<U = ()> = Attributed<PatternKind<U>, U>;
#[derive(Clone, Debug, PartialEq)]
pub struct TypeIgnoreTypeIgnore {
pub lineno: usize,
pub lineno: u32,
pub tag: String,
}
@ -1059,6 +1019,25 @@ pub mod fold {
type TargetU;
type Error;
fn map_user(&mut self, user: U) -> Result<Self::TargetU, Self::Error>;
fn map_attributed<T>(
&mut self,
attributed: Attributed<T, U>,
) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
let custom = self.map_user(attributed.custom)?;
Ok(Attributed {
range: attributed.range,
custom,
node: attributed.node,
})
}
fn fold<X: Foldable<U, Self::TargetU>>(
&mut self,
node: X,
) -> Result<X::Mapped, Self::Error> {
node.fold(self)
}
fn fold_mod(&mut self, node: Mod<U>) -> Result<Mod<Self::TargetU>, Self::Error> {
fold_mod(self, node)
}
@ -1135,15 +1114,15 @@ pub mod fold {
fold_type_ignore(self, node)
}
}
fn fold_located<U, F: Fold<U> + ?Sized, T, MT>(
fn fold_attributed<U, F: Fold<U> + ?Sized, T, MT>(
folder: &mut F,
node: Located<T, U>,
node: Attributed<T, U>,
f: impl FnOnce(&mut F, T) -> Result<MT, F::Error>,
) -> Result<Located<MT, F::TargetU>, F::Error> {
Ok(Located {
custom: folder.map_user(node.custom)?,
location: node.location,
end_location: node.end_location,
) -> Result<Attributed<MT, F::TargetU>, F::Error> {
let node = folder.map_attributed(node)?;
Ok(Attributed {
custom: node.custom,
range: node.range,
node: f(folder, node.node)?,
})
}
@ -1192,7 +1171,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Stmt<U>,
) -> Result<Stmt<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| match node {
fold_attributed(folder, node, |folder, node| match node {
StmtKind::FunctionDef(StmtFunctionDef {
name,
args,
@ -1396,7 +1375,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Expr<U>,
) -> Result<Expr<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| match node {
fold_attributed(folder, node, |folder, node| match node {
ExprKind::BoolOp(ExprBoolOp { op, values }) => Ok(ExprKind::BoolOp(ExprBoolOp {
op: Foldable::fold(op, folder)?,
values: Foldable::fold(values, folder)?,
@ -1696,7 +1675,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Excepthandler<U>,
) -> Result<Excepthandler<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| match node {
fold_attributed(folder, node, |folder, node| match node {
ExcepthandlerKind::ExceptHandler(ExcepthandlerExceptHandler { type_, name, body }) => {
Ok(ExcepthandlerKind::ExceptHandler(
ExcepthandlerExceptHandler {
@ -1753,7 +1732,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Arg<U>,
) -> Result<Arg<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| {
fold_attributed(folder, node, |folder, node| {
let ArgData {
arg,
annotation,
@ -1779,7 +1758,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Keyword<U>,
) -> Result<Keyword<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| {
fold_attributed(folder, node, |folder, node| {
let KeywordData { arg, value } = node;
Ok(KeywordData {
arg: Foldable::fold(arg, folder)?,
@ -1800,7 +1779,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Alias<U>,
) -> Result<Alias<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| {
fold_attributed(folder, node, |folder, node| {
let AliasData { name, asname } = node;
Ok(AliasData {
name: Foldable::fold(name, folder)?,
@ -1867,7 +1846,7 @@ pub mod fold {
#[allow(unused)] folder: &mut F,
node: Pattern<U>,
) -> Result<Pattern<F::TargetU>, F::Error> {
fold_located(folder, node, |folder, node| match node {
fold_attributed(folder, node, |folder, node| match node {
PatternKind::MatchValue(PatternMatchValue { value }) => {
Ok(PatternKind::MatchValue(PatternMatchValue {
value: Foldable::fold(value, folder)?,

95
ast/src/gen/located.rs Normal file
View file

@ -0,0 +1,95 @@
// File automatically generated by ast/asdl_rs.py.
use rustpython_parser_core::source_code::SourceRange;
pub type Located<T> = super::generic::Attributed<T, SourceRange>;
pub type Mod = super::generic::Mod<SourceRange>;
pub type ModModule = super::generic::ModModule<SourceRange>;
pub type ModInteractive = super::generic::ModInteractive<SourceRange>;
pub type ModExpression = super::generic::ModExpression<SourceRange>;
pub type ModFunctionType = super::generic::ModFunctionType<SourceRange>;
pub type Stmt = super::generic::Stmt<SourceRange>;
pub type StmtKind = super::generic::StmtKind<SourceRange>;
pub type StmtFunctionDef = super::generic::StmtFunctionDef<SourceRange>;
pub type StmtAsyncFunctionDef = super::generic::StmtAsyncFunctionDef<SourceRange>;
pub type StmtClassDef = super::generic::StmtClassDef<SourceRange>;
pub type StmtReturn = super::generic::StmtReturn<SourceRange>;
pub type StmtDelete = super::generic::StmtDelete<SourceRange>;
pub type StmtAssign = super::generic::StmtAssign<SourceRange>;
pub type StmtAugAssign = super::generic::StmtAugAssign<SourceRange>;
pub type StmtAnnAssign = super::generic::StmtAnnAssign<SourceRange>;
pub type StmtFor = super::generic::StmtFor<SourceRange>;
pub type StmtAsyncFor = super::generic::StmtAsyncFor<SourceRange>;
pub type StmtWhile = super::generic::StmtWhile<SourceRange>;
pub type StmtIf = super::generic::StmtIf<SourceRange>;
pub type StmtWith = super::generic::StmtWith<SourceRange>;
pub type StmtAsyncWith = super::generic::StmtAsyncWith<SourceRange>;
pub type StmtMatch = super::generic::StmtMatch<SourceRange>;
pub type StmtRaise = super::generic::StmtRaise<SourceRange>;
pub type StmtTry = super::generic::StmtTry<SourceRange>;
pub type StmtTryStar = super::generic::StmtTryStar<SourceRange>;
pub type StmtAssert = super::generic::StmtAssert<SourceRange>;
pub type StmtImport = super::generic::StmtImport<SourceRange>;
pub type StmtImportFrom = super::generic::StmtImportFrom<SourceRange>;
pub type StmtGlobal = super::generic::StmtGlobal;
pub type StmtNonlocal = super::generic::StmtNonlocal;
pub type StmtExpr = super::generic::StmtExpr<SourceRange>;
pub type Expr = super::generic::Expr<SourceRange>;
pub type ExprKind = super::generic::ExprKind<SourceRange>;
pub type ExprBoolOp = super::generic::ExprBoolOp<SourceRange>;
pub type ExprNamedExpr = super::generic::ExprNamedExpr<SourceRange>;
pub type ExprBinOp = super::generic::ExprBinOp<SourceRange>;
pub type ExprUnaryOp = super::generic::ExprUnaryOp<SourceRange>;
pub type ExprLambda = super::generic::ExprLambda<SourceRange>;
pub type ExprIfExp = super::generic::ExprIfExp<SourceRange>;
pub type ExprDict = super::generic::ExprDict<SourceRange>;
pub type ExprSet = super::generic::ExprSet<SourceRange>;
pub type ExprListComp = super::generic::ExprListComp<SourceRange>;
pub type ExprSetComp = super::generic::ExprSetComp<SourceRange>;
pub type ExprDictComp = super::generic::ExprDictComp<SourceRange>;
pub type ExprGeneratorExp = super::generic::ExprGeneratorExp<SourceRange>;
pub type ExprAwait = super::generic::ExprAwait<SourceRange>;
pub type ExprYield = super::generic::ExprYield<SourceRange>;
pub type ExprYieldFrom = super::generic::ExprYieldFrom<SourceRange>;
pub type ExprCompare = super::generic::ExprCompare<SourceRange>;
pub type ExprCall = super::generic::ExprCall<SourceRange>;
pub type ExprFormattedValue = super::generic::ExprFormattedValue<SourceRange>;
pub type ExprJoinedStr = super::generic::ExprJoinedStr<SourceRange>;
pub type ExprConstant = super::generic::ExprConstant;
pub type ExprAttribute = super::generic::ExprAttribute<SourceRange>;
pub type ExprSubscript = super::generic::ExprSubscript<SourceRange>;
pub type ExprStarred = super::generic::ExprStarred<SourceRange>;
pub type ExprName = super::generic::ExprName;
pub type ExprList = super::generic::ExprList<SourceRange>;
pub type ExprTuple = super::generic::ExprTuple<SourceRange>;
pub type ExprSlice = super::generic::ExprSlice<SourceRange>;
pub type ExprContext = super::generic::ExprContext;
pub type Boolop = super::generic::Boolop;
pub type Operator = super::generic::Operator;
pub type Unaryop = super::generic::Unaryop;
pub type Cmpop = super::generic::Cmpop;
pub type Comprehension = super::generic::Comprehension<SourceRange>;
pub type Excepthandler = super::generic::Excepthandler<SourceRange>;
pub type ExcepthandlerKind = super::generic::ExcepthandlerKind<SourceRange>;
pub type ExcepthandlerExceptHandler = super::generic::ExcepthandlerExceptHandler<SourceRange>;
pub type Arguments = super::generic::Arguments<SourceRange>;
pub type Arg = super::generic::Arg<SourceRange>;
pub type ArgData = super::generic::ArgData<SourceRange>;
pub type Keyword = super::generic::Keyword<SourceRange>;
pub type KeywordData = super::generic::KeywordData<SourceRange>;
pub type Alias = super::generic::Alias<SourceRange>;
pub type AliasData = super::generic::AliasData;
pub type Withitem = super::generic::Withitem<SourceRange>;
pub type MatchCase = super::generic::MatchCase<SourceRange>;
pub type Pattern = super::generic::Pattern<SourceRange>;
pub type PatternKind = super::generic::PatternKind<SourceRange>;
pub type PatternMatchValue = super::generic::PatternMatchValue<SourceRange>;
pub type PatternMatchSingleton = super::generic::PatternMatchSingleton;
pub type PatternMatchSequence = super::generic::PatternMatchSequence<SourceRange>;
pub type PatternMatchMapping = super::generic::PatternMatchMapping<SourceRange>;
pub type PatternMatchClass = super::generic::PatternMatchClass<SourceRange>;
pub type PatternMatchStar = super::generic::PatternMatchStar;
pub type PatternMatchAs = super::generic::PatternMatchAs<SourceRange>;
pub type PatternMatchOr = super::generic::PatternMatchOr<SourceRange>;
pub type TypeIgnore = super::generic::TypeIgnore;
pub type TypeIgnoreTypeIgnore = super::generic::TypeIgnoreTypeIgnore;

View file

@ -1,12 +1,27 @@
mod ast_gen;
mod attributed;
mod constant;
#[cfg(feature = "fold")]
mod fold_helpers;
mod generic {
#![allow(clippy::derive_partial_eq_without_eq)]
include!("gen/generic.rs");
}
mod impls;
#[cfg(feature = "source-code")]
mod source_locator;
#[cfg(feature = "unparse")]
mod unparse;
pub use ast_gen::*;
pub use rustpython_compiler_core::Location;
pub use attributed::Attributed;
pub use constant::Constant;
pub use generic::*;
pub use rustpython_parser_core::{text_size, ConversionFlag};
pub type Suite<U = ()> = Vec<Stmt<U>>;
#[cfg(feature = "source-code")]
pub mod located {
include!("gen/located.rs");
}
pub use rustpython_parser_core::source_code;

25
ast/src/source_locator.rs Normal file
View file

@ -0,0 +1,25 @@
use crate::attributed::Attributed;
use rustpython_parser_core::source_code::{SourceLocator, SourceRange};
impl crate::fold::Fold<()> for SourceLocator<'_> {
type TargetU = SourceRange;
type Error = std::convert::Infallible;
#[cold]
fn map_user(&mut self, _user: ()) -> Result<Self::TargetU, Self::Error> {
unreachable!("implemented map_attributed");
}
fn map_attributed<T>(
&mut self,
node: Attributed<T, ()>,
) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
let start = self.locate(node.range.start());
let end = self.locate(node.range.end());
Ok(Attributed {
range: node.range,
custom: (start..end).into(),
node: node.node,
})
}
}

View file

@ -1,7 +1,5 @@
use crate::{
Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, ConversionFlag, Expr, ExprKind,
Operator,
};
use crate::ConversionFlag;
use crate::{Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, Expr, ExprKind, Operator};
use std::fmt;
mod precedence {
@ -452,7 +450,7 @@ impl<'a> Unparser<'a> {
fn unparse_formatted<U>(
&mut self,
val: &Expr<U>,
conversion: usize,
conversion: u32,
spec: Option<&Expr<U>>,
) -> fmt::Result {
let buffered = to_string_fmt(|f| Unparser::new(f).unparse_expr(val, precedence::TEST + 1));
@ -466,7 +464,7 @@ impl<'a> Unparser<'a> {
self.p(&buffered)?;
drop(buffered);
if conversion != ConversionFlag::None as usize {
if conversion != ConversionFlag::None as u32 {
self.p("!")?;
let buf = &[conversion as u8];
let c = std::str::from_utf8(buf).unwrap();

View file

@ -1,6 +1,6 @@
[package]
name = "rustpython-compiler-core"
description = "RustPython specific bytecode."
name = "rustpython-parser-core"
description = "RustPython parser data types."
version = "0.2.0"
authors = ["RustPython Team"]
edition = "2021"
@ -8,11 +8,17 @@ repository = "https://github.com/RustPython/RustPython"
license = "MIT"
[dependencies]
bitflags = { workspace = true }
bstr = { workspace = true }
itertools = { workspace = true }
num-bigint = { workspace = true }
num-complex = { workspace = true }
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
# ruff dependency shouldn't be placed out of this crate
ruff_text_size = { path = "../ruff_text_size" }
ruff_source_location = { path = "../ruff_source_location", optional = true }
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
lz4_flex = "0.9.2"
[features]
default = ["source-code"]
source-code = ["ruff_source_location"]

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,10 @@
use crate::Location;
use std::error::Error as StdError;
use crate::text_size::TextSize;
use std::fmt::Display;
#[derive(Debug, PartialEq, Eq)]
pub struct BaseError<T> {
pub error: T,
pub location: Location,
pub offset: TextSize,
pub source_path: String,
}
@ -17,11 +16,11 @@ impl<T> std::ops::Deref for BaseError<T> {
}
}
impl<T> StdError for BaseError<T>
impl<T> std::error::Error for BaseError<T>
where
T: StdError + 'static,
T: std::error::Error + 'static,
{
fn source(&self) -> Option<&(dyn StdError + 'static)> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}
@ -31,7 +30,12 @@ where
T: std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.location.fmt_with(f, &self.error)
write!(
f,
"{} at byte offset {}",
&self.error,
u32::from(self.offset)
)
}
}
@ -46,7 +50,7 @@ impl<T> BaseError<T> {
{
Self {
error: obj.error.into(),
location: obj.location,
offset: obj.offset,
source_path: obj.source_path,
}
}

13
core/src/format.rs Normal file
View file

@ -0,0 +1,13 @@
/// Transforms a value prior to formatting it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum ConversionFlag {
/// No conversion
None = 0, // CPython uses -1 but not pleasure for us
/// Converts by calling `str(<value>)`.
Str = b's',
/// Converts by calling `ascii(<value>)`.
Ascii = b'a',
/// Converts by calling `repr(<value>)`.
Repr = b'r',
}

View file

@ -1,13 +1,15 @@
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
#![doc(html_root_url = "https://docs.rs/rustpython-compiler-core/")]
#![doc(html_root_url = "https://docs.rs/rustpython-parser-core/")]
mod bytecode;
mod error;
mod location;
pub mod marshal;
mod mode;
mod format;
pub mod mode;
#[cfg(feature = "source-code")]
pub mod source_code;
pub use bytecode::*;
pub use error::BaseError;
pub use location::Location;
pub use format::ConversionFlag;
pub use mode::Mode;
// re-export our public interface
pub use ruff_text_size as text_size;

View file

@ -1,128 +0,0 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// Source code location.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Location {
pub(super) row: u32,
pub(super) column: u32,
}
impl Default for Location {
fn default() -> Self {
Self { row: 1, column: 0 }
}
}
impl Location {
pub fn fmt_with(
&self,
f: &mut impl std::fmt::Write,
e: &impl std::fmt::Display,
) -> std::fmt::Result {
write!(f, "{} at line {} column {}", e, self.row(), self.column())
}
}
impl Location {
/// Creates a new Location object at the given row and column.
///
/// # Example
/// ```
/// use rustpython_compiler_core::Location;
/// let loc = Location::new(10, 10);
/// ```
pub fn new(row: usize, column: usize) -> Self {
let row = row.try_into().expect("Location::row over u32");
let column = column.try_into().expect("Location::column over u32");
Location { row, column }
}
/// Current row
pub fn row(&self) -> usize {
self.row as usize
}
/// Current column
pub fn column(&self) -> usize {
self.column as usize
}
pub fn reset(&mut self) {
self.row = 1;
self.column = 0;
}
pub fn go_right(&mut self) {
self.column += 1;
}
pub fn go_left(&mut self) {
self.column -= 1;
}
pub fn newline(&mut self) {
self.row += 1;
self.column = 0;
}
pub fn with_col_offset<T: TryInto<isize>>(&self, offset: T) -> Self
where
<T as TryInto<isize>>::Error: std::fmt::Debug,
{
let column = (self.column as isize
+ offset
.try_into()
.expect("offset should be able to convert to isize")) as u32;
Self {
row: self.row,
column,
}
}
pub fn with_row_offset<T: TryInto<isize>>(&self, offset: T) -> Self
where
<T as TryInto<isize>>::Error: std::fmt::Debug,
{
let row = (self.row as isize
+ offset
.try_into()
.expect("offset should be able to convert to isize")) as u32;
Self {
row,
column: self.column,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_gt() {
assert!(Location::new(1, 2) > Location::new(1, 1));
assert!(Location::new(2, 1) > Location::new(1, 1));
assert!(Location::new(2, 1) > Location::new(1, 2));
}
#[test]
fn test_lt() {
assert!(Location::new(1, 1) < Location::new(1, 2));
assert!(Location::new(1, 1) < Location::new(2, 1));
assert!(Location::new(1, 2) < Location::new(2, 1));
}
#[test]
fn test_with_col_offset() {
assert_eq!(Location::new(1, 1).with_col_offset(1), Location::new(1, 2));
assert_eq!(Location::new(1, 1).with_col_offset(-1), Location::new(1, 0));
}
#[test]
fn test_with_row_offset() {
assert_eq!(Location::new(1, 1).with_row_offset(1), Location::new(2, 1));
assert_eq!(Location::new(1, 1).with_row_offset(-1), Location::new(0, 1));
}
}

View file

@ -1,628 +0,0 @@
use core::fmt;
use std::convert::Infallible;
use num_bigint::{BigInt, Sign};
use num_complex::Complex64;
use crate::{bytecode::*, Location};
pub const FORMAT_VERSION: u32 = 4;
#[derive(Debug)]
pub enum MarshalError {
/// Unexpected End Of File
Eof,
/// Invalid Bytecode
InvalidBytecode,
/// Invalid utf8 in string
InvalidUtf8,
/// Bad type marker
BadType,
}
impl fmt::Display for MarshalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Eof => f.write_str("unexpected end of data"),
Self::InvalidBytecode => f.write_str("invalid bytecode"),
Self::InvalidUtf8 => f.write_str("invalid utf8"),
Self::BadType => f.write_str("bad type marker"),
}
}
}
impl From<std::str::Utf8Error> for MarshalError {
fn from(_: std::str::Utf8Error) -> Self {
Self::InvalidUtf8
}
}
impl std::error::Error for MarshalError {}
type Result<T, E = MarshalError> = std::result::Result<T, E>;
#[repr(u8)]
enum Type {
// Null = b'0',
None = b'N',
False = b'F',
True = b'T',
StopIter = b'S',
Ellipsis = b'.',
Int = b'i',
Float = b'g',
Complex = b'y',
// Long = b'l', // i32
Bytes = b's', // = TYPE_STRING
// Interned = b't',
// Ref = b'r',
Tuple = b'(',
List = b'[',
Dict = b'{',
Code = b'c',
Unicode = b'u',
// Unknown = b'?',
Set = b'<',
FrozenSet = b'>',
Ascii = b'a',
// AsciiInterned = b'A',
// SmallTuple = b')',
// ShortAscii = b'z',
// ShortAsciiInterned = b'Z',
}
// const FLAG_REF: u8 = b'\x80';
impl TryFrom<u8> for Type {
type Error = MarshalError;
fn try_from(value: u8) -> Result<Self> {
use Type::*;
Ok(match value {
// b'0' => Null,
b'N' => None,
b'F' => False,
b'T' => True,
b'S' => StopIter,
b'.' => Ellipsis,
b'i' => Int,
b'g' => Float,
b'y' => Complex,
// b'l' => Long,
b's' => Bytes,
// b't' => Interned,
// b'r' => Ref,
b'(' => Tuple,
b'[' => List,
b'{' => Dict,
b'c' => Code,
b'u' => Unicode,
// b'?' => Unknown,
b'<' => Set,
b'>' => FrozenSet,
b'a' => Ascii,
// b'A' => AsciiInterned,
// b')' => SmallTuple,
// b'z' => ShortAscii,
// b'Z' => ShortAsciiInterned,
_ => return Err(MarshalError::BadType),
})
}
}
pub trait Read {
fn read_slice(&mut self, n: u32) -> Result<&[u8]>;
fn read_array<const N: usize>(&mut self) -> Result<&[u8; N]> {
self.read_slice(N as u32).map(|s| s.try_into().unwrap())
}
fn read_str(&mut self, len: u32) -> Result<&str> {
Ok(std::str::from_utf8(self.read_slice(len)?)?)
}
fn read_u8(&mut self) -> Result<u8> {
Ok(u8::from_le_bytes(*self.read_array()?))
}
fn read_u16(&mut self) -> Result<u16> {
Ok(u16::from_le_bytes(*self.read_array()?))
}
fn read_u32(&mut self) -> Result<u32> {
Ok(u32::from_le_bytes(*self.read_array()?))
}
fn read_u64(&mut self) -> Result<u64> {
Ok(u64::from_le_bytes(*self.read_array()?))
}
}
pub(crate) trait ReadBorrowed<'a>: Read {
fn read_slice_borrow(&mut self, n: u32) -> Result<&'a [u8]>;
fn read_str_borrow(&mut self, len: u32) -> Result<&'a str> {
Ok(std::str::from_utf8(self.read_slice_borrow(len)?)?)
}
}
impl Read for &[u8] {
fn read_slice(&mut self, n: u32) -> Result<&[u8]> {
self.read_slice_borrow(n)
}
}
impl<'a> ReadBorrowed<'a> for &'a [u8] {
fn read_slice_borrow(&mut self, n: u32) -> Result<&'a [u8]> {
let data = self.get(..n as usize).ok_or(MarshalError::Eof)?;
*self = &self[n as usize..];
Ok(data)
}
}
pub struct Cursor<B> {
pub data: B,
pub position: usize,
}
impl<B: AsRef<[u8]>> Read for Cursor<B> {
fn read_slice(&mut self, n: u32) -> Result<&[u8]> {
let data = &self.data.as_ref()[self.position..];
let slice = data.get(..n as usize).ok_or(MarshalError::Eof)?;
self.position += n as usize;
Ok(slice)
}
}
pub fn deserialize_code<R: Read, Bag: ConstantBag>(
rdr: &mut R,
bag: Bag,
) -> Result<CodeObject<Bag::Constant>> {
let len = rdr.read_u32()?;
let instructions = rdr.read_slice(len * 2)?;
let instructions = instructions
.chunks_exact(2)
.map(|cu| {
let op = Instruction::try_from(cu[0])?;
let arg = OpArgByte(cu[1]);
Ok(CodeUnit { op, arg })
})
.collect::<Result<Box<[CodeUnit]>>>()?;
let len = rdr.read_u32()?;
let locations = (0..len)
.map(|_| {
Ok(Location {
row: rdr.read_u32()?,
column: rdr.read_u32()?,
})
})
.collect::<Result<Box<[Location]>>>()?;
let flags = CodeFlags::from_bits_truncate(rdr.read_u16()?);
let posonlyarg_count = rdr.read_u32()?;
let arg_count = rdr.read_u32()?;
let kwonlyarg_count = rdr.read_u32()?;
let len = rdr.read_u32()?;
let source_path = bag.make_name(rdr.read_str(len)?);
let first_line_number = rdr.read_u32()?;
let max_stackdepth = rdr.read_u32()?;
let len = rdr.read_u32()?;
let obj_name = bag.make_name(rdr.read_str(len)?);
let len = rdr.read_u32()?;
let cell2arg = (len != 0)
.then(|| {
(0..len)
.map(|_| Ok(rdr.read_u32()? as i32))
.collect::<Result<Box<[i32]>>>()
})
.transpose()?;
let len = rdr.read_u32()?;
let constants = (0..len)
.map(|_| deserialize_value(rdr, bag))
.collect::<Result<Box<[_]>>>()?;
let mut read_names = || {
let len = rdr.read_u32()?;
(0..len)
.map(|_| {
let len = rdr.read_u32()?;
Ok(bag.make_name(rdr.read_str(len)?))
})
.collect::<Result<Box<[_]>>>()
};
let names = read_names()?;
let varnames = read_names()?;
let cellvars = read_names()?;
let freevars = read_names()?;
Ok(CodeObject {
instructions,
locations,
flags,
posonlyarg_count,
arg_count,
kwonlyarg_count,
source_path,
first_line_number,
max_stackdepth,
obj_name,
cell2arg,
constants,
names,
varnames,
cellvars,
freevars,
})
}
pub trait MarshalBag: Copy {
type Value;
fn make_bool(&self, value: bool) -> Self::Value;
fn make_none(&self) -> Self::Value;
fn make_ellipsis(&self) -> Self::Value;
fn make_float(&self, value: f64) -> Self::Value;
fn make_complex(&self, value: Complex64) -> Self::Value;
fn make_str(&self, value: &str) -> Self::Value;
fn make_bytes(&self, value: &[u8]) -> Self::Value;
fn make_int(&self, value: BigInt) -> Self::Value;
fn make_tuple(&self, elements: impl Iterator<Item = Self::Value>) -> Self::Value;
fn make_code(
&self,
code: CodeObject<<Self::ConstantBag as ConstantBag>::Constant>,
) -> Self::Value;
fn make_stop_iter(&self) -> Result<Self::Value>;
fn make_list(&self, it: impl Iterator<Item = Self::Value>) -> Result<Self::Value>;
fn make_set(&self, it: impl Iterator<Item = Self::Value>) -> Result<Self::Value>;
fn make_frozenset(&self, it: impl Iterator<Item = Self::Value>) -> Result<Self::Value>;
fn make_dict(
&self,
it: impl Iterator<Item = (Self::Value, Self::Value)>,
) -> Result<Self::Value>;
type ConstantBag: ConstantBag;
fn constant_bag(self) -> Self::ConstantBag;
}
impl<Bag: ConstantBag> MarshalBag for Bag {
type Value = Bag::Constant;
fn make_bool(&self, value: bool) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Boolean { value })
}
fn make_none(&self) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::None)
}
fn make_ellipsis(&self) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Ellipsis)
}
fn make_float(&self, value: f64) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Float { value })
}
fn make_complex(&self, value: Complex64) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Complex { value })
}
fn make_str(&self, value: &str) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Str { value })
}
fn make_bytes(&self, value: &[u8]) -> Self::Value {
self.make_constant::<Bag::Constant>(BorrowedConstant::Bytes { value })
}
fn make_int(&self, value: BigInt) -> Self::Value {
self.make_int(value)
}
fn make_tuple(&self, elements: impl Iterator<Item = Self::Value>) -> Self::Value {
self.make_tuple(elements)
}
fn make_code(
&self,
code: CodeObject<<Self::ConstantBag as ConstantBag>::Constant>,
) -> Self::Value {
self.make_code(code)
}
fn make_stop_iter(&self) -> Result<Self::Value> {
Err(MarshalError::BadType)
}
fn make_list(&self, _: impl Iterator<Item = Self::Value>) -> Result<Self::Value> {
Err(MarshalError::BadType)
}
fn make_set(&self, _: impl Iterator<Item = Self::Value>) -> Result<Self::Value> {
Err(MarshalError::BadType)
}
fn make_frozenset(&self, _: impl Iterator<Item = Self::Value>) -> Result<Self::Value> {
Err(MarshalError::BadType)
}
fn make_dict(
&self,
_: impl Iterator<Item = (Self::Value, Self::Value)>,
) -> Result<Self::Value> {
Err(MarshalError::BadType)
}
type ConstantBag = Self;
fn constant_bag(self) -> Self::ConstantBag {
self
}
}
pub fn deserialize_value<R: Read, Bag: MarshalBag>(rdr: &mut R, bag: Bag) -> Result<Bag::Value> {
let typ = Type::try_from(rdr.read_u8()?)?;
let value = match typ {
Type::True => bag.make_bool(true),
Type::False => bag.make_bool(false),
Type::None => bag.make_none(),
Type::StopIter => bag.make_stop_iter()?,
Type::Ellipsis => bag.make_ellipsis(),
Type::Int => {
let len = rdr.read_u32()? as i32;
let sign = if len < 0 { Sign::Minus } else { Sign::Plus };
let bytes = rdr.read_slice(len.unsigned_abs())?;
let int = BigInt::from_bytes_le(sign, bytes);
bag.make_int(int)
}
Type::Float => {
let value = f64::from_bits(rdr.read_u64()?);
bag.make_float(value)
}
Type::Complex => {
let re = f64::from_bits(rdr.read_u64()?);
let im = f64::from_bits(rdr.read_u64()?);
let value = Complex64 { re, im };
bag.make_complex(value)
}
Type::Ascii | Type::Unicode => {
let len = rdr.read_u32()?;
let value = rdr.read_str(len)?;
bag.make_str(value)
}
Type::Tuple => {
let len = rdr.read_u32()?;
let it = (0..len).map(|_| deserialize_value(rdr, bag));
itertools::process_results(it, |it| bag.make_tuple(it))?
}
Type::List => {
let len = rdr.read_u32()?;
let it = (0..len).map(|_| deserialize_value(rdr, bag));
itertools::process_results(it, |it| bag.make_list(it))??
}
Type::Set => {
let len = rdr.read_u32()?;
let it = (0..len).map(|_| deserialize_value(rdr, bag));
itertools::process_results(it, |it| bag.make_set(it))??
}
Type::FrozenSet => {
let len = rdr.read_u32()?;
let it = (0..len).map(|_| deserialize_value(rdr, bag));
itertools::process_results(it, |it| bag.make_frozenset(it))??
}
Type::Dict => {
let len = rdr.read_u32()?;
let it = (0..len).map(|_| {
let k = deserialize_value(rdr, bag)?;
let v = deserialize_value(rdr, bag)?;
Ok::<_, MarshalError>((k, v))
});
itertools::process_results(it, |it| bag.make_dict(it))??
}
Type::Bytes => {
// Following CPython, after marshaling, byte arrays are converted into bytes.
let len = rdr.read_u32()?;
let value = rdr.read_slice(len)?;
bag.make_bytes(value)
}
Type::Code => bag.make_code(deserialize_code(rdr, bag.constant_bag())?),
};
Ok(value)
}
pub trait Dumpable: Sized {
type Error;
type Constant: Constant;
fn with_dump<R>(&self, f: impl FnOnce(DumpableValue<'_, Self>) -> R) -> Result<R, Self::Error>;
}
pub enum DumpableValue<'a, D: Dumpable> {
Integer(&'a BigInt),
Float(f64),
Complex(Complex64),
Boolean(bool),
Str(&'a str),
Bytes(&'a [u8]),
Code(&'a CodeObject<D::Constant>),
Tuple(&'a [D]),
None,
Ellipsis,
StopIter,
List(&'a [D]),
Set(&'a [D]),
Frozenset(&'a [D]),
Dict(&'a [(D, D)]),
}
impl<'a, C: Constant> From<BorrowedConstant<'a, C>> for DumpableValue<'a, C> {
fn from(c: BorrowedConstant<'a, C>) -> Self {
match c {
BorrowedConstant::Integer { value } => Self::Integer(value),
BorrowedConstant::Float { value } => Self::Float(value),
BorrowedConstant::Complex { value } => Self::Complex(value),
BorrowedConstant::Boolean { value } => Self::Boolean(value),
BorrowedConstant::Str { value } => Self::Str(value),
BorrowedConstant::Bytes { value } => Self::Bytes(value),
BorrowedConstant::Code { code } => Self::Code(code),
BorrowedConstant::Tuple { elements } => Self::Tuple(elements),
BorrowedConstant::None => Self::None,
BorrowedConstant::Ellipsis => Self::Ellipsis,
}
}
}
impl<C: Constant> Dumpable for C {
type Error = Infallible;
type Constant = Self;
#[inline(always)]
fn with_dump<R>(&self, f: impl FnOnce(DumpableValue<'_, Self>) -> R) -> Result<R, Self::Error> {
Ok(f(self.borrow_constant().into()))
}
}
pub trait Write {
fn write_slice(&mut self, slice: &[u8]);
fn write_u8(&mut self, v: u8) {
self.write_slice(&v.to_le_bytes())
}
fn write_u16(&mut self, v: u16) {
self.write_slice(&v.to_le_bytes())
}
fn write_u32(&mut self, v: u32) {
self.write_slice(&v.to_le_bytes())
}
fn write_u64(&mut self, v: u64) {
self.write_slice(&v.to_le_bytes())
}
}
impl Write for Vec<u8> {
fn write_slice(&mut self, slice: &[u8]) {
self.extend_from_slice(slice)
}
}
pub(crate) fn write_len<W: Write>(buf: &mut W, len: usize) {
let Ok(len) = len.try_into() else { panic!("too long to serialize") };
buf.write_u32(len);
}
pub(crate) fn write_vec<W: Write>(buf: &mut W, slice: &[u8]) {
write_len(buf, slice.len());
buf.write_slice(slice);
}
pub fn serialize_value<W: Write, D: Dumpable>(
buf: &mut W,
constant: DumpableValue<'_, D>,
) -> Result<(), D::Error> {
match constant {
DumpableValue::Integer(int) => {
buf.write_u8(Type::Int as u8);
let (sign, bytes) = int.to_bytes_le();
let len: i32 = bytes.len().try_into().expect("too long to serialize");
let len = if sign == Sign::Minus { -len } else { len };
buf.write_u32(len as u32);
buf.write_slice(&bytes);
}
DumpableValue::Float(f) => {
buf.write_u8(Type::Float as u8);
buf.write_u64(f.to_bits());
}
DumpableValue::Complex(c) => {
buf.write_u8(Type::Complex as u8);
buf.write_u64(c.re.to_bits());
buf.write_u64(c.im.to_bits());
}
DumpableValue::Boolean(b) => {
buf.write_u8(if b { Type::True } else { Type::False } as u8);
}
DumpableValue::Str(s) => {
buf.write_u8(Type::Unicode as u8);
write_vec(buf, s.as_bytes());
}
DumpableValue::Bytes(b) => {
buf.write_u8(Type::Bytes as u8);
write_vec(buf, b);
}
DumpableValue::Code(c) => {
buf.write_u8(Type::Code as u8);
serialize_code(buf, c);
}
DumpableValue::Tuple(tup) => {
buf.write_u8(Type::Tuple as u8);
write_len(buf, tup.len());
for val in tup {
val.with_dump(|val| serialize_value(buf, val))??
}
}
DumpableValue::None => {
buf.write_u8(Type::None as u8);
}
DumpableValue::Ellipsis => {
buf.write_u8(Type::Ellipsis as u8);
}
DumpableValue::StopIter => {
buf.write_u8(Type::StopIter as u8);
}
DumpableValue::List(l) => {
buf.write_u8(Type::List as u8);
write_len(buf, l.len());
for val in l {
val.with_dump(|val| serialize_value(buf, val))??
}
}
DumpableValue::Set(set) => {
buf.write_u8(Type::Set as u8);
write_len(buf, set.len());
for val in set {
val.with_dump(|val| serialize_value(buf, val))??
}
}
DumpableValue::Frozenset(set) => {
buf.write_u8(Type::FrozenSet as u8);
write_len(buf, set.len());
for val in set {
val.with_dump(|val| serialize_value(buf, val))??
}
}
DumpableValue::Dict(d) => {
buf.write_u8(Type::Dict as u8);
write_len(buf, d.len());
for (k, v) in d {
k.with_dump(|val| serialize_value(buf, val))??;
v.with_dump(|val| serialize_value(buf, val))??;
}
}
}
Ok(())
}
pub fn serialize_code<W: Write, C: Constant>(buf: &mut W, code: &CodeObject<C>) {
write_len(buf, code.instructions.len());
// SAFETY: it's ok to transmute CodeUnit to [u8; 2]
let (_, instructions_bytes, _) = unsafe { code.instructions.align_to() };
buf.write_slice(instructions_bytes);
write_len(buf, code.locations.len());
for loc in &*code.locations {
buf.write_u32(loc.row);
buf.write_u32(loc.column);
}
buf.write_u16(code.flags.bits());
buf.write_u32(code.posonlyarg_count);
buf.write_u32(code.arg_count);
buf.write_u32(code.kwonlyarg_count);
write_vec(buf, code.source_path.as_ref().as_bytes());
buf.write_u32(code.first_line_number);
buf.write_u32(code.max_stackdepth);
write_vec(buf, code.obj_name.as_ref().as_bytes());
let cell2arg = code.cell2arg.as_deref().unwrap_or(&[]);
write_len(buf, cell2arg.len());
for &i in cell2arg {
buf.write_u32(i as u32)
}
write_len(buf, code.constants.len());
for constant in &*code.constants {
serialize_value(buf, constant.borrow_constant().into()).unwrap_or_else(|x| match x {})
}
let mut write_names = |names: &[C::Name]| {
write_len(buf, names.len());
for name in names {
write_vec(buf, name.as_ref().as_bytes());
}
};
write_names(&code.names);
write_names(&code.varnames);
write_names(&code.cellvars);
write_names(&code.freevars);
}

View file

@ -1,27 +1,30 @@
//! Control in the different modes by which a source file can be parsed.
/// The mode argument specifies in what way code must be parsed.
#[derive(Clone, Copy)]
pub enum Mode {
Exec,
Eval,
Single,
BlockExpr,
/// The code consists of a sequence of statements.
Module,
/// The code consists of a sequence of interactive statement.
Interactive,
/// The code consists of a single expression.
Expression,
}
impl std::str::FromStr for Mode {
type Err = ModeParseError;
// To support `builtins.compile()` `mode` argument
fn from_str(s: &str) -> Result<Self, ModeParseError> {
match s {
"exec" => Ok(Mode::Exec),
"eval" => Ok(Mode::Eval),
"single" => Ok(Mode::Single),
_ => Err(ModeParseError(())),
"exec" | "single" => Ok(Mode::Module),
"eval" => Ok(Mode::Expression),
_ => Err(ModeParseError),
}
}
}
/// Returned when a given mode is not valid.
#[derive(Debug)]
pub struct ModeParseError(());
pub struct ModeParseError;
impl std::fmt::Display for ModeParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {

126
core/src/source_code.rs Normal file
View file

@ -0,0 +1,126 @@
// re-export our public interface
pub use ruff_source_location::*;
pub type LineNumber = OneIndexed;
#[derive(Debug)]
pub struct SourceRange {
pub start: SourceLocation,
pub end: Option<SourceLocation>,
}
impl SourceRange {
pub fn new(start: SourceLocation, end: SourceLocation) -> Self {
Self {
start,
end: Some(end),
}
}
pub fn unwrap_end(&self) -> SourceLocation {
self.end.unwrap()
}
}
impl From<std::ops::Range<SourceLocation>> for SourceRange {
fn from(value: std::ops::Range<SourceLocation>) -> Self {
Self {
start: value.start,
end: Some(value.end),
}
}
}
/// Converts source code byte-offset to Python convention line and column numbers.
pub struct SourceLocator<'a> {
pub source: &'a str,
index: LineIndex,
}
impl<'a> SourceLocator<'a> {
#[inline]
pub fn new(source: &'a str) -> Self {
let index = LineIndex::from_source_text(source);
Self { source, index }
}
pub fn to_source_code(&self) -> SourceCode {
SourceCode::new(self.source, &self.index)
}
pub fn locate(&mut self, offset: crate::text_size::TextSize) -> SourceLocation {
let offset = offset.to_u32().into();
self.to_source_code().source_location(offset)
}
pub fn locate_error<T, U>(&mut self, base: crate::error::BaseError<T>) -> LocatedError<U>
where
T: Into<U>,
{
let location = self.locate(base.offset);
LocatedError {
error: base.error.into(),
location: Some(location),
source_path: base.source_path,
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct LocatedError<T> {
pub error: T,
pub location: Option<SourceLocation>,
pub source_path: String,
}
impl<T> LocatedError<T> {
pub fn error(self) -> T {
self.error
}
pub fn from<U>(obj: LocatedError<U>) -> Self
where
U: Into<T>,
{
Self {
error: obj.error.into(),
location: obj.location,
source_path: obj.source_path,
}
}
pub fn into<U>(self) -> LocatedError<U>
where
T: Into<U>,
{
LocatedError::from(self)
}
pub fn python_location(&self) -> (usize, usize) {
if let Some(location) = self.location {
(location.row.to_usize(), location.column.to_usize())
} else {
(0, 0)
}
}
}
impl<T> std::fmt::Display for LocatedError<T>
where
T: std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let (row, column) = self
.location
.map_or((0, 0), |l| (l.row.to_usize(), l.column.to_usize()));
write!(f, "{} at row {} col {}", &self.error, row, column,)
}
}
impl<T> std::error::Error for LocatedError<T>
where
T: std::error::Error + 'static,
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}

View file

@ -10,7 +10,7 @@ edition = "2021"
[features]
default = []
serde = ["dep:serde", "rustpython-compiler-core/serde"]
serde = ["dep:serde", "rustpython-parser-core/serde"]
[build-dependencies]
anyhow = { workspace = true }
@ -19,10 +19,9 @@ phf_codegen = "0.11.1"
tiny-keccak = { version = "2", features = ["sha3"] }
[dependencies]
rustpython-ast = { path = "../ast", version = "0.2.0" }
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
rustpython-ast = { workspace = true }
rustpython-parser-core = { workspace = true }
ahash = { workspace = true }
itertools = { workspace = true }
log = { workspace = true }
num-bigint = { workspace = true }

View file

@ -3,6 +3,7 @@
use crate::{
ast,
lexer::{LexicalError, LexicalErrorType},
text_size::TextSize,
};
use rustc_hash::FxHashSet;
@ -18,7 +19,7 @@ type ParameterDef = (ast::Arg, Option<ast::Expr>);
pub(crate) fn validate_arguments(
arguments: ast::Arguments,
) -> Result<ast::Arguments, LexicalError> {
let mut all_args: Vec<&ast::Located<ast::ArgData>> = vec![];
let mut all_args: Vec<&ast::Attributed<ast::ArgData>> = vec![];
all_args.extend(arguments.posonlyargs.iter());
all_args.extend(arguments.args.iter());
@ -83,10 +84,7 @@ pub(crate) fn parse_params(
Ok((pos_only, names, defaults))
}
type FunctionArgument = (
Option<(ast::Location, ast::Location, Option<String>)>,
ast::Expr,
);
type FunctionArgument = (Option<(TextSize, TextSize, Option<String>)>, ast::Expr);
// Parse arguments as supplied during a function/lambda *call*.
pub(crate) fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentList, LexicalError> {
@ -116,8 +114,7 @@ pub(crate) fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentLis
}
keywords.push(ast::Keyword::new(
start,
end,
start..end,
ast::KeywordData { arg: name, value },
));
}

View file

@ -7,7 +7,7 @@
//! The primary function in this module is [`lex`], which takes a string slice
//! and returns an iterator over the tokens in the source code. The tokens are currently returned
//! as a `Result<Spanned, LexicalError>`, where [`Spanned`] is a tuple containing the
//! start and end [`Location`] and a [`Tok`] denoting the token.
//! start and end [`TextSize`] and a [`Tok`] denoting the token.
//!
//! # Example
//!
@ -19,24 +19,20 @@
//! .map(|tok| tok.expect("Failed to lex"))
//! .collect::<Vec<_>>();
//!
//! for (start, token, end) in tokens {
//! for (token, range) in tokens {
//! println!(
//! "{0},{1}-{2},{3:<5} {token:?}",
//! start.row(),
//! start.column(),
//! end.row(),
//! end.column(),
//! "{token:?}@{range:?}",
//! );
//! }
//! ```
//!
//! [Lexical analysis]: https://docs.python.org/3/reference/lexical_analysis.html
use crate::{
ast::Location,
mode::Mode,
soft_keywords::SoftKeywordTransformer,
string::FStringErrorType,
text_size::{TextLen, TextRange, TextSize},
token::{StringKind, Tok},
Mode,
};
use log::trace;
use num_bigint::BigInt;
@ -57,7 +53,7 @@ impl IndentationLevel {
fn compare_strict(
&self,
other: &IndentationLevel,
location: Location,
location: TextSize,
) -> Result<Ordering, LexicalError> {
// We only know for sure that we're smaller or bigger if tabs
// and spaces both differ in the same direction. Otherwise we're
@ -178,7 +174,7 @@ pub struct Lexer<T: Iterator<Item = char>> {
// Pending list of tokens to be returned.
pending: Vec<Spanned>,
// The current location.
location: Location,
location: TextSize,
}
// generated in build.rs, in gen_phf()
@ -186,8 +182,8 @@ pub struct Lexer<T: Iterator<Item = char>> {
pub static KEYWORDS: phf::Map<&'static str, Tok> =
include!(concat!(env!("OUT_DIR"), "/keywords.rs"));
/// Contains a Token along with its start and end location.
pub type Spanned = (Location, Tok, Location);
/// Contains a Token along with its `range`.
pub type Spanned = (Tok, TextRange);
/// The result of lexing a token.
pub type LexResult = Result<Spanned, LexicalError>;
@ -207,17 +203,17 @@ pub type LexResult = Result<Spanned, LexicalError>;
/// ```
#[inline]
pub fn lex(source: &str, mode: Mode) -> impl Iterator<Item = LexResult> + '_ {
lex_located(source, mode, Location::default())
lex_starts_at(source, mode, TextSize::default())
}
/// Create a new lexer from a source string, starting at a given location.
/// You probably want to use [`lex`] instead.
pub fn lex_located(
pub fn lex_starts_at(
source: &str,
mode: Mode,
start_location: Location,
start_offset: TextSize,
) -> impl Iterator<Item = LexResult> + '_ {
SoftKeywordTransformer::new(Lexer::new(source.chars(), start_location), mode)
SoftKeywordTransformer::new(Lexer::new(source.chars(), start_offset), mode)
}
impl<T> Lexer<T>
@ -226,7 +222,7 @@ where
{
/// Create a new lexer from T and a starting location. You probably want to use
/// [`lex`] instead.
pub fn new(input: T, start: Location) -> Self {
pub fn new(input: T, start: TextSize) -> Self {
let mut lxr = Lexer {
at_begin_of_line: true,
nesting: 0,
@ -244,6 +240,7 @@ where
// spell-checker:ignore feff
if let Some('\u{feff}') = lxr.window[0] {
lxr.window.slide();
lxr.location += '\u{feff}'.text_len();
}
lxr
}
@ -273,9 +270,9 @@ where
let end_pos = self.get_pos();
if let Some(tok) = KEYWORDS.get(&name) {
Ok((start_pos, tok.clone(), end_pos))
Ok((tok.clone(), TextRange::new(start_pos, end_pos)))
} else {
Ok((start_pos, Tok::Name { name }, end_pos))
Ok((Tok::Name { name }, TextRange::new(start_pos, end_pos)))
}
}
@ -306,14 +303,14 @@ where
}
/// Lex a hex/octal/decimal/binary number without a decimal point.
fn lex_number_radix(&mut self, start_pos: Location, radix: u32) -> LexResult {
fn lex_number_radix(&mut self, start_pos: TextSize, radix: u32) -> LexResult {
let value_text = self.radix_run(radix);
let end_pos = self.get_pos();
let value = BigInt::from_str_radix(&value_text, radix).map_err(|e| LexicalError {
error: LexicalErrorType::OtherError(format!("{e:?}")),
location: start_pos,
})?;
Ok((start_pos, Tok::Int { value }, end_pos))
Ok((Tok::Int { value }, TextRange::new(start_pos, end_pos)))
}
/// Lex a normal number, that is, no octal, hex or binary number.
@ -370,16 +367,15 @@ where
self.next_char();
let end_pos = self.get_pos();
Ok((
start_pos,
Tok::Complex {
real: 0.0,
imag: value,
},
end_pos,
TextRange::new(start_pos, end_pos),
))
} else {
let end_pos = self.get_pos();
Ok((start_pos, Tok::Float { value }, end_pos))
Ok((Tok::Float { value }, TextRange::new(start_pos, end_pos)))
}
} else {
// Parse trailing 'j':
@ -387,7 +383,10 @@ where
self.next_char();
let end_pos = self.get_pos();
let imag = f64::from_str(&value_text).unwrap();
Ok((start_pos, Tok::Complex { real: 0.0, imag }, end_pos))
Ok((
Tok::Complex { real: 0.0, imag },
TextRange::new(start_pos, end_pos),
))
} else {
let end_pos = self.get_pos();
let value = value_text.parse::<BigInt>().unwrap();
@ -398,7 +397,7 @@ where
location: self.get_pos(),
});
}
Ok((start_pos, Tok::Int { value }, end_pos))
Ok((Tok::Int { value }, TextRange::new(start_pos, end_pos)))
}
}
}
@ -458,7 +457,7 @@ where
match self.window[0] {
Some('\n' | '\r') | None => {
let end_pos = self.get_pos();
return Ok((start_pos, Tok::Comment(value), end_pos));
return Ok((Tok::Comment(value), TextRange::new(start_pos, end_pos)));
}
Some(_) => {}
}
@ -469,7 +468,7 @@ where
/// Lex a string literal.
fn lex_string(&mut self, kind: StringKind) -> LexResult {
let start_pos = self.get_pos();
for _ in 0..kind.prefix_len() {
for _ in 0..u32::from(kind.prefix_len()) {
self.next_char();
}
let quote_char = self.next_char().unwrap();
@ -538,7 +537,7 @@ where
kind,
triple_quoted,
};
Ok((start_pos, tok, end_pos))
Ok((tok, TextRange::new(start_pos, end_pos)))
}
// Checks if the character c is a valid starting character as described
@ -664,7 +663,15 @@ where
// New indentation level:
self.indentations.push(indentation_level);
let tok_pos = self.get_pos();
self.emit((tok_pos, Tok::Indent, tok_pos));
self.emit((
Tok::Indent,
TextRange::new(
tok_pos
- TextSize::new(indentation_level.spaces)
- TextSize::new(indentation_level.tabs),
tok_pos,
),
));
}
Ordering::Less => {
// One or more dedentations
@ -678,7 +685,7 @@ where
Ordering::Less => {
self.indentations.pop();
let tok_pos = self.get_pos();
self.emit((tok_pos, Tok::Dedent, tok_pos));
self.emit((Tok::Dedent, TextRange::empty(tok_pos)));
}
Ordering::Equal => {
// We arrived at proper level of indentation.
@ -723,16 +730,16 @@ where
// Next, insert a trailing newline, if required.
if !self.at_begin_of_line {
self.at_begin_of_line = true;
self.emit((tok_pos, Tok::Newline, tok_pos));
self.emit((Tok::Newline, TextRange::empty(tok_pos)));
}
// Next, flush the indentation stack to zero.
while !self.indentations.is_empty() {
self.indentations.pop();
self.emit((tok_pos, Tok::Dedent, tok_pos));
self.emit((Tok::Dedent, TextRange::empty(tok_pos)));
}
self.emit((tok_pos, Tok::EndOfFile, tok_pos));
self.emit((Tok::EndOfFile, TextRange::empty(tok_pos)));
}
Ok(())
@ -760,11 +767,11 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::EqEqual, tok_end));
self.emit((Tok::EqEqual, TextRange::new(tok_start, tok_end)));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Equal, tok_end));
self.emit((Tok::Equal, TextRange::new(tok_start, tok_end)));
}
}
}
@ -774,10 +781,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::PlusEqual, tok_end));
self.emit((Tok::PlusEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Plus, tok_end));
self.emit((Tok::Plus, TextRange::new(tok_start, tok_end)));
}
}
'*' => {
@ -787,7 +794,7 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::StarEqual, tok_end));
self.emit((Tok::StarEqual, TextRange::new(tok_start, tok_end)));
}
Some('*') => {
self.next_char();
@ -795,17 +802,20 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::DoubleStarEqual, tok_end));
self.emit((
Tok::DoubleStarEqual,
TextRange::new(tok_start, tok_end),
));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::DoubleStar, tok_end));
self.emit((Tok::DoubleStar, TextRange::new(tok_start, tok_end)));
}
}
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Star, tok_end));
self.emit((Tok::Star, TextRange::new(tok_start, tok_end)));
}
}
}
@ -816,7 +826,7 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::SlashEqual, tok_end));
self.emit((Tok::SlashEqual, TextRange::new(tok_start, tok_end)));
}
Some('/') => {
self.next_char();
@ -824,17 +834,20 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::DoubleSlashEqual, tok_end));
self.emit((
Tok::DoubleSlashEqual,
TextRange::new(tok_start, tok_end),
));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::DoubleSlash, tok_end));
self.emit((Tok::DoubleSlash, TextRange::new(tok_start, tok_end)));
}
}
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Slash, tok_end));
self.emit((Tok::Slash, TextRange::new(tok_start, tok_end)));
}
}
}
@ -844,10 +857,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::PercentEqual, tok_end));
self.emit((Tok::PercentEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Percent, tok_end));
self.emit((Tok::Percent, TextRange::new(tok_start, tok_end)));
}
}
'|' => {
@ -856,10 +869,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::VbarEqual, tok_end));
self.emit((Tok::VbarEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Vbar, tok_end));
self.emit((Tok::Vbar, TextRange::new(tok_start, tok_end)));
}
}
'^' => {
@ -868,10 +881,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::CircumflexEqual, tok_end));
self.emit((Tok::CircumflexEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::CircumFlex, tok_end));
self.emit((Tok::CircumFlex, TextRange::new(tok_start, tok_end)));
}
}
'&' => {
@ -880,10 +893,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::AmperEqual, tok_end));
self.emit((Tok::AmperEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Amper, tok_end));
self.emit((Tok::Amper, TextRange::new(tok_start, tok_end)));
}
}
'-' => {
@ -893,16 +906,16 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::MinusEqual, tok_end));
self.emit((Tok::MinusEqual, TextRange::new(tok_start, tok_end)));
}
Some('>') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Rarrow, tok_end));
self.emit((Tok::Rarrow, TextRange::new(tok_start, tok_end)));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Minus, tok_end));
self.emit((Tok::Minus, TextRange::new(tok_start, tok_end)));
}
}
}
@ -912,10 +925,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::AtEqual, tok_end));
self.emit((Tok::AtEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::At, tok_end));
self.emit((Tok::At, TextRange::new(tok_start, tok_end)));
}
}
'!' => {
@ -924,7 +937,7 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::NotEqual, tok_end));
self.emit((Tok::NotEqual, TextRange::new(tok_start, tok_end)));
} else {
return Err(LexicalError {
error: LexicalErrorType::UnrecognizedToken { tok: '!' },
@ -983,10 +996,10 @@ where
if let Some('=') = self.window[0] {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::ColonEqual, tok_end));
self.emit((Tok::ColonEqual, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Colon, tok_end));
self.emit((Tok::Colon, TextRange::new(tok_start, tok_end)));
}
}
';' => {
@ -1002,22 +1015,25 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::LeftShiftEqual, tok_end));
self.emit((
Tok::LeftShiftEqual,
TextRange::new(tok_start, tok_end),
));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::LeftShift, tok_end));
self.emit((Tok::LeftShift, TextRange::new(tok_start, tok_end)));
}
}
}
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::LessEqual, tok_end));
self.emit((Tok::LessEqual, TextRange::new(tok_start, tok_end)));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Less, tok_end));
self.emit((Tok::Less, TextRange::new(tok_start, tok_end)));
}
}
}
@ -1031,22 +1047,25 @@ where
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::RightShiftEqual, tok_end));
self.emit((
Tok::RightShiftEqual,
TextRange::new(tok_start, tok_end),
));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::RightShift, tok_end));
self.emit((Tok::RightShift, TextRange::new(tok_start, tok_end)));
}
}
}
Some('=') => {
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::GreaterEqual, tok_end));
self.emit((Tok::GreaterEqual, TextRange::new(tok_start, tok_end)));
}
_ => {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Greater, tok_end));
self.emit((Tok::Greater, TextRange::new(tok_start, tok_end)));
}
}
}
@ -1064,10 +1083,10 @@ where
self.next_char();
self.next_char();
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Ellipsis, tok_end));
self.emit((Tok::Ellipsis, TextRange::new(tok_start, tok_end)));
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Tok::Dot, tok_end));
self.emit((Tok::Dot, TextRange::new(tok_start, tok_end)));
}
}
}
@ -1080,9 +1099,9 @@ where
// non-logical newline:
if self.nesting == 0 {
self.at_begin_of_line = true;
self.emit((tok_start, Tok::Newline, tok_end));
self.emit((Tok::Newline, TextRange::new(tok_start, tok_end)));
} else {
self.emit((tok_start, Tok::NonLogicalNewline, tok_end));
self.emit((Tok::NonLogicalNewline, TextRange::new(tok_start, tok_end)));
}
}
' ' | '\t' | '\x0C' => {
@ -1119,11 +1138,10 @@ where
self.next_char();
let tok_end = self.get_pos();
self.emit((
tok_start,
Tok::Name {
name: c.to_string(),
},
tok_end,
TextRange::new(tok_start, tok_end),
));
} else {
let c = self.next_char();
@ -1147,7 +1165,7 @@ where
std::hint::unreachable_unchecked()
});
let tok_end = self.get_pos();
self.emit((tok_start, ty, tok_end));
self.emit((ty, TextRange::new(tok_start, tok_end)));
}
// Helper function to go to the next character coming up.
@ -1155,25 +1173,26 @@ where
let mut c = self.window[0];
self.window.slide();
match c {
Some('\n') => {
self.location.newline();
}
Some('\r') => {
if self.window[0] == Some('\n') {
self.location += TextSize::from(1);
self.window.slide();
}
self.location.newline();
self.location += TextSize::from(1);
c = Some('\n');
}
_ => {
self.location.go_right();
#[allow(unused_variables)]
Some(c) => {
self.location += c.text_len();
}
_ => {}
}
c
}
// Helper function to retrieve the current position.
fn get_pos(&self) -> Location {
fn get_pos(&self) -> TextSize {
self.location
}
@ -1202,7 +1221,7 @@ where
);
match token {
Ok((_, Tok::EndOfFile, _)) => None,
Ok((Tok::EndOfFile, _)) => None,
r => Some(r),
}
}
@ -1218,12 +1237,12 @@ pub struct LexicalError {
/// The type of error that occurred.
pub error: LexicalErrorType,
/// The location of the error.
pub location: Location,
pub location: TextSize,
}
impl LexicalError {
/// Creates a new `LexicalError` with the given error type and location.
pub fn new(error: LexicalErrorType, location: Location) -> Self {
pub fn new(error: LexicalErrorType, location: TextSize) -> Self {
Self { error, location }
}
}
@ -1325,7 +1344,7 @@ mod tests {
pub fn lex_source(source: &str) -> Vec<Tok> {
let lexer = lex(source, Mode::Module);
lexer.map(|x| x.unwrap().1).collect()
lexer.map(|x| x.unwrap().0).collect()
}
fn str_tok(s: &str) -> Tok {

View file

@ -113,20 +113,19 @@
#![doc(html_root_url = "https://docs.rs/rustpython-parser/")]
pub use rustpython_ast as ast;
pub use rustpython_parser_core::{source_code, text_size, Mode};
mod function;
// Skip flattening lexer to distinguish from full parser
mod context;
pub mod lexer;
mod mode;
mod parser;
mod soft_keywords;
mod string;
mod token;
pub use mode::Mode;
pub use parser::{
parse, parse_expression, parse_expression_located, parse_located, parse_program, parse_tokens,
parse, parse_expression, parse_expression_at, parse_program, parse_starts_at, parse_tokens,
ParseError, ParseErrorType,
};
pub use string::FStringErrorType;

View file

@ -1,55 +0,0 @@
//! Control in the different modes by which a source file can be parsed.
use crate::token::Tok;
/// The mode argument specifies in what way code must be parsed.
#[derive(Clone, Copy)]
pub enum Mode {
/// The code consists of a sequence of statements.
Module,
/// The code consists of a sequence of interactive statement.
Interactive,
/// The code consists of a single expression.
Expression,
}
impl Mode {
pub(crate) fn to_marker(self) -> Tok {
match self {
Self::Module => Tok::StartModule,
Self::Interactive => Tok::StartInteractive,
Self::Expression => Tok::StartExpression,
}
}
}
impl From<rustpython_compiler_core::Mode> for Mode {
fn from(mode: rustpython_compiler_core::Mode) -> Self {
use rustpython_compiler_core::Mode as CompileMode;
match mode {
CompileMode::Exec => Self::Module,
CompileMode::Eval => Self::Expression,
CompileMode::Single | CompileMode::BlockExpr => Self::Interactive,
}
}
}
impl std::str::FromStr for Mode {
type Err = ModeParseError;
fn from_str(s: &str) -> Result<Self, ModeParseError> {
match s {
"exec" | "single" => Ok(Mode::Module),
"eval" => Ok(Mode::Expression),
_ => Err(ModeParseError(())),
}
}
}
/// Returned when a given mode is not valid.
#[derive(Debug)]
pub struct ModeParseError(());
impl std::fmt::Display for ModeParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, r#"mode must be "exec", "eval", or "single""#)
}
}

View file

@ -13,11 +13,12 @@
//! [`Mode`]: crate::mode
use crate::{
ast::{self, Location},
ast,
lexer::{self, LexResult, LexicalError, LexicalErrorType},
mode::Mode,
python,
text_size::TextSize,
token::Tok,
Mode,
};
use itertools::Itertools;
use std::iter;
@ -69,7 +70,7 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
///
/// ```
pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseError> {
parse_expression_located(source, path, Location::new(1, 0))
parse_expression_at(source, path, TextSize::default())
}
/// Parses a Python expression from a given location.
@ -83,17 +84,17 @@ pub fn parse_expression(source: &str, path: &str) -> Result<ast::Expr, ParseErro
/// somewhat silly, location:
///
/// ```
/// use rustpython_parser::{ast::Location, parse_expression_located};
/// use rustpython_parser::{text_size::TextSize, parse_expression_at};
///
/// let expr = parse_expression_located("1 + 2", "<embedded>", Location::new(5, 20));
/// let expr = parse_expression_at("1 + 2", "<embedded>", TextSize::from(400));
/// assert!(expr.is_ok());
/// ```
pub fn parse_expression_located(
pub fn parse_expression_at(
source: &str,
path: &str,
location: Location,
offset: TextSize,
) -> Result<ast::Expr, ParseError> {
parse_located(source, Mode::Expression, path, location).map(|top| match top {
parse_starts_at(source, Mode::Expression, path, offset).map(|top| match top {
ast::Mod::Expression(ast::ModExpression { body }) => *body,
_ => unreachable!(),
})
@ -131,7 +132,7 @@ pub fn parse_expression_located(
/// assert!(program.is_ok());
/// ```
pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, ParseError> {
parse_located(source, mode, source_path, Location::new(1, 0))
parse_starts_at(source, mode, source_path, TextSize::default())
}
/// Parse the given Python source code using the specified [`Mode`] and [`Location`].
@ -142,7 +143,7 @@ pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, Pa
/// # Example
///
/// ```
/// use rustpython_parser::{ast::Location, Mode, parse_located};
/// use rustpython_parser::{text_size::TextSize, Mode, parse_starts_at};
///
/// let source = r#"
/// def fib(i):
@ -153,16 +154,16 @@ pub fn parse(source: &str, mode: Mode, source_path: &str) -> Result<ast::Mod, Pa
///
/// print(fib(42))
/// "#;
/// let program = parse_located(source, Mode::Module, "<embedded>", Location::new(1, 0));
/// let program = parse_starts_at(source, Mode::Module, "<embedded>", TextSize::from(0));
/// assert!(program.is_ok());
/// ```
pub fn parse_located(
pub fn parse_starts_at(
source: &str,
mode: Mode,
source_path: &str,
location: Location,
offset: TextSize,
) -> Result<ast::Mod, ParseError> {
let lxr = lexer::lex_located(source, mode, location);
let lxr = lexer::lex_starts_at(source, mode, offset);
parse_tokens(lxr, mode, source_path)
}
@ -186,18 +187,22 @@ pub fn parse_tokens(
mode: Mode,
source_path: &str,
) -> Result<ast::Mod, ParseError> {
let marker_token = (Default::default(), mode.to_marker(), Default::default());
let marker_token = (Tok::start_marker(mode), Default::default());
let lexer = iter::once(Ok(marker_token))
.chain(lxr)
.filter_ok(|(_, tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline));
.filter_ok(|(tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline));
python::TopParser::new()
.parse(lexer.into_iter())
.parse(
lexer
.into_iter()
.map_ok(|(t, range)| (range.start(), t, range.end())),
)
.map_err(|e| parse_error_from_lalrpop(e, source_path))
}
/// Represents represent errors that occur during parsing and are
/// returned by the `parse_*` functions.
pub type ParseError = rustpython_compiler_core::BaseError<ParseErrorType>;
pub type ParseError = rustpython_parser_core::BaseError<ParseErrorType>;
/// Represents the different types of errors that can occur during parsing.
#[derive(Debug, PartialEq)]
@ -219,25 +224,26 @@ impl std::error::Error for ParseErrorType {}
// Convert `lalrpop_util::ParseError` to our internal type
fn parse_error_from_lalrpop(
err: LalrpopError<Location, Tok, LexicalError>,
err: LalrpopError<TextSize, Tok, LexicalError>,
source_path: &str,
) -> ParseError {
let source_path = source_path.to_owned();
match err {
// TODO: Are there cases where this isn't an EOF?
LalrpopError::InvalidToken { location } => ParseError {
error: ParseErrorType::Eof,
location,
offset: location,
source_path,
},
LalrpopError::ExtraToken { token } => ParseError {
error: ParseErrorType::ExtraToken(token.1),
location: token.0,
offset: token.0,
source_path,
},
LalrpopError::User { error } => ParseError {
error: ParseErrorType::Lexical(error.error),
location: error.location,
offset: error.location,
source_path,
},
LalrpopError::UnrecognizedToken { token, expected } => {
@ -246,7 +252,7 @@ fn parse_error_from_lalrpop(
let expected = (expected.len() == 1).then(|| expected[0].clone());
ParseError {
error: ParseErrorType::UnrecognizedToken(token.1, expected),
location: token.0.with_col_offset(1),
offset: token.0,
source_path,
}
}
@ -256,13 +262,13 @@ fn parse_error_from_lalrpop(
if indent_error {
ParseError {
error: ParseErrorType::Lexical(LexicalErrorType::IndentationError),
location,
offset: location,
source_path,
}
} else {
ParseError {
error: ParseErrorType::Eof,
location,
offset: location,
source_path,
}
}
@ -576,9 +582,9 @@ except* OSError as e:
fn test_modes() {
let source = "a[0][1][2][3][4]";
assert!(parse(&source, Mode::Expression, "<embedded>").is_ok());
assert!(parse(&source, Mode::Module, "<embedded>").is_ok());
assert!(parse(&source, Mode::Interactive, "<embedded>").is_ok());
assert!(parse(source, Mode::Expression, "<embedded>").is_ok());
assert!(parse(source, Mode::Module, "<embedded>").is_ok());
assert!(parse(source, Mode::Interactive, "<embedded>").is_ok());
}
#[test]

View file

@ -10,6 +10,7 @@ use crate::{
context::set_context,
string::parse_strings,
token::{self, StringKind},
text_size::TextSize,
};
use num_bigint::BigInt;
@ -68,7 +69,7 @@ SmallStatement: ast::Stmt = {
PassStatement: ast::Stmt = {
<location:@L> "pass" <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtKind::Pass,
)
@ -78,7 +79,7 @@ PassStatement: ast::Stmt = {
DelStatement: ast::Stmt = {
<location:@L> "del" <targets:ExpressionList2> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtDelete { targets: targets.into_iter().map(|expr| set_context(expr, ast::ExprContext::Del)).collect() }.into()
)
@ -90,7 +91,7 @@ ExpressionStatement: ast::Stmt = {
// Just an expression, no assignment:
if suffix.is_empty() {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtExpr { value: Box::new(expression) }.into()
)
@ -105,7 +106,7 @@ ExpressionStatement: ast::Stmt = {
let value = Box::new(values.into_iter().next().unwrap());
ast::Stmt::new(
location,
location..
end_location,
ast::StmtAssign { targets, value, type_comment: None }.into()
)
@ -113,7 +114,7 @@ ExpressionStatement: ast::Stmt = {
},
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestListOrYieldExpr> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtAugAssign {
target: Box::new(set_context(target, ast::ExprContext::Store)),
@ -125,7 +126,7 @@ ExpressionStatement: ast::Stmt = {
<location:@L> <target:Test<"all">> ":" <annotation:Test<"all">> <rhs:AssignSuffix?> <end_location:@R> => {
let simple = matches!(target.node, ast::ExprKind::Name { .. });
ast::Stmt::new(
location,
location..
end_location,
ast::StmtAnnAssign {
target: Box::new(set_context(target, ast::ExprContext::Store)),
@ -186,28 +187,28 @@ AugAssign: ast::Operator = {
FlowStatement: ast::Stmt = {
<location:@L> "break" <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtKind::Break,
)
},
<location:@L> "continue" <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtKind::Continue,
)
},
<location:@L> "return" <value:TestList?> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtReturn { value: value.map(Box::new) }.into()
)
},
<location:@L> <expression:YieldExpr> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtExpr { value: Box::new(expression) }.into()
)
@ -218,14 +219,14 @@ FlowStatement: ast::Stmt = {
RaiseStatement: ast::Stmt = {
<location:@L> "raise" <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtRaise { exc: None, cause: None }.into()
)
},
<location:@L> "raise" <t:Test<"all">> <c:("from" Test<"all">)?> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtRaise { exc: Some(Box::new(t)), cause: c.map(|x| Box::new(x.1)) }.into()
)
@ -235,7 +236,7 @@ RaiseStatement: ast::Stmt = {
ImportStatement: ast::Stmt = {
<location:@L> "import" <names: OneOrMore<ImportAsAlias<DottedName>>> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtImport { names }.into()
)
@ -243,7 +244,7 @@ ImportStatement: ast::Stmt = {
<location:@L> "from" <source:ImportFromLocation> "import" <names: ImportAsNames> <end_location:@R> => {
let (level, module) = source;
ast::Stmt::new(
location,
location..
end_location,
ast::StmtImportFrom {
level,
@ -254,7 +255,7 @@ ImportStatement: ast::Stmt = {
},
};
ImportFromLocation: (Option<usize>, Option<String>) = {
ImportFromLocation: (Option<u32>, Option<String>) = {
<dots: ImportDots*> <name:DottedName> => {
(Some(dots.iter().sum()), Some(name))
},
@ -263,7 +264,7 @@ ImportFromLocation: (Option<usize>, Option<String>) = {
},
};
ImportDots: usize = {
ImportDots: u32 = {
"..." => 3,
"." => 1,
};
@ -273,14 +274,14 @@ ImportAsNames: Vec<ast::Alias> = {
<location:@L> "(" <i:OneOrMore<ImportAsAlias<Identifier>>> ","? ")" <end_location:@R> => i,
<location:@L> "*" <end_location:@R> => {
// Star import all
vec![ast::Alias::new(location, end_location, ast::AliasData { name: "*".to_string(), asname: None })]
vec![ast::Alias::new(location..end_location, ast::AliasData { name: "*".to_string(), asname: None })]
},
};
#[inline]
ImportAsAlias<I>: ast::Alias = {
<location:@L> <name:I> <a: ("as" Identifier)?> <end_location:@R> => ast::Alias::new(location, end_location, ast::AliasData { name, asname: a.map(|a| a.1) }),
<location:@L> <name:I> <a: ("as" Identifier)?> <end_location:@R> => ast::Alias::new(location..end_location, ast::AliasData { name, asname: a.map(|a| a.1) }),
}
// A name like abc or abc.def.ghi
@ -299,7 +300,7 @@ DottedName: String = {
GlobalStatement: ast::Stmt = {
<location:@L> "global" <names:OneOrMore<Identifier>> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtGlobal { names }.into()
)
@ -309,7 +310,7 @@ GlobalStatement: ast::Stmt = {
NonlocalStatement: ast::Stmt = {
<location:@L> "nonlocal" <names:OneOrMore<Identifier>> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtNonlocal { names }.into()
)
@ -319,7 +320,7 @@ NonlocalStatement: ast::Stmt = {
AssertStatement: ast::Stmt = {
<location:@L> "assert" <test:Test<"all">> <msg: ("," Test<"all">)?> <end_location:@R> => {
ast::Stmt::new(
location,
location..
end_location,
ast::StmtAssert {
test: Box::new(test),
@ -350,7 +351,7 @@ MatchStatement: ast::Stmt = {
.unwrap()
.end();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtMatch {
subject: Box::new(subject),
@ -367,7 +368,7 @@ MatchStatement: ast::Stmt = {
.unwrap()
.end();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtMatch {
subject: Box::new(subject),
@ -386,11 +387,11 @@ MatchStatement: ast::Stmt = {
let mut subjects = subjects;
subjects.insert(0, subject);
ast::Stmt::new(
location,
location..
end_location,
ast::StmtMatch {
subject: Box::new(ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple {
elts: subjects,
@ -421,7 +422,7 @@ Guard: ast::Expr = {
Patterns: ast::Pattern = {
<location:@L> <pattern:Pattern> "," <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
ast::PatternMatchSequence {
patterns: vec![pattern]
@ -431,7 +432,7 @@ Patterns: ast::Pattern = {
let mut patterns = patterns;
patterns.insert(0, pattern);
ast::Pattern::new(
location,
location..
end_location,
ast::PatternMatchSequence {
patterns
@ -455,7 +456,7 @@ AsPattern: ast::Pattern = {
})?
} else {
Ok(ast::Pattern::new(
location,
location..
end_location,
ast::PatternMatchAs {
pattern: Some(Box::new(pattern)),
@ -472,7 +473,7 @@ OrPattern: ast::Pattern = {
let mut patterns = patterns;
patterns.insert(0, pattern);
ast::Pattern::new(
location,
location..
end_location,
ast::PatternMatchOr { patterns }.into()
)
@ -481,37 +482,37 @@ OrPattern: ast::Pattern = {
ClosedPattern: ast::Pattern = {
<location:@L> <node:LiteralPattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:CapturePattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:StarPattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:ValuePattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:SequencePattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:MappingPattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
<location:@L> <node:ClassPattern> <end_location:@R> => ast::Pattern::new(
location,
location..
end_location,
node,
),
@ -543,7 +544,7 @@ StarPattern: ast::PatternKind = {
ConstantAtom: ast::Expr = {
<location:@L> <value:Constant> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprConstant { value, kind: None }.into()
),
@ -552,7 +553,7 @@ ConstantAtom: ast::Expr = {
ConstantExpr: ast::Expr = {
ConstantAtom,
<location:@L> "-" <operand:ConstantAtom> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprUnaryOp {
op: ast::Unaryop::USub,
@ -563,7 +564,7 @@ ConstantExpr: ast::Expr = {
AddOpExpr: ast::Expr = {
<location:@L> <left:ConstantExpr> <op:AddOp> <right:ConstantAtom> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp {
left: Box::new(left),
@ -603,7 +604,7 @@ CapturePattern: ast::PatternKind = {
MatchName: ast::Expr = {
<location:@L> <name:Identifier> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into(),
),
@ -611,7 +612,7 @@ MatchName: ast::Expr = {
MatchNameOrAttr: ast::Expr = {
<location:@L> <name:MatchName> "." <attr:Identifier> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprAttribute {
value: Box::new(name),
@ -620,7 +621,7 @@ MatchNameOrAttr: ast::Expr = {
}.into(),
),
<location:@L> <e:MatchNameOrAttr> "." <attr:Identifier> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprAttribute {
value: Box::new(e),
@ -641,7 +642,7 @@ MappingKey: ast::Expr = {
AddOpExpr,
MatchNameOrAttr,
<location:@L> "None" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprConstant {
value: ast::Constant::None,
@ -649,7 +650,7 @@ MappingKey: ast::Expr = {
}.into(),
),
<location:@L> "True" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprConstant {
value: true.into(),
@ -657,7 +658,7 @@ MappingKey: ast::Expr = {
}.into(),
),
<location:@L> "False" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprConstant {
value: false.into(),
@ -804,7 +805,7 @@ IfStatement: ast::Stmt = {
// handle elif:
for i in s2.into_iter().rev() {
let x = ast::Stmt::new(
i.0,
i.0..
end_location,
ast::StmtIf { test: Box::new(i.2), body: i.4, orelse: last }.into()
);
@ -812,7 +813,7 @@ IfStatement: ast::Stmt = {
}
ast::Stmt::new(
location,
location..
end_location,
ast::StmtIf { test: Box::new(test), body, orelse: last }.into()
)
@ -828,7 +829,7 @@ WhileStatement: ast::Stmt = {
.unwrap()
.end();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtWhile {
test: Box::new(test),
@ -855,7 +856,7 @@ ForStatement: ast::Stmt = {
} else {
ast::StmtFor { target, iter, body, orelse, type_comment }.into()
};
ast::Stmt::new(location, end_location, node)
ast::Stmt::new(location..end_location, node)
},
};
@ -870,7 +871,7 @@ TryStatement: ast::Stmt = {
.or_else(|| handlers.last().map(|last| last.end()))
.unwrap();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtTry {
body,
@ -890,7 +891,7 @@ TryStatement: ast::Stmt = {
.or_else(|| handlers.last().map(|last| last.end()))
.unwrap();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtTryStar {
body,
@ -906,7 +907,7 @@ TryStatement: ast::Stmt = {
let finalbody = finally.2;
let end_location = finalbody.last().unwrap().end();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtTry {
body,
@ -922,7 +923,7 @@ ExceptStarClause: ast::Excepthandler = {
<location:@L> "except" "*" <typ:Test<"all">> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::new(
location,
location..
end_location,
ast::ExcepthandlerExceptHandler {
type_: Some(Box::new(typ)),
@ -934,7 +935,7 @@ ExceptStarClause: ast::Excepthandler = {
<location:@L> "except" "*" <x:(Test<"all"> "as" Identifier)> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::new(
location,
location..
end_location,
ast::ExcepthandlerExceptHandler {
type_: Some(Box::new(x.0)),
@ -950,7 +951,7 @@ ExceptClause: ast::Excepthandler = {
<location:@L> "except" <typ:Test<"all">?> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::new(
location,
location..
end_location,
ast::ExcepthandlerExceptHandler {
type_: typ.map(Box::new),
@ -962,7 +963,7 @@ ExceptClause: ast::Excepthandler = {
<location:@L> "except" <x:(Test<"all"> "as" Identifier)> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::new(
location,
location..
end_location,
ast::ExcepthandlerExceptHandler {
type_: Some(Box::new(x.0)),
@ -982,7 +983,7 @@ WithStatement: ast::Stmt = {
} else {
ast::StmtWith { items, body, type_comment }.into()
};
ast::Stmt::new(location, end_location, node)
ast::Stmt::new(location..end_location, node)
},
};
@ -1023,7 +1024,7 @@ FuncDef: ast::Stmt = {
} else {
ast::StmtFunctionDef { name, args, body, decorator_list, returns, type_comment }.into()
};
ast::Stmt::new(location, end_location, node)
ast::Stmt::new(location..end_location, node)
},
};
@ -1126,7 +1127,7 @@ ParameterDef<ArgType>: (ast::Arg, Option<ast::Expr>) = {
UntypedParameter: ast::Arg = {
<location:@L> <arg:Identifier> <end_location:@R> => ast::Arg::new(
location,
location..
end_location,
ast::ArgData { arg, annotation: None, type_comment: None },
),
@ -1135,14 +1136,14 @@ UntypedParameter: ast::Arg = {
TypedParameter: ast::Arg = {
<location:@L> <arg:Identifier> <a:(":" Test<"all">)?> <end_location:@R> => {
let annotation = a.map(|x| Box::new(x.1));
ast::Arg::new(location, end_location, ast::ArgData { arg, annotation, type_comment: None })
ast::Arg::new(location..end_location, ast::ArgData { arg, annotation, type_comment: None })
},
};
StarTypedParameter: ast::Arg = {
<location:@L> <arg:Identifier> <a:(":" TestOrStarExpr)?> <end_location:@R> => {
let annotation = a.map(|x| Box::new(x.1));
ast::Arg::new(location, end_location, ast::ArgData { arg, annotation, type_comment: None })
ast::Arg::new(location..end_location, ast::ArgData { arg, annotation, type_comment: None })
},
};
@ -1193,7 +1194,7 @@ ClassDef: ast::Stmt = {
};
let end_location = body.last().unwrap().end();
ast::Stmt::new(
location,
location..
end_location,
ast::StmtClassDef {
name,
@ -1215,12 +1216,12 @@ Decorator: ast::Expr = {
YieldExpr: ast::Expr = {
<location:@L> "yield" <value:TestList?> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprYield { value: value.map(Box::new) }.into()
),
<location:@L> "yield" "from" <e:Test<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprYieldFrom { value: Box::new(e) }.into()
),
@ -1228,7 +1229,7 @@ YieldExpr: ast::Expr = {
Test<Goal>: ast::Expr = {
<location:@L> <body:OrTest<"all">> "if" <test:OrTest<"all">> "else" <orelse:Test<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprIfExp {
test: Box::new(test),
@ -1248,11 +1249,11 @@ NamedExpressionTest: ast::Expr = {
NamedExpression: ast::Expr = {
<location:@L> <id:Identifier> <end_location:@R> ":=" <value:Test<"all">> => {
ast::Expr::new(
location,
location..
value.end(),
ast::ExprNamedExpr {
target: Box::new(ast::Expr::new(
location,
location..
end_location,
ast::ExprName { id, ctx: ast::ExprContext::Store }.into(),
)),
@ -1279,7 +1280,7 @@ LambdaDef: ast::Expr = {
))?;
Ok(ast::Expr::new(
location,
location..
end_location,
ast::ExprLambda {
args: Box::new(p),
@ -1294,7 +1295,7 @@ OrTest<Goal>: ast::Expr = {
let mut values = vec![e1];
values.extend(e2.into_iter().map(|e| e.1));
ast::Expr::new(
location,
location..
end_location,
ast::ExprBoolOp { op: ast::Boolop::Or, values }.into()
)
@ -1307,7 +1308,7 @@ AndTest<Goal>: ast::Expr = {
let mut values = vec![e1];
values.extend(e2.into_iter().map(|e| e.1));
ast::Expr::new(
location,
location..
end_location,
ast::ExprBoolOp { op: ast::Boolop::And, values }.into()
)
@ -1317,7 +1318,7 @@ AndTest<Goal>: ast::Expr = {
NotTest<Goal>: ast::Expr = {
<location:@L> "not" <e:NotTest<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not }.into()
),
@ -1328,7 +1329,7 @@ Comparison<Goal>: ast::Expr = {
<location:@L> <left:Expression<"all">> <comparisons:(CompOp Expression<"all">)+> <end_location:@R> => {
let (ops, comparators) = comparisons.into_iter().unzip();
ast::Expr::new(
location,
location..
end_location,
ast::ExprCompare { left: Box::new(left), ops, comparators }.into()
)
@ -1351,7 +1352,7 @@ CompOp: ast::Cmpop = {
Expression<Goal>: ast::Expr = {
<location:@L> <e1:Expression<"all">> "|" <e2:XorExpression<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) }.into()
),
@ -1360,7 +1361,7 @@ Expression<Goal>: ast::Expr = {
XorExpression<Goal>: ast::Expr = {
<location:@L> <e1:XorExpression<"all">> "^" <e2:AndExpression<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) }.into()
),
@ -1369,7 +1370,7 @@ XorExpression<Goal>: ast::Expr = {
AndExpression<Goal>: ast::Expr = {
<location:@L> <e1:AndExpression<"all">> "&" <e2:ShiftExpression<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) }.into()
),
@ -1378,7 +1379,7 @@ AndExpression<Goal>: ast::Expr = {
ShiftExpression<Goal>: ast::Expr = {
<location:@L> <e1:ShiftExpression<"all">> <op:ShiftOp> <e2:ArithmeticExpression<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) }.into()
),
@ -1392,7 +1393,7 @@ ShiftOp: ast::Operator = {
ArithmeticExpression<Goal>: ast::Expr = {
<location:@L> <a:ArithmeticExpression<"all">> <op:AddOp> <b:Term<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into()
),
@ -1406,7 +1407,7 @@ AddOp: ast::Operator = {
Term<Goal>: ast::Expr = {
<location:@L> <a:Term<"all">> <op:MulOp> <b:Factor<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into()
),
@ -1423,7 +1424,7 @@ MulOp: ast::Operator = {
Factor<Goal>: ast::Expr = {
<location:@L> <op:UnaryOp> <e:Factor<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprUnaryOp { operand: Box::new(e), op }.into()
),
@ -1438,7 +1439,7 @@ UnaryOp: ast::Unaryop = {
Power<Goal>: ast::Expr = {
<location:@L> <e:AtomExpr<"all">> "**" <b:Factor<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) }.into()
),
@ -1448,7 +1449,7 @@ Power<Goal>: ast::Expr = {
AtomExpr<Goal>: ast::Expr = {
<location:@L> "await" <atom:AtomExpr2<"all">> <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprAwait { value: Box::new(atom) }.into()
)
@ -1460,18 +1461,18 @@ AtomExpr2<Goal>: ast::Expr = {
Atom<Goal>,
<location:@L> <f:AtomExpr2<"all">> "(" <a:ArgumentList> ")" <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords }.into()
)
},
<location:@L> <e:AtomExpr2<"all">> "[" <s:SubscriptList> "]" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load }.into()
),
<location:@L> <e:AtomExpr2<"all">> "." <attr:Identifier> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load }.into()
),
@ -1488,7 +1489,7 @@ SubscriptList: ast::Expr = {
}
ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple { elts: dims, ctx: ast::ExprContext::Load }.into(),
)
@ -1503,7 +1504,7 @@ Subscript: ast::Expr = {
let upper = e2.map(Box::new);
let step = e3.flatten().map(Box::new);
ast::Expr::new(
location,
location..
end_location,
ast::ExprSlice { lower, upper, step }.into()
)
@ -1517,26 +1518,26 @@ SliceOp: Option<ast::Expr> = {
Atom<Goal>: ast::Expr = {
<location:@L> <s:(@L string @R)+> =>? Ok(parse_strings(s)?),
<location:@L> <value:Constant> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprConstant { value, kind: None }.into()
),
<location:@L> <name:Identifier> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into()
),
<location:@L> "[" <e:ListLiteralValues?> "]"<end_location:@R> => {
let elts = e.unwrap_or_default();
ast::Expr::new(
location,
location..
end_location,
ast::ExprList { elts, ctx: ast::ExprContext::Load }.into()
)
},
<location:@L> "[" <elt:TestOrStarNamedExpr> <generators:CompFor> "]" <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprListComp { elt: Box::new(elt), generators }.into()
)
@ -1546,7 +1547,7 @@ Atom<Goal>: ast::Expr = {
elts.into_iter().next().unwrap()
} else {
ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into()
)
@ -1564,21 +1565,21 @@ Atom<Goal>: ast::Expr = {
} else {
let elts = left.into_iter().flatten().chain([mid]).chain(right).collect();
Ok(ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into(),
))
}
},
<location:@L> "(" ")" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load }.into()
),
"(" <e:YieldExpr> ")" => e,
<location:@L> "(" <elt:NamedExpressionTest> <generators:CompFor> ")" <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprGeneratorExp { elt: Box::new(elt), generators }.into()
)
@ -1596,14 +1597,14 @@ Atom<Goal>: ast::Expr = {
.map(|(k, v)| (k.map(|x| *x), v))
.unzip();
ast::Expr::new(
location,
location..
end_location,
ast::ExprDict { keys, values }.into()
)
},
<location:@L> "{" <e1:DictEntry> <generators:CompFor> "}" <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprDictComp {
key: Box::new(e1.0),
@ -1613,21 +1614,21 @@ Atom<Goal>: ast::Expr = {
)
},
<location:@L> "{" <elts:SetLiteralValues> "}" <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprSet { elts }.into()
),
<location:@L> "{" <elt:NamedExpressionTest> <generators:CompFor> "}" <end_location:@R> => {
ast::Expr::new(
location,
location..
end_location,
ast::ExprSetComp { elt: Box::new(elt), generators }.into()
)
},
<location:@L> "True" <end_location:@R> => ast::Expr::new(location, end_location, ast::ExprConstant { value: true.into(), kind: None }.into()),
<location:@L> "False" <end_location:@R> => ast::Expr::new(location, end_location, ast::ExprConstant { value: false.into(), kind: None }.into()),
<location:@L> "None" <end_location:@R> => ast::Expr::new(location, end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }.into()),
<location:@L> "..." <end_location:@R> => ast::Expr::new(location, end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }.into()),
<location:@L> "True" <end_location:@R> => ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }.into()),
<location:@L> "False" <end_location:@R> => ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }.into()),
<location:@L> "None" <end_location:@R> => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }.into()),
<location:@L> "..." <end_location:@R> => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }.into()),
};
ListLiteralValues: Vec<ast::Expr> = {
@ -1679,7 +1680,7 @@ GenericList<Element>: ast::Expr = {
elts.into_iter().next().unwrap()
} else {
ast::Expr::new(
location,
location..
end_location,
ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into()
)
@ -1690,7 +1691,7 @@ GenericList<Element>: ast::Expr = {
// Test
StarExpr: ast::Expr = {
<location:@L> "*" <e:Expression<"all">> <end_location:@R> => ast::Expr::new(
location,
location..
end_location,
ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(),
)
@ -1721,12 +1722,11 @@ ArgumentList: ArgumentList = {
}
};
FunctionArgument: (Option<(ast::Location, ast::Location, Option<String>)>, ast::Expr) = {
FunctionArgument: (Option<(TextSize, TextSize, Option<String>)>, ast::Expr) = {
<location:@L> <e:NamedExpressionTest> <c:CompFor?> <end_location:@R> => {
let expr = match c {
Some(c) => ast::Expr::new(
location,
end_location,
location..end_location,
ast::ExprGeneratorExp {
elt: Box::new(e),
generators: c,
@ -1739,7 +1739,7 @@ FunctionArgument: (Option<(ast::Location, ast::Location, Option<String>)>, ast::
<location:@L> <i:Identifier> "=" <e:Test<"all">> <end_location:@R> => (Some((location, end_location, Some(i))), e),
<location:@L> "*" <e:Test<"all">> <end_location:@R> => {
let expr = ast::Expr::new(
location,
location..
end_location,
ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(),
);
@ -1776,7 +1776,7 @@ Identifier: String = <s:name> => s;
// Hook external lexer:
extern {
type Location = ast::Location;
type Location = TextSize;
type Error = LexicalError;
enum token::Tok {

19203
parser/src/python.rs generated

File diff suppressed because it is too large Load diff

View file

@ -3,31 +3,13 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 0..10,
custom: (),
node: AnnAssign(
StmtAnnAssign {
target: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
target: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -36,17 +18,8 @@ expression: parse_ast
},
),
},
annotation: Located {
location: Location {
row: 1,
column: 3,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
annotation: Attributed {
range: 3..6,
custom: (),
node: Name(
ExprName {
@ -56,17 +29,8 @@ expression: parse_ast
),
},
value: Some(
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,46 +3,19 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 0..15,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
Attributed {
range: 0..3,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
value: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -57,32 +30,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
value: Attributed {
range: 6..15,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: Constant(
ExprConstant {
@ -93,17 +48,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {
@ -114,17 +60,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 24,
},
),
Attributed {
range: 0..24,
custom: (),
node: For(
StmtFor {
target: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
target: Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {
@ -36,32 +18,14 @@ expression: parse_ast
},
),
},
iter: Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
iter: Attributed {
range: 9..18,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {
@ -72,17 +36,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Constant(
ExprConstant {
@ -93,17 +48,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 16..17,
custom: (),
node: Constant(
ExprConstant {
@ -120,17 +66,8 @@ expression: parse_ast
),
},
body: [
Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 24,
},
),
Attributed {
range: 20..24,
custom: (),
node: Pass,
},

View file

@ -3,47 +3,20 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 0..18,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 0..6,
custom: (),
node: List(
ExprList {
elts: [
Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -52,17 +25,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {
@ -77,32 +41,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
value: Attributed {
range: 9..18,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {
@ -113,17 +59,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Constant(
ExprConstant {
@ -134,17 +71,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 16..17,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,32 +3,14 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -38,31 +20,13 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
value: Attributed {
range: 4..26,
custom: (),
node: ListComp(
ExprListComp {
elt: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
elt: Attributed {
range: 5..6,
custom: (),
node: Name(
ExprName {
@ -73,17 +37,8 @@ expression: parse_ast
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
target: Attributed {
range: 11..12,
custom: (),
node: Name(
ExprName {
@ -92,32 +47,14 @@ expression: parse_ast
},
),
},
iter: Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
iter: Attributed {
range: 16..25,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 17..18,
custom: (),
node: Constant(
ExprConstant {
@ -128,17 +65,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 21,
},
),
Attributed {
range: 20..21,
custom: (),
node: Constant(
ExprConstant {
@ -149,17 +77,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 23,
},
end_location: Some(
Location {
row: 1,
column: 24,
},
),
Attributed {
range: 23..24,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,32 +3,14 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 0..13,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -38,32 +20,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
value: Attributed {
range: 4..13,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 5..6,
custom: (),
node: Constant(
ExprConstant {
@ -74,17 +38,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 8..9,
custom: (),
node: Constant(
ExprConstant {
@ -95,17 +50,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 11..12,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,45 +3,18 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: If(
StmtIf {
test: Located {
location: Location {
row: 1,
column: 3,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
test: Attributed {
range: 3..8,
custom: (),
node: NamedExpr(
ExprNamedExpr {
target: Located {
location: Location {
row: 1,
column: 3,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
target: Attributed {
range: 3..4,
custom: (),
node: Name(
ExprName {
@ -50,17 +23,8 @@ expression: parse_ast
},
),
},
value: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
value: Attributed {
range: 7..8,
custom: (),
node: Constant(
ExprConstant {
@ -75,17 +39,8 @@ expression: parse_ast
),
},
body: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 10..14,
custom: (),
node: Pass,
},

View file

@ -3,32 +3,14 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -38,31 +20,13 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
value: Attributed {
range: 4..26,
custom: (),
node: SetComp(
ExprSetComp {
elt: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
elt: Attributed {
range: 5..6,
custom: (),
node: Name(
ExprName {
@ -73,17 +37,8 @@ expression: parse_ast
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
target: Attributed {
range: 11..12,
custom: (),
node: Name(
ExprName {
@ -92,32 +47,14 @@ expression: parse_ast
},
),
},
iter: Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
iter: Attributed {
range: 16..25,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 17..18,
custom: (),
node: Constant(
ExprConstant {
@ -128,17 +65,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 21,
},
),
Attributed {
range: 20..21,
custom: (),
node: Constant(
ExprConstant {
@ -149,17 +77,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 23,
},
end_location: Some(
Location {
row: 1,
column: 24,
},
),
Attributed {
range: 23..24,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,47 +3,20 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 0..19,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 0..7,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -52,31 +25,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 4..6,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
value: Attributed {
range: 5..6,
custom: (),
node: Name(
ExprName {
@ -95,32 +50,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
value: Attributed {
range: 10..19,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 11..12,
custom: (),
node: Constant(
ExprConstant {
@ -131,17 +68,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 14..15,
custom: (),
node: Constant(
ExprConstant {
@ -152,17 +80,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 17..18,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,46 +3,19 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 0..16,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
Attributed {
range: 0..4,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
value: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -51,17 +24,8 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 1,
column: 2,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
slice: Attributed {
range: 2..3,
custom: (),
node: Name(
ExprName {
@ -75,32 +39,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
value: Attributed {
range: 7..16,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 8..9,
custom: (),
node: Constant(
ExprConstant {
@ -111,17 +57,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 11..12,
custom: (),
node: Constant(
ExprConstant {
@ -132,17 +69,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 14..15,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,47 +3,20 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 0..18,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 0..6,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -52,17 +25,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {
@ -77,32 +41,14 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
value: Attributed {
range: 9..18,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {
@ -113,17 +59,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Constant(
ExprConstant {
@ -134,17 +71,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 16..17,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,33 +3,15 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 0..17,
custom: (),
node: With(
StmtWith {
items: [
Withitem {
context_expr: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
context_expr: Attributed {
range: 5..6,
custom: (),
node: Constant(
ExprConstant {
@ -41,17 +23,8 @@ expression: parse_ast
),
},
optional_vars: Some(
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Name(
ExprName {
@ -64,17 +37,8 @@ expression: parse_ast
},
],
body: [
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 13..17,
custom: (),
node: Pass,
},

View file

@ -3,45 +3,18 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 0..16,
custom: (),
node: AugAssign(
StmtAugAssign {
target: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
target: Attributed {
range: 0..3,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
value: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -56,32 +29,14 @@ expression: parse_ast
),
},
op: Add,
value: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
value: Attributed {
range: 7..16,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 8..9,
custom: (),
node: Constant(
ExprConstant {
@ -92,17 +47,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 11..12,
custom: (),
node: Constant(
ExprConstant {
@ -113,17 +59,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 14..15,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 0..6,
custom: (),
node: AugAssign(
StmtAugAssign {
target: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
target: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -37,17 +19,8 @@ expression: parse_ast
),
},
op: Add,
value: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
value: Attributed {
range: 5..6,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,45 +3,18 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 0..17,
custom: (),
node: AugAssign(
StmtAugAssign {
target: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
target: Attributed {
range: 0..4,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
value: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -50,17 +23,8 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 1,
column: 2,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
slice: Attributed {
range: 2..3,
custom: (),
node: Name(
ExprName {
@ -74,32 +38,14 @@ expression: parse_ast
),
},
op: Add,
value: Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
value: Attributed {
range: 8..17,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: Constant(
ExprConstant {
@ -110,17 +56,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: Constant(
ExprConstant {
@ -131,17 +68,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 15,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 15..16,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,46 +3,19 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 0..7,
custom: (),
node: Delete(
StmtDelete {
targets: [
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 4..7,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
value: Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {

View file

@ -3,32 +3,14 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
Attributed {
range: 0..5,
custom: (),
node: Delete(
StmtDelete {
targets: [
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {

View file

@ -3,46 +3,19 @@ source: parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 0..8,
custom: (),
node: Delete(
StmtDelete {
targets: [
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 4..8,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
value: Attributed {
range: 4..5,
custom: (),
node: Name(
ExprName {
@ -51,17 +24,8 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
slice: Attributed {
range: 6..7,
custom: (),
node: Name(
ExprName {

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 0..23,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -24,17 +15,8 @@ Ok(
args: [],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "a",
@ -42,17 +24,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "b",
@ -60,17 +33,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 15,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 15..16,
custom: (),
node: ArgData {
arg: "c",
@ -84,17 +48,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 19,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 19..23,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 29,
},
),
Attributed {
range: 0..29,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -24,17 +15,8 @@ Ok(
args: [],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "a",
@ -42,17 +24,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "b",
@ -60,17 +33,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 18,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 18..19,
custom: (),
node: ArgData {
arg: "c",
@ -80,17 +44,8 @@ Ok(
},
],
kw_defaults: [
Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 14..16,
custom: (),
node: Constant(
ExprConstant {
@ -101,17 +56,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 22,
},
),
Attributed {
range: 20..22,
custom: (),
node: Constant(
ExprConstant {
@ -127,17 +73,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 25,
},
end_location: Some(
Location {
row: 1,
column: 29,
},
),
Attributed {
range: 25..29,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 0..13,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -29,17 +20,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 9..13,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
Attributed {
range: 0..32,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "c",
@ -79,17 +43,8 @@ Ok(
],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 18,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 18..19,
custom: (),
node: ArgData {
arg: "d",
@ -97,17 +52,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 22,
},
),
Attributed {
range: 21..22,
custom: (),
node: ArgData {
arg: "e",
@ -115,17 +61,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 24,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
Attributed {
range: 24..25,
custom: (),
node: ArgData {
arg: "f",
@ -139,17 +76,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 28,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
Attributed {
range: 28..32,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 38,
},
),
Attributed {
range: 0..38,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "c",
@ -79,17 +43,8 @@ Ok(
],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 18,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 18..19,
custom: (),
node: ArgData {
arg: "d",
@ -97,17 +52,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 22,
},
),
Attributed {
range: 21..22,
custom: (),
node: ArgData {
arg: "e",
@ -115,17 +61,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 27,
},
end_location: Some(
Location {
row: 1,
column: 28,
},
),
Attributed {
range: 27..28,
custom: (),
node: ArgData {
arg: "f",
@ -135,17 +72,8 @@ Ok(
},
],
kw_defaults: [
Located {
location: Location {
row: 1,
column: 23,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
Attributed {
range: 23..25,
custom: (),
node: Constant(
ExprConstant {
@ -156,17 +84,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 29,
},
end_location: Some(
Location {
row: 1,
column: 31,
},
),
Attributed {
range: 29..31,
custom: (),
node: Constant(
ExprConstant {
@ -182,17 +101,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 34,
},
end_location: Some(
Location {
row: 1,
column: 38,
},
),
Attributed {
range: 34..38,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 42,
},
),
Attributed {
range: 0..42,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "c",
@ -78,17 +42,8 @@ Ok(
},
],
vararg: Some(
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 16..20,
custom: (),
node: ArgData {
arg: "args",
@ -98,17 +53,8 @@ Ok(
},
),
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 22..23,
custom: (),
node: ArgData {
arg: "d",
@ -116,17 +62,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 25,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 25..26,
custom: (),
node: ArgData {
arg: "e",
@ -134,17 +71,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 31,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
Attributed {
range: 31..32,
custom: (),
node: ArgData {
arg: "f",
@ -154,17 +82,8 @@ Ok(
},
],
kw_defaults: [
Located {
location: Location {
row: 1,
column: 27,
},
end_location: Some(
Location {
row: 1,
column: 29,
},
),
Attributed {
range: 27..29,
custom: (),
node: Constant(
ExprConstant {
@ -175,17 +94,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 33,
},
end_location: Some(
Location {
row: 1,
column: 35,
},
),
Attributed {
range: 33..35,
custom: (),
node: Constant(
ExprConstant {
@ -201,17 +111,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 38,
},
end_location: Some(
Location {
row: 1,
column: 42,
},
),
Attributed {
range: 38..42,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 52,
},
),
Attributed {
range: 0..52,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "c",
@ -78,17 +42,8 @@ Ok(
},
],
vararg: Some(
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 16..20,
custom: (),
node: ArgData {
arg: "args",
@ -98,17 +53,8 @@ Ok(
},
),
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 22..23,
custom: (),
node: ArgData {
arg: "d",
@ -116,17 +62,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 25,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 25..26,
custom: (),
node: ArgData {
arg: "e",
@ -134,17 +71,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 31,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
Attributed {
range: 31..32,
custom: (),
node: ArgData {
arg: "f",
@ -154,17 +82,8 @@ Ok(
},
],
kw_defaults: [
Located {
location: Location {
row: 1,
column: 27,
},
end_location: Some(
Location {
row: 1,
column: 29,
},
),
Attributed {
range: 27..29,
custom: (),
node: Constant(
ExprConstant {
@ -175,17 +94,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 33,
},
end_location: Some(
Location {
row: 1,
column: 35,
},
),
Attributed {
range: 33..35,
custom: (),
node: Constant(
ExprConstant {
@ -198,17 +108,8 @@ Ok(
},
],
kwarg: Some(
Located {
location: Location {
row: 1,
column: 39,
},
end_location: Some(
Location {
row: 1,
column: 45,
},
),
Attributed {
range: 39..45,
custom: (),
node: ArgData {
arg: "kwargs",
@ -220,17 +121,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 48,
},
end_location: Some(
Location {
row: 1,
column: 52,
},
),
Attributed {
range: 48..52,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 0..20,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 12..13,
custom: (),
node: ArgData {
arg: "c",
@ -84,17 +48,8 @@ Ok(
defaults: [],
},
body: [
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 16..20,
custom: (),
node: Pass,
},

View file

@ -4,17 +4,8 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,17 +13,8 @@ Ok(
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: ArgData {
arg: "a",
@ -40,17 +22,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 9,
},
end_location: Some(
Location {
row: 1,
column: 10,
},
),
Attributed {
range: 9..10,
custom: (),
node: ArgData {
arg: "b",
@ -58,17 +31,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 15,
},
end_location: Some(
Location {
row: 1,
column: 16,
},
),
Attributed {
range: 15..16,
custom: (),
node: ArgData {
arg: "c",
@ -82,17 +46,8 @@ Ok(
kw_defaults: [],
kwarg: None,
defaults: [
Located {
location: Location {
row: 1,
column: 11,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 11..13,
custom: (),
node: Constant(
ExprConstant {
@ -103,17 +58,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 17..19,
custom: (),
node: Constant(
ExprConstant {
@ -127,17 +73,8 @@ Ok(
],
},
body: [
Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 22..26,
custom: (),
node: Pass,
},

View file

@ -4,31 +4,13 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 0..20,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
value: Attributed {
range: 0..20,
custom: (),
node: Lambda(
ExprLambda {
@ -37,17 +19,8 @@ Ok(
args: [],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "a",
@ -55,17 +28,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: ArgData {
arg: "b",
@ -73,17 +37,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 16..17,
custom: (),
node: ArgData {
arg: "c",
@ -96,17 +51,8 @@ Ok(
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 19,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
body: Attributed {
range: 19..20,
custom: (),
node: Constant(
ExprConstant {

View file

@ -4,31 +4,13 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
value: Attributed {
range: 0..26,
custom: (),
node: Lambda(
ExprLambda {
@ -37,17 +19,8 @@ Ok(
args: [],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "a",
@ -55,17 +28,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: ArgData {
arg: "b",
@ -73,17 +37,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 19,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 19..20,
custom: (),
node: ArgData {
arg: "c",
@ -93,17 +48,8 @@ Ok(
},
],
kw_defaults: [
Located {
location: Location {
row: 1,
column: 15,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 15..17,
custom: (),
node: Constant(
ExprConstant {
@ -114,17 +60,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 21..23,
custom: (),
node: Constant(
ExprConstant {
@ -139,17 +76,8 @@ Ok(
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 25,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
body: Attributed {
range: 25..26,
custom: (),
node: Constant(
ExprConstant {

View file

@ -4,31 +4,13 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 0..9,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
value: Attributed {
range: 0..9,
custom: (),
node: Lambda(
ExprLambda {
@ -41,17 +23,8 @@ Ok(
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
body: Attributed {
range: 8..9,
custom: (),
node: Constant(
ExprConstant {

View file

@ -4,48 +4,21 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
value: Attributed {
range: 0..26,
custom: (),
node: Lambda(
ExprLambda {
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: ArgData {
arg: "a",
@ -53,17 +26,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "b",
@ -71,17 +35,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: ArgData {
arg: "c",
@ -92,17 +47,8 @@ Ok(
],
vararg: None,
kwonlyargs: [
Located {
location: Location {
row: 1,
column: 19,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 19..20,
custom: (),
node: ArgData {
arg: "d",
@ -110,17 +56,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 22..23,
custom: (),
node: ArgData {
arg: "e",
@ -133,17 +70,8 @@ Ok(
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 25,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
body: Attributed {
range: 25..26,
custom: (),
node: Constant(
ExprConstant {

View file

@ -4,48 +4,21 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 0..17,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
value: Attributed {
range: 0..17,
custom: (),
node: Lambda(
ExprLambda {
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: ArgData {
arg: "a",
@ -53,17 +26,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "b",
@ -71,17 +35,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: ArgData {
arg: "c",
@ -96,17 +51,8 @@ Ok(
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
body: Attributed {
range: 16..17,
custom: (),
node: Constant(
ExprConstant {

View file

@ -4,48 +4,21 @@ expression: parse_ast
---
Ok(
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 0..23,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
value: Attributed {
range: 0..23,
custom: (),
node: Lambda(
ExprLambda {
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: ArgData {
arg: "a",
@ -53,17 +26,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "b",
@ -71,17 +35,8 @@ Ok(
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
Attributed {
range: 16..17,
custom: (),
node: ArgData {
arg: "c",
@ -95,17 +50,8 @@ Ok(
kw_defaults: [],
kwarg: None,
defaults: [
Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 12..14,
custom: (),
node: Constant(
ExprConstant {
@ -116,17 +62,8 @@ Ok(
},
),
},
Located {
location: Location {
row: 1,
column: 18,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 18..20,
custom: (),
node: Constant(
ExprConstant {
@ -139,17 +76,8 @@ Ok(
},
],
},
body: Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
body: Attributed {
range: 22..23,
custom: (),
node: Constant(
ExprConstant {

View file

@ -2,33 +2,15 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
Attributed {
range: 0..25,
custom: (),
node: Dict(
ExprDict {
keys: [
Some(
Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
Attributed {
range: 1..4,
custom: (),
node: Constant(
ExprConstant {
@ -42,17 +24,8 @@ Located {
),
None,
Some(
Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 16..19,
custom: (),
node: Constant(
ExprConstant {
@ -66,17 +39,8 @@ Located {
),
],
values: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 6..9,
custom: (),
node: Constant(
ExprConstant {
@ -87,17 +51,8 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Name(
ExprName {
@ -106,17 +61,8 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 24,
},
),
Attributed {
range: 21..24,
custom: (),
node: Constant(
ExprConstant {

View file

@ -2,45 +2,18 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 7,
column: 1,
},
),
Attributed {
range: 0..141,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
func: Attributed {
range: 0..8,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
value: Attributed {
range: 0..3,
custom: (),
node: Constant(
ExprConstant {
@ -57,31 +30,13 @@ Located {
),
},
args: [
Located {
location: Location {
row: 2,
column: 4,
},
end_location: Some(
Location {
row: 6,
column: 5,
},
),
Attributed {
range: 14..139,
custom: (),
node: GeneratorExp(
ExprGeneratorExp {
elt: Located {
location: Location {
row: 2,
column: 4,
},
end_location: Some(
Location {
row: 2,
column: 7,
},
),
elt: Attributed {
range: 14..17,
custom: (),
node: Name(
ExprName {
@ -92,17 +47,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 3,
column: 8,
},
end_location: Some(
Location {
row: 3,
column: 11,
},
),
target: Attributed {
range: 26..29,
custom: (),
node: Name(
ExprName {
@ -111,46 +57,19 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 3,
column: 15,
},
end_location: Some(
Location {
row: 6,
column: 5,
},
),
iter: Attributed {
range: 33..139,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 4,
column: 8,
},
end_location: Some(
Location {
row: 4,
column: 45,
},
),
Attributed {
range: 43..80,
custom: (),
node: IfExp(
ExprIfExp {
test: Located {
location: Location {
row: 4,
column: 30,
},
end_location: Some(
Location {
row: 4,
column: 35,
},
),
test: Attributed {
range: 65..70,
custom: (),
node: Name(
ExprName {
@ -159,31 +78,13 @@ Located {
},
),
},
body: Located {
location: Location {
row: 4,
column: 8,
},
end_location: Some(
Location {
row: 4,
column: 26,
},
),
body: Attributed {
range: 43..61,
custom: (),
node: BinOp(
ExprBinOp {
left: Located {
location: Location {
row: 4,
column: 8,
},
end_location: Some(
Location {
row: 4,
column: 18,
},
),
left: Attributed {
range: 43..53,
custom: (),
node: Constant(
ExprConstant {
@ -195,17 +96,8 @@ Located {
),
},
op: Mod,
right: Located {
location: Location {
row: 4,
column: 21,
},
end_location: Some(
Location {
row: 4,
column: 26,
},
),
right: Attributed {
range: 56..61,
custom: (),
node: Name(
ExprName {
@ -217,17 +109,8 @@ Located {
},
),
},
orelse: Located {
location: Location {
row: 4,
column: 41,
},
end_location: Some(
Location {
row: 4,
column: 45,
},
),
orelse: Attributed {
range: 76..80,
custom: (),
node: Constant(
ExprConstant {
@ -239,31 +122,13 @@ Located {
},
),
},
Located {
location: Location {
row: 5,
column: 8,
},
end_location: Some(
Location {
row: 5,
column: 50,
},
),
Attributed {
range: 90..132,
custom: (),
node: IfExp(
ExprIfExp {
test: Located {
location: Location {
row: 5,
column: 34,
},
end_location: Some(
Location {
row: 5,
column: 40,
},
),
test: Attributed {
range: 116..122,
custom: (),
node: Name(
ExprName {
@ -272,31 +137,13 @@ Located {
},
),
},
body: Located {
location: Location {
row: 5,
column: 9,
},
end_location: Some(
Location {
row: 5,
column: 29,
},
),
body: Attributed {
range: 91..111,
custom: (),
node: BinOp(
ExprBinOp {
left: Located {
location: Location {
row: 5,
column: 9,
},
end_location: Some(
Location {
row: 5,
column: 20,
},
),
left: Attributed {
range: 91..102,
custom: (),
node: Constant(
ExprConstant {
@ -308,17 +155,8 @@ Located {
),
},
op: Mod,
right: Located {
location: Location {
row: 5,
column: 23,
},
end_location: Some(
Location {
row: 5,
column: 29,
},
),
right: Attributed {
range: 105..111,
custom: (),
node: Name(
ExprName {
@ -330,17 +168,8 @@ Located {
},
),
},
orelse: Located {
location: Location {
row: 5,
column: 46,
},
end_location: Some(
Location {
row: 5,
column: 50,
},
),
orelse: Attributed {
range: 128..132,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,47 +3,20 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 6,
column: 19,
},
),
Attributed {
range: 1..73,
custom: (),
node: Match(
StmtMatch {
subject: Located {
location: Location {
row: 2,
column: 6,
},
end_location: Some(
Location {
row: 2,
column: 17,
},
),
subject: Attributed {
range: 7..18,
custom: (),
node: Dict(
ExprDict {
keys: [
Some(
Located {
location: Location {
row: 2,
column: 7,
},
end_location: Some(
Location {
row: 2,
column: 13,
},
),
Attributed {
range: 8..14,
custom: (),
node: Constant(
ExprConstant {
@ -57,17 +30,8 @@ expression: parse_ast
),
],
values: [
Located {
location: Location {
row: 2,
column: 15,
},
end_location: Some(
Location {
row: 2,
column: 16,
},
),
Attributed {
range: 16..17,
custom: (),
node: Constant(
ExprConstant {
@ -84,17 +48,8 @@ expression: parse_ast
},
cases: [
MatchCase {
pattern: Located {
location: Location {
row: 3,
column: 9,
},
end_location: Some(
Location {
row: 5,
column: 5,
},
),
pattern: Attributed {
range: 29..52,
custom: (),
node: MatchMapping(
PatternMatchMapping {
@ -108,45 +63,18 @@ expression: parse_ast
},
guard: None,
body: [
Located {
location: Location {
row: 6,
column: 8,
},
end_location: Some(
Location {
row: 6,
column: 19,
},
),
Attributed {
range: 62..73,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 6,
column: 8,
},
end_location: Some(
Location {
row: 6,
column: 19,
},
),
value: Attributed {
range: 62..73,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 6,
column: 8,
},
end_location: Some(
Location {
row: 6,
column: 13,
},
),
func: Attributed {
range: 62..67,
custom: (),
node: Name(
ExprName {
@ -156,17 +84,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 6,
column: 14,
},
end_location: Some(
Location {
row: 6,
column: 18,
},
),
Attributed {
range: 68..72,
custom: (),
node: Name(
ExprName {
@ -189,47 +108,20 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 7,
column: 0,
},
end_location: Some(
Location {
row: 11,
column: 20,
},
),
Attributed {
range: 74..177,
custom: (),
node: Match(
StmtMatch {
subject: Located {
location: Location {
row: 7,
column: 6,
},
end_location: Some(
Location {
row: 7,
column: 23,
},
),
subject: Attributed {
range: 80..97,
custom: (),
node: Dict(
ExprDict {
keys: [
Some(
Located {
location: Location {
row: 7,
column: 7,
},
end_location: Some(
Location {
row: 7,
column: 14,
},
),
Attributed {
range: 81..88,
custom: (),
node: Constant(
ExprConstant {
@ -243,17 +135,8 @@ expression: parse_ast
),
],
values: [
Located {
location: Location {
row: 7,
column: 16,
},
end_location: Some(
Location {
row: 7,
column: 22,
},
),
Attributed {
range: 90..96,
custom: (),
node: Constant(
ExprConstant {
@ -270,32 +153,14 @@ expression: parse_ast
},
cases: [
MatchCase {
pattern: Located {
location: Location {
row: 8,
column: 9,
},
end_location: Some(
Location {
row: 10,
column: 5,
},
),
pattern: Attributed {
range: 108..155,
custom: (),
node: MatchMapping(
PatternMatchMapping {
keys: [
Located {
location: Location {
row: 9,
column: 8,
},
end_location: Some(
Location {
row: 9,
column: 15,
},
),
Attributed {
range: 118..125,
custom: (),
node: Constant(
ExprConstant {
@ -308,61 +173,25 @@ expression: parse_ast
},
],
patterns: [
Located {
location: Location {
row: 9,
column: 17,
},
end_location: Some(
Location {
row: 9,
column: 38,
},
),
Attributed {
range: 127..148,
custom: (),
node: MatchAs(
PatternMatchAs {
pattern: Some(
Located {
location: Location {
row: 9,
column: 17,
},
end_location: Some(
Location {
row: 9,
column: 29,
},
),
Attributed {
range: 127..139,
custom: (),
node: MatchOr(
PatternMatchOr {
patterns: [
Located {
location: Location {
row: 9,
column: 17,
},
end_location: Some(
Location {
row: 9,
column: 22,
},
),
Attributed {
range: 127..132,
custom: (),
node: MatchClass(
PatternMatchClass {
cls: Located {
location: Location {
row: 9,
column: 17,
},
end_location: Some(
Location {
row: 9,
column: 20,
},
),
cls: Attributed {
range: 127..130,
custom: (),
node: Name(
ExprName {
@ -377,17 +206,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 9,
column: 25,
},
end_location: Some(
Location {
row: 9,
column: 29,
},
),
Attributed {
range: 135..139,
custom: (),
node: MatchSingleton(
PatternMatchSingleton {
@ -413,45 +233,18 @@ expression: parse_ast
},
guard: None,
body: [
Located {
location: Location {
row: 11,
column: 8,
},
end_location: Some(
Location {
row: 11,
column: 20,
},
),
Attributed {
range: 165..177,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 11,
column: 8,
},
end_location: Some(
Location {
row: 11,
column: 20,
},
),
value: Attributed {
range: 165..177,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 11,
column: 8,
},
end_location: Some(
Location {
row: 11,
column: 13,
},
),
func: Attributed {
range: 165..170,
custom: (),
node: Name(
ExprName {
@ -461,17 +254,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 11,
column: 14,
},
end_location: Some(
Location {
row: 11,
column: 19,
},
),
Attributed {
range: 171..176,
custom: (),
node: Name(
ExprName {
@ -494,31 +278,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 12,
column: 0,
},
end_location: Some(
Location {
row: 14,
column: 13,
},
),
Attributed {
range: 178..218,
custom: (),
node: Match(
StmtMatch {
subject: Located {
location: Location {
row: 12,
column: 6,
},
end_location: Some(
Location {
row: 12,
column: 7,
},
),
subject: Attributed {
range: 184..185,
custom: (),
node: Name(
ExprName {
@ -529,46 +295,19 @@ expression: parse_ast
},
cases: [
MatchCase {
pattern: Located {
location: Location {
row: 13,
column: 9,
},
end_location: Some(
Location {
row: 13,
column: 16,
},
),
pattern: Attributed {
range: 196..203,
custom: (),
node: MatchSequence(
PatternMatchSequence {
patterns: [
Located {
location: Location {
row: 13,
column: 10,
},
end_location: Some(
Location {
row: 13,
column: 11,
},
),
Attributed {
range: 197..198,
custom: (),
node: MatchValue(
PatternMatchValue {
value: Located {
location: Location {
row: 13,
column: 10,
},
end_location: Some(
Location {
row: 13,
column: 11,
},
),
value: Attributed {
range: 197..198,
custom: (),
node: Constant(
ExprConstant {
@ -582,31 +321,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 13,
column: 13,
},
end_location: Some(
Location {
row: 13,
column: 14,
},
),
Attributed {
range: 200..201,
custom: (),
node: MatchValue(
PatternMatchValue {
value: Located {
location: Location {
row: 13,
column: 13,
},
end_location: Some(
Location {
row: 13,
column: 14,
},
),
value: Attributed {
range: 200..201,
custom: (),
node: Constant(
ExprConstant {
@ -626,32 +347,14 @@ expression: parse_ast
},
guard: None,
body: [
Located {
location: Location {
row: 14,
column: 8,
},
end_location: Some(
Location {
row: 14,
column: 13,
},
),
Attributed {
range: 213..218,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 14,
column: 8,
},
end_location: Some(
Location {
row: 14,
column: 9,
},
),
Attributed {
range: 213..214,
custom: (),
node: Name(
ExprName {
@ -661,17 +364,8 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 14,
column: 12,
},
end_location: Some(
Location {
row: 14,
column: 13,
},
),
value: Attributed {
range: 217..218,
custom: (),
node: Constant(
ExprConstant {
@ -692,31 +386,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 15,
column: 0,
},
end_location: Some(
Location {
row: 17,
column: 13,
},
),
Attributed {
range: 219..259,
custom: (),
node: Match(
StmtMatch {
subject: Located {
location: Location {
row: 15,
column: 6,
},
end_location: Some(
Location {
row: 15,
column: 7,
},
),
subject: Attributed {
range: 225..226,
custom: (),
node: Name(
ExprName {
@ -727,46 +403,19 @@ expression: parse_ast
},
cases: [
MatchCase {
pattern: Located {
location: Location {
row: 16,
column: 9,
},
end_location: Some(
Location {
row: 16,
column: 16,
},
),
pattern: Attributed {
range: 237..244,
custom: (),
node: MatchSequence(
PatternMatchSequence {
patterns: [
Located {
location: Location {
row: 16,
column: 10,
},
end_location: Some(
Location {
row: 16,
column: 11,
},
),
Attributed {
range: 238..239,
custom: (),
node: MatchValue(
PatternMatchValue {
value: Located {
location: Location {
row: 16,
column: 10,
},
end_location: Some(
Location {
row: 16,
column: 11,
},
),
value: Attributed {
range: 238..239,
custom: (),
node: Constant(
ExprConstant {
@ -780,31 +429,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 16,
column: 13,
},
end_location: Some(
Location {
row: 16,
column: 14,
},
),
Attributed {
range: 241..242,
custom: (),
node: MatchValue(
PatternMatchValue {
value: Located {
location: Location {
row: 16,
column: 13,
},
end_location: Some(
Location {
row: 16,
column: 14,
},
),
value: Attributed {
range: 241..242,
custom: (),
node: Constant(
ExprConstant {
@ -824,32 +455,14 @@ expression: parse_ast
},
guard: None,
body: [
Located {
location: Location {
row: 17,
column: 8,
},
end_location: Some(
Location {
row: 17,
column: 13,
},
),
Attributed {
range: 254..259,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 17,
column: 8,
},
end_location: Some(
Location {
row: 17,
column: 9,
},
),
Attributed {
range: 254..255,
custom: (),
node: Name(
ExprName {
@ -859,17 +472,8 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 17,
column: 12,
},
end_location: Some(
Location {
row: 17,
column: 13,
},
),
value: Attributed {
range: 258..259,
custom: (),
node: Constant(
ExprConstant {
@ -890,31 +494,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 18,
column: 0,
},
end_location: Some(
Location {
row: 20,
column: 13,
},
),
Attributed {
range: 260..297,
custom: (),
node: Match(
StmtMatch {
subject: Located {
location: Location {
row: 18,
column: 6,
},
end_location: Some(
Location {
row: 18,
column: 7,
},
),
subject: Attributed {
range: 266..267,
custom: (),
node: Name(
ExprName {
@ -925,46 +511,19 @@ expression: parse_ast
},
cases: [
MatchCase {
pattern: Located {
location: Location {
row: 19,
column: 9,
},
end_location: Some(
Location {
row: 19,
column: 13,
},
),
pattern: Attributed {
range: 278..282,
custom: (),
node: MatchSequence(
PatternMatchSequence {
patterns: [
Located {
location: Location {
row: 19,
column: 10,
},
end_location: Some(
Location {
row: 19,
column: 11,
},
),
Attributed {
range: 279..280,
custom: (),
node: MatchValue(
PatternMatchValue {
value: Located {
location: Location {
row: 19,
column: 10,
},
end_location: Some(
Location {
row: 19,
column: 11,
},
),
value: Attributed {
range: 279..280,
custom: (),
node: Constant(
ExprConstant {
@ -984,32 +543,14 @@ expression: parse_ast
},
guard: None,
body: [
Located {
location: Location {
row: 20,
column: 8,
},
end_location: Some(
Location {
row: 20,
column: 13,
},
),
Attributed {
range: 292..297,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 20,
column: 8,
},
end_location: Some(
Location {
row: 20,
column: 9,
},
),
Attributed {
range: 292..293,
custom: (),
node: Name(
ExprName {
@ -1019,17 +560,8 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 20,
column: 12,
},
end_location: Some(
Location {
row: 20,
column: 13,
},
),
value: Attributed {
range: 296..297,
custom: (),
node: Constant(
ExprConstant {

View file

@ -2,33 +2,15 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 0..7,
custom: (),
node: BoolOp(
ExprBoolOp {
op: And,
values: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -37,17 +19,8 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: Name(
ExprName {

View file

@ -2,33 +2,15 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 0..6,
custom: (),
node: BoolOp(
ExprBoolOp {
op: Or,
values: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -37,17 +19,8 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
Attributed {
range: 5..6,
custom: (),
node: Name(
ExprName {

View file

@ -3,33 +3,15 @@ source: parser/src/parser.rs
expression: "parse_program(source, \"<test>\").unwrap()"
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 5,
column: 6,
},
),
Attributed {
range: 0..98,
custom: (),
node: ClassDef(
StmtClassDef {
name: "Foo",
bases: [
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Name(
ExprName {
@ -38,17 +20,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
},
),
},
Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 13..14,
custom: (),
node: Name(
ExprName {
@ -60,17 +33,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
],
keywords: [],
body: [
Located {
location: Location {
row: 2,
column: 1,
},
end_location: Some(
Location {
row: 3,
column: 6,
},
),
Attributed {
range: 18..44,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -78,17 +42,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 2,
column: 14,
},
end_location: Some(
Location {
row: 2,
column: 18,
},
),
Attributed {
range: 31..35,
custom: (),
node: ArgData {
arg: "self",
@ -104,17 +59,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
defaults: [],
},
body: [
Located {
location: Location {
row: 3,
column: 2,
},
end_location: Some(
Location {
row: 3,
column: 6,
},
),
Attributed {
range: 40..44,
custom: (),
node: Pass,
},
@ -125,17 +71,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
},
),
},
Located {
location: Location {
row: 4,
column: 1,
},
end_location: Some(
Location {
row: 5,
column: 6,
},
),
Attributed {
range: 46..98,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -143,17 +80,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 4,
column: 25,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
Attributed {
range: 70..74,
custom: (),
node: ArgData {
arg: "self",
@ -161,17 +89,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
type_comment: None,
},
},
Located {
location: Location {
row: 4,
column: 31,
},
end_location: Some(
Location {
row: 4,
column: 34,
},
),
Attributed {
range: 76..79,
custom: (),
node: ArgData {
arg: "arg",
@ -185,17 +104,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
kw_defaults: [],
kwarg: None,
defaults: [
Located {
location: Location {
row: 4,
column: 35,
},
end_location: Some(
Location {
row: 4,
column: 44,
},
),
Attributed {
range: 80..89,
custom: (),
node: Constant(
ExprConstant {
@ -209,17 +119,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
],
},
body: [
Located {
location: Location {
row: 5,
column: 2,
},
end_location: Some(
Location {
row: 5,
column: 6,
},
),
Attributed {
range: 94..98,
custom: (),
node: Pass,
},

View file

@ -2,31 +2,13 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 0..19,
custom: (),
node: DictComp(
ExprDictComp {
key: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
key: Attributed {
range: 1..3,
custom: (),
node: Name(
ExprName {
@ -35,17 +17,8 @@ Located {
},
),
},
value: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
value: Attributed {
range: 5..7,
custom: (),
node: Name(
ExprName {
@ -56,17 +29,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
target: Attributed {
range: 12..13,
custom: (),
node: Name(
ExprName {
@ -75,17 +39,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
iter: Attributed {
range: 17..18,
custom: (),
node: Name(
ExprName {

View file

@ -2,31 +2,13 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 48,
},
),
Attributed {
range: 0..48,
custom: (),
node: ListComp(
ExprListComp {
elt: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
elt: Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -37,32 +19,14 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
target: Attributed {
range: 7..12,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: Name(
ExprName {
@ -71,17 +35,8 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 10..12,
custom: (),
node: Name(
ExprName {
@ -95,17 +50,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
iter: Attributed {
range: 16..17,
custom: (),
node: Name(
ExprName {
@ -118,17 +64,8 @@ Located {
is_async: 0,
},
Comprehension {
target: Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
target: Attributed {
range: 22..23,
custom: (),
node: Name(
ExprName {
@ -137,17 +74,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 27,
},
end_location: Some(
Location {
row: 1,
column: 28,
},
),
iter: Attributed {
range: 27..28,
custom: (),
node: Name(
ExprName {
@ -157,31 +85,13 @@ Located {
),
},
ifs: [
Located {
location: Location {
row: 1,
column: 32,
},
end_location: Some(
Location {
row: 1,
column: 37,
},
),
Attributed {
range: 32..37,
custom: (),
node: Compare(
ExprCompare {
left: Located {
location: Location {
row: 1,
column: 32,
},
end_location: Some(
Location {
row: 1,
column: 33,
},
),
left: Attributed {
range: 32..33,
custom: (),
node: Name(
ExprName {
@ -194,17 +104,8 @@ Located {
Lt,
],
comparators: [
Located {
location: Location {
row: 1,
column: 36,
},
end_location: Some(
Location {
row: 1,
column: 37,
},
),
Attributed {
range: 36..37,
custom: (),
node: Constant(
ExprConstant {
@ -219,31 +120,13 @@ Located {
},
),
},
Located {
location: Location {
row: 1,
column: 41,
},
end_location: Some(
Location {
row: 1,
column: 47,
},
),
Attributed {
range: 41..47,
custom: (),
node: Compare(
ExprCompare {
left: Located {
location: Location {
row: 1,
column: 41,
},
end_location: Some(
Location {
row: 1,
column: 42,
},
),
left: Attributed {
range: 41..42,
custom: (),
node: Name(
ExprName {
@ -256,17 +139,8 @@ Located {
Gt,
],
comparators: [
Located {
location: Location {
row: 1,
column: 45,
},
end_location: Some(
Location {
row: 1,
column: 47,
},
),
Attributed {
range: 45..47,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,46 +3,19 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
value: Attributed {
range: 0..14,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: Constant(
ExprConstant {

View file

@ -2,31 +2,13 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: GeneratorExp(
ExprGeneratorExp {
elt: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
elt: Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -37,17 +19,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
target: Attributed {
range: 7..8,
custom: (),
node: Name(
ExprName {
@ -56,17 +29,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
iter: Attributed {
range: 12..13,
custom: (),
node: Name(
ExprName {

View file

@ -3,31 +3,13 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 3,
column: 8,
},
),
Attributed {
range: 0..28,
custom: (),
node: If(
StmtIf {
test: Located {
location: Location {
row: 1,
column: 3,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
test: Attributed {
range: 3..4,
custom: (),
node: Constant(
ExprConstant {
@ -39,31 +21,13 @@ expression: parse_ast
),
},
body: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 6..8,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
value: Attributed {
range: 6..8,
custom: (),
node: Constant(
ExprConstant {
@ -79,31 +43,13 @@ expression: parse_ast
},
],
orelse: [
Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 3,
column: 8,
},
),
Attributed {
range: 9..28,
custom: (),
node: If(
StmtIf {
test: Located {
location: Location {
row: 2,
column: 5,
},
end_location: Some(
Location {
row: 2,
column: 6,
},
),
test: Attributed {
range: 14..15,
custom: (),
node: Constant(
ExprConstant {
@ -115,31 +61,13 @@ expression: parse_ast
),
},
body: [
Located {
location: Location {
row: 2,
column: 8,
},
end_location: Some(
Location {
row: 2,
column: 10,
},
),
Attributed {
range: 17..19,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 2,
column: 8,
},
end_location: Some(
Location {
row: 2,
column: 10,
},
),
value: Attributed {
range: 17..19,
custom: (),
node: Constant(
ExprConstant {
@ -155,31 +83,13 @@ expression: parse_ast
},
],
orelse: [
Located {
location: Location {
row: 3,
column: 6,
},
end_location: Some(
Location {
row: 3,
column: 8,
},
),
Attributed {
range: 26..28,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 3,
column: 6,
},
end_location: Some(
Location {
row: 3,
column: 8,
},
),
value: Attributed {
range: 26..28,
custom: (),
node: Constant(
ExprConstant {

View file

@ -2,45 +2,18 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 26,
},
),
Attributed {
range: 0..26,
custom: (),
node: GeneratorExp(
ExprGeneratorExp {
elt: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
elt: Attributed {
range: 1..14,
custom: (),
node: IfExp(
ExprIfExp {
test: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
test: Attributed {
range: 6..7,
custom: (),
node: Name(
ExprName {
@ -49,17 +22,8 @@ Located {
},
),
},
body: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
body: Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -68,17 +32,8 @@ Located {
},
),
},
orelse: Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
orelse: Attributed {
range: 13..14,
custom: (),
node: Name(
ExprName {
@ -92,17 +47,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 19,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
target: Attributed {
range: 19..20,
custom: (),
node: Name(
ExprName {
@ -111,17 +57,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 24,
},
end_location: Some(
Location {
row: 1,
column: 25,
},
),
iter: Attributed {
range: 24..25,
custom: (),
node: Name(
ExprName {

View file

@ -3,45 +3,18 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
Attributed {
range: 0..32,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 32,
},
),
value: Attributed {
range: 0..32,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
func: Attributed {
range: 0..7,
custom: (),
node: Name(
ExprName {
@ -51,17 +24,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 1,
column: 8,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 8..20,
custom: (),
node: Constant(
ExprConstant {
@ -74,33 +38,15 @@ expression: parse_ast
},
],
keywords: [
Located {
location: Location {
row: 1,
column: 22,
},
end_location: Some(
Location {
row: 1,
column: 31,
},
),
Attributed {
range: 22..31,
custom: (),
node: KeywordData {
arg: Some(
"keyword",
),
value: Located {
location: Location {
row: 1,
column: 30,
},
end_location: Some(
Location {
row: 1,
column: 31,
},
),
value: Attributed {
range: 30..31,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,48 +3,21 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
Attributed {
range: 0..18,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
value: Attributed {
range: 0..18,
custom: (),
node: Lambda(
ExprLambda {
args: Arguments {
posonlyargs: [],
args: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: ArgData {
arg: "x",
@ -52,17 +25,8 @@ expression: parse_ast
type_comment: None,
},
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: ArgData {
arg: "y",
@ -77,31 +41,13 @@ expression: parse_ast
kwarg: None,
defaults: [],
},
body: Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
body: Attributed {
range: 13..18,
custom: (),
node: BinOp(
ExprBinOp {
left: Located {
location: Location {
row: 1,
column: 13,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
left: Attributed {
range: 13..14,
custom: (),
node: Name(
ExprName {
@ -111,17 +57,8 @@ expression: parse_ast
),
},
op: Mult,
right: Located {
location: Location {
row: 1,
column: 17,
},
end_location: Some(
Location {
row: 1,
column: 18,
},
),
right: Attributed {
range: 17..18,
custom: (),
node: Name(
ExprName {

View file

@ -2,31 +2,13 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: ListComp(
ExprListComp {
elt: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
elt: Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -37,17 +19,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
target: Attributed {
range: 7..8,
custom: (),
node: Name(
ExprName {
@ -56,17 +29,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 12,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
iter: Attributed {
range: 12..13,
custom: (),
node: Name(
ExprName {

View file

@ -2,45 +2,18 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 0..23,
custom: (),
node: GeneratorExp(
ExprGeneratorExp {
elt: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
elt: Attributed {
range: 1..11,
custom: (),
node: NamedExpr(
ExprNamedExpr {
target: Located {
location: Location {
row: 1,
column: 1,
},
end_location: Some(
Location {
row: 1,
column: 2,
},
),
target: Attributed {
range: 1..2,
custom: (),
node: Name(
ExprName {
@ -49,31 +22,13 @@ Located {
},
),
},
value: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
value: Attributed {
range: 6..11,
custom: (),
node: BinOp(
ExprBinOp {
left: Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
left: Attributed {
range: 6..7,
custom: (),
node: Name(
ExprName {
@ -83,17 +38,8 @@ Located {
),
},
op: Add,
right: Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
right: Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {
@ -112,17 +58,8 @@ Located {
},
generators: [
Comprehension {
target: Located {
location: Location {
row: 1,
column: 16,
},
end_location: Some(
Location {
row: 1,
column: 17,
},
),
target: Attributed {
range: 16..17,
custom: (),
node: Name(
ExprName {
@ -131,17 +68,8 @@ Located {
},
),
},
iter: Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 22,
},
),
iter: Attributed {
range: 21..22,
custom: (),
node: Name(
ExprName {

View file

@ -3,45 +3,18 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
Attributed {
range: 0..23,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 23,
},
),
value: Attributed {
range: 0..23,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
func: Attributed {
range: 0..5,
custom: (),
node: Name(
ExprName {
@ -51,17 +24,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 6..19,
custom: (),
node: Constant(
ExprConstant {
@ -72,17 +36,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 21,
},
end_location: Some(
Location {
row: 1,
column: 22,
},
),
Attributed {
range: 21..22,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,45 +3,18 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
Attributed {
range: 0..20,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 20,
},
),
value: Attributed {
range: 0..20,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
func: Attributed {
range: 0..5,
custom: (),
node: Name(
ExprName {
@ -51,17 +24,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
Attributed {
range: 6..19,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 0..13,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
value: Attributed {
range: 0..13,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,47 +3,20 @@ source: parser/src/parser.rs
expression: "parse_program(source, \"<test>\").unwrap()"
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 0..11,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
Attributed {
range: 0..4,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -52,17 +25,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
},
),
},
Located {
location: Location {
row: 1,
column: 3,
},
end_location: Some(
Location {
row: 1,
column: 4,
},
),
Attributed {
range: 3..4,
custom: (),
node: Name(
ExprName {
@ -77,32 +41,14 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
},
],
value: Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
value: Attributed {
range: 7..11,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 7,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 7..8,
custom: (),
node: Constant(
ExprConstant {
@ -113,17 +59,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
},
),
},
Located {
location: Location {
row: 1,
column: 10,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 10..11,
custom: (),
node: Constant(
ExprConstant {

File diff suppressed because it is too large Load diff

View file

@ -2,31 +2,13 @@
source: parser/src/parser.rs
expression: parse_ast
---
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 0..8,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 1,
},
),
value: Attributed {
range: 0..1,
custom: (),
node: Name(
ExprName {
@ -35,32 +17,14 @@ Located {
},
),
},
slice: Located {
location: Location {
row: 1,
column: 2,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
slice: Attributed {
range: 2..7,
custom: (),
node: Slice(
ExprSlice {
lower: Some(
Located {
location: Location {
row: 1,
column: 2,
},
end_location: Some(
Location {
row: 1,
column: 3,
},
),
Attributed {
range: 2..3,
custom: (),
node: Constant(
ExprConstant {
@ -73,17 +37,8 @@ Located {
},
),
upper: Some(
Located {
location: Location {
row: 1,
column: 4,
},
end_location: Some(
Location {
row: 1,
column: 5,
},
),
Attributed {
range: 4..5,
custom: (),
node: Constant(
ExprConstant {
@ -96,17 +51,8 @@ Located {
},
),
step: Some(
Located {
location: Location {
row: 1,
column: 6,
},
end_location: Some(
Location {
row: 1,
column: 7,
},
),
Attributed {
range: 6..7,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,32 +3,14 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 36,
},
),
Attributed {
range: 0..36,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 11,
},
),
Attributed {
range: 0..11,
custom: (),
node: Name(
ExprName {
@ -38,31 +20,13 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 36,
},
),
value: Attributed {
range: 14..36,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 1,
column: 14,
},
end_location: Some(
Location {
row: 1,
column: 19,
},
),
value: Attributed {
range: 14..19,
custom: (),
node: Name(
ExprName {
@ -71,32 +35,14 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 35,
},
),
slice: Attributed {
range: 20..35,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 1,
column: 20,
},
end_location: Some(
Location {
row: 1,
column: 21,
},
),
Attributed {
range: 20..21,
custom: (),
node: Constant(
ExprConstant {
@ -107,31 +53,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 23,
},
end_location: Some(
Location {
row: 1,
column: 31,
},
),
Attributed {
range: 23..31,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 1,
column: 24,
},
end_location: Some(
Location {
row: 1,
column: 31,
},
),
value: Attributed {
range: 24..31,
custom: (),
node: Name(
ExprName {
@ -144,32 +72,14 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 33,
},
end_location: Some(
Location {
row: 1,
column: 35,
},
),
Attributed {
range: 33..35,
custom: (),
node: UnaryOp(
ExprUnaryOp {
op: USub,
operand: Located {
location: Location {
row: 1,
column: 34,
},
end_location: Some(
Location {
row: 1,
column: 35,
},
),
operand: Attributed {
range: 34..35,
custom: (),
node: Constant(
ExprConstant {
@ -196,46 +106,19 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 2,
column: 36,
},
),
Attributed {
range: 37..73,
custom: (),
node: Assign(
StmtAssign {
targets: [
Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 2,
column: 22,
},
),
Attributed {
range: 37..59,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 2,
column: 5,
},
),
value: Attributed {
range: 37..42,
custom: (),
node: Name(
ExprName {
@ -244,32 +127,14 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 2,
column: 6,
},
end_location: Some(
Location {
row: 2,
column: 21,
},
),
slice: Attributed {
range: 43..58,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 2,
column: 6,
},
end_location: Some(
Location {
row: 2,
column: 7,
},
),
Attributed {
range: 43..44,
custom: (),
node: Constant(
ExprConstant {
@ -280,31 +145,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 2,
column: 9,
},
end_location: Some(
Location {
row: 2,
column: 17,
},
),
Attributed {
range: 46..54,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 2,
column: 10,
},
end_location: Some(
Location {
row: 2,
column: 17,
},
),
value: Attributed {
range: 47..54,
custom: (),
node: Name(
ExprName {
@ -317,32 +164,14 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 2,
column: 19,
},
end_location: Some(
Location {
row: 2,
column: 21,
},
),
Attributed {
range: 56..58,
custom: (),
node: UnaryOp(
ExprUnaryOp {
op: USub,
operand: Located {
location: Location {
row: 2,
column: 20,
},
end_location: Some(
Location {
row: 2,
column: 21,
},
),
operand: Attributed {
range: 57..58,
custom: (),
node: Constant(
ExprConstant {
@ -366,17 +195,8 @@ expression: parse_ast
),
},
],
value: Located {
location: Location {
row: 2,
column: 25,
},
end_location: Some(
Location {
row: 2,
column: 36,
},
),
value: Attributed {
range: 62..73,
custom: (),
node: Name(
ExprName {
@ -389,45 +209,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 0,
},
end_location: Some(
Location {
row: 3,
column: 45,
},
),
Attributed {
range: 74..119,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 3,
column: 0,
},
end_location: Some(
Location {
row: 3,
column: 45,
},
),
value: Attributed {
range: 74..119,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 3,
column: 0,
},
end_location: Some(
Location {
row: 3,
column: 5,
},
),
value: Attributed {
range: 74..79,
custom: (),
node: Name(
ExprName {
@ -436,46 +229,19 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 3,
column: 6,
},
end_location: Some(
Location {
row: 3,
column: 44,
},
),
slice: Attributed {
range: 80..118,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 3,
column: 6,
},
end_location: Some(
Location {
row: 3,
column: 24,
},
),
Attributed {
range: 80..98,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 3,
column: 7,
},
end_location: Some(
Location {
row: 3,
column: 24,
},
),
value: Attributed {
range: 81..98,
custom: (),
node: Name(
ExprName {
@ -488,31 +254,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 26,
},
end_location: Some(
Location {
row: 3,
column: 44,
},
),
Attributed {
range: 100..118,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 3,
column: 27,
},
end_location: Some(
Location {
row: 3,
column: 44,
},
),
value: Attributed {
range: 101..118,
custom: (),
node: Name(
ExprName {
@ -537,45 +285,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 4,
column: 0,
},
end_location: Some(
Location {
row: 4,
column: 30,
},
),
Attributed {
range: 120..150,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 4,
column: 0,
},
end_location: Some(
Location {
row: 4,
column: 30,
},
),
value: Attributed {
range: 120..150,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 4,
column: 0,
},
end_location: Some(
Location {
row: 4,
column: 5,
},
),
value: Attributed {
range: 120..125,
custom: (),
node: Name(
ExprName {
@ -584,47 +305,20 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 4,
column: 6,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
slice: Attributed {
range: 126..149,
custom: (),
node: Tuple(
ExprTuple {
elts: [
Located {
location: Location {
row: 4,
column: 6,
},
end_location: Some(
Location {
row: 4,
column: 9,
},
),
Attributed {
range: 126..129,
custom: (),
node: Slice(
ExprSlice {
lower: Some(
Located {
location: Location {
row: 4,
column: 6,
},
end_location: Some(
Location {
row: 4,
column: 7,
},
),
Attributed {
range: 126..127,
custom: (),
node: Constant(
ExprConstant {
@ -637,17 +331,8 @@ expression: parse_ast
},
),
upper: Some(
Located {
location: Location {
row: 4,
column: 8,
},
end_location: Some(
Location {
row: 4,
column: 9,
},
),
Attributed {
range: 128..129,
custom: (),
node: Constant(
ExprConstant {
@ -663,31 +348,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 4,
column: 11,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
Attributed {
range: 131..149,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 4,
column: 12,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
value: Attributed {
range: 132..149,
custom: (),
node: Name(
ExprName {

View file

@ -3,61 +3,25 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 6,
column: 30,
},
),
Attributed {
range: 0..134,
custom: (),
node: Try(
StmtTry {
body: [
Located {
location: Location {
row: 2,
column: 4,
},
end_location: Some(
Location {
row: 2,
column: 23,
},
),
Attributed {
range: 9..28,
custom: (),
node: Raise(
StmtRaise {
exc: Some(
Located {
location: Location {
row: 2,
column: 10,
},
end_location: Some(
Location {
row: 2,
column: 23,
},
),
Attributed {
range: 15..28,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 2,
column: 10,
},
end_location: Some(
Location {
row: 2,
column: 20,
},
),
func: Attributed {
range: 15..25,
custom: (),
node: Name(
ExprName {
@ -67,17 +31,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 2,
column: 21,
},
end_location: Some(
Location {
row: 2,
column: 22,
},
),
Attributed {
range: 26..27,
custom: (),
node: Constant(
ExprConstant {
@ -100,32 +55,14 @@ expression: parse_ast
},
],
handlers: [
Located {
location: Location {
row: 3,
column: 0,
},
end_location: Some(
Location {
row: 4,
column: 30,
},
),
Attributed {
range: 29..82,
custom: (),
node: ExceptHandler(
ExcepthandlerExceptHandler {
type_: Some(
Located {
location: Location {
row: 3,
column: 7,
},
end_location: Some(
Location {
row: 3,
column: 16,
},
),
Attributed {
range: 36..45,
custom: (),
node: Name(
ExprName {
@ -139,45 +76,18 @@ expression: parse_ast
"e",
),
body: [
Located {
location: Location {
row: 4,
column: 4,
},
end_location: Some(
Location {
row: 4,
column: 30,
},
),
Attributed {
range: 56..82,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 4,
column: 4,
},
end_location: Some(
Location {
row: 4,
column: 30,
},
),
value: Attributed {
range: 56..82,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 4,
column: 4,
},
end_location: Some(
Location {
row: 4,
column: 9,
},
),
func: Attributed {
range: 56..61,
custom: (),
node: Name(
ExprName {
@ -187,32 +97,14 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 4,
column: 10,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
Attributed {
range: 62..81,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 4,
column: 10,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
Attributed {
range: 62..81,
custom: (),
node: Constant(
ExprConstant {
@ -223,45 +115,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 4,
column: 10,
},
end_location: Some(
Location {
row: 4,
column: 29,
},
),
Attributed {
range: 62..81,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 4,
column: 20,
},
end_location: Some(
Location {
row: 4,
column: 27,
},
),
value: Attributed {
range: 72..79,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 4,
column: 20,
},
end_location: Some(
Location {
row: 4,
column: 24,
},
),
func: Attributed {
range: 72..76,
custom: (),
node: Name(
ExprName {
@ -271,17 +136,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 4,
column: 25,
},
end_location: Some(
Location {
row: 4,
column: 26,
},
),
Attributed {
range: 77..78,
custom: (),
node: Name(
ExprName {
@ -316,32 +172,14 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 5,
column: 0,
},
end_location: Some(
Location {
row: 6,
column: 30,
},
),
Attributed {
range: 83..134,
custom: (),
node: ExceptHandler(
ExcepthandlerExceptHandler {
type_: Some(
Located {
location: Location {
row: 5,
column: 7,
},
end_location: Some(
Location {
row: 5,
column: 14,
},
),
Attributed {
range: 90..97,
custom: (),
node: Name(
ExprName {
@ -355,45 +193,18 @@ expression: parse_ast
"e",
),
body: [
Located {
location: Location {
row: 6,
column: 4,
},
end_location: Some(
Location {
row: 6,
column: 30,
},
),
Attributed {
range: 108..134,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 6,
column: 4,
},
end_location: Some(
Location {
row: 6,
column: 30,
},
),
value: Attributed {
range: 108..134,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 6,
column: 4,
},
end_location: Some(
Location {
row: 6,
column: 9,
},
),
func: Attributed {
range: 108..113,
custom: (),
node: Name(
ExprName {
@ -403,32 +214,14 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 6,
column: 10,
},
end_location: Some(
Location {
row: 6,
column: 29,
},
),
Attributed {
range: 114..133,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 6,
column: 10,
},
end_location: Some(
Location {
row: 6,
column: 29,
},
),
Attributed {
range: 114..133,
custom: (),
node: Constant(
ExprConstant {
@ -439,45 +232,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 6,
column: 10,
},
end_location: Some(
Location {
row: 6,
column: 29,
},
),
Attributed {
range: 114..133,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 6,
column: 20,
},
end_location: Some(
Location {
row: 6,
column: 27,
},
),
value: Attributed {
range: 124..131,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 6,
column: 20,
},
end_location: Some(
Location {
row: 6,
column: 24,
},
),
func: Attributed {
range: 124..128,
custom: (),
node: Name(
ExprName {
@ -487,17 +253,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 6,
column: 25,
},
end_location: Some(
Location {
row: 6,
column: 26,
},
),
Attributed {
range: 129..130,
custom: (),
node: Name(
ExprName {

View file

@ -3,61 +3,25 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 7,
column: 57,
},
),
Attributed {
range: 0..260,
custom: (),
node: TryStar(
StmtTryStar {
body: [
Located {
location: Location {
row: 2,
column: 4,
},
end_location: Some(
Location {
row: 3,
column: 62,
},
),
Attributed {
range: 9..98,
custom: (),
node: Raise(
StmtRaise {
exc: Some(
Located {
location: Location {
row: 2,
column: 10,
},
end_location: Some(
Location {
row: 3,
column: 62,
},
),
Attributed {
range: 15..98,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 2,
column: 10,
},
end_location: Some(
Location {
row: 2,
column: 24,
},
),
func: Attributed {
range: 15..29,
custom: (),
node: Name(
ExprName {
@ -67,17 +31,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 2,
column: 25,
},
end_location: Some(
Location {
row: 2,
column: 29,
},
),
Attributed {
range: 30..34,
custom: (),
node: Constant(
ExprConstant {
@ -88,46 +43,19 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 8,
},
end_location: Some(
Location {
row: 3,
column: 61,
},
),
Attributed {
range: 44..97,
custom: (),
node: List(
ExprList {
elts: [
Located {
location: Location {
row: 3,
column: 9,
},
end_location: Some(
Location {
row: 3,
column: 22,
},
),
Attributed {
range: 45..58,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 3,
column: 9,
},
end_location: Some(
Location {
row: 3,
column: 19,
},
),
func: Attributed {
range: 45..55,
custom: (),
node: Name(
ExprName {
@ -137,17 +65,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 3,
column: 20,
},
end_location: Some(
Location {
row: 3,
column: 21,
},
),
Attributed {
range: 56..57,
custom: (),
node: Constant(
ExprConstant {
@ -163,31 +82,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 24,
},
end_location: Some(
Location {
row: 3,
column: 36,
},
),
Attributed {
range: 60..72,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 3,
column: 24,
},
end_location: Some(
Location {
row: 3,
column: 33,
},
),
func: Attributed {
range: 60..69,
custom: (),
node: Name(
ExprName {
@ -197,17 +98,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 3,
column: 34,
},
end_location: Some(
Location {
row: 3,
column: 35,
},
),
Attributed {
range: 70..71,
custom: (),
node: Constant(
ExprConstant {
@ -223,31 +115,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 38,
},
end_location: Some(
Location {
row: 3,
column: 48,
},
),
Attributed {
range: 74..84,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 3,
column: 38,
},
end_location: Some(
Location {
row: 3,
column: 45,
},
),
func: Attributed {
range: 74..81,
custom: (),
node: Name(
ExprName {
@ -257,17 +131,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 3,
column: 46,
},
end_location: Some(
Location {
row: 3,
column: 47,
},
),
Attributed {
range: 82..83,
custom: (),
node: Constant(
ExprConstant {
@ -283,31 +148,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 3,
column: 50,
},
end_location: Some(
Location {
row: 3,
column: 60,
},
),
Attributed {
range: 86..96,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 3,
column: 50,
},
end_location: Some(
Location {
row: 3,
column: 57,
},
),
func: Attributed {
range: 86..93,
custom: (),
node: Name(
ExprName {
@ -317,17 +164,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 3,
column: 58,
},
end_location: Some(
Location {
row: 3,
column: 59,
},
),
Attributed {
range: 94..95,
custom: (),
node: Constant(
ExprConstant {
@ -360,32 +198,14 @@ expression: parse_ast
},
],
handlers: [
Located {
location: Location {
row: 4,
column: 0,
},
end_location: Some(
Location {
row: 5,
column: 57,
},
),
Attributed {
range: 99..180,
custom: (),
node: ExceptHandler(
ExcepthandlerExceptHandler {
type_: Some(
Located {
location: Location {
row: 4,
column: 8,
},
end_location: Some(
Location {
row: 4,
column: 17,
},
),
Attributed {
range: 107..116,
custom: (),
node: Name(
ExprName {
@ -399,45 +219,18 @@ expression: parse_ast
"e",
),
body: [
Located {
location: Location {
row: 5,
column: 4,
},
end_location: Some(
Location {
row: 5,
column: 57,
},
),
Attributed {
range: 127..180,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 5,
column: 4,
},
end_location: Some(
Location {
row: 5,
column: 57,
},
),
value: Attributed {
range: 127..180,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 5,
column: 4,
},
end_location: Some(
Location {
row: 5,
column: 9,
},
),
func: Attributed {
range: 127..132,
custom: (),
node: Name(
ExprName {
@ -447,32 +240,14 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 5,
column: 10,
},
end_location: Some(
Location {
row: 5,
column: 56,
},
),
Attributed {
range: 133..179,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 5,
column: 10,
},
end_location: Some(
Location {
row: 5,
column: 56,
},
),
Attributed {
range: 133..179,
custom: (),
node: Constant(
ExprConstant {
@ -483,45 +258,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 5,
column: 10,
},
end_location: Some(
Location {
row: 5,
column: 56,
},
),
Attributed {
range: 133..179,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 5,
column: 20,
},
end_location: Some(
Location {
row: 5,
column: 27,
},
),
value: Attributed {
range: 143..150,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 5,
column: 20,
},
end_location: Some(
Location {
row: 5,
column: 24,
},
),
func: Attributed {
range: 143..147,
custom: (),
node: Name(
ExprName {
@ -531,17 +279,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 5,
column: 25,
},
end_location: Some(
Location {
row: 5,
column: 26,
},
),
Attributed {
range: 148..149,
custom: (),
node: Name(
ExprName {
@ -560,17 +299,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 5,
column: 10,
},
end_location: Some(
Location {
row: 5,
column: 56,
},
),
Attributed {
range: 133..179,
custom: (),
node: Constant(
ExprConstant {
@ -581,45 +311,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 5,
column: 10,
},
end_location: Some(
Location {
row: 5,
column: 56,
},
),
Attributed {
range: 133..179,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 5,
column: 42,
},
end_location: Some(
Location {
row: 5,
column: 54,
},
),
value: Attributed {
range: 165..177,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 5,
column: 42,
},
end_location: Some(
Location {
row: 5,
column: 43,
},
),
value: Attributed {
range: 165..166,
custom: (),
node: Name(
ExprName {
@ -654,32 +357,14 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 6,
column: 0,
},
end_location: Some(
Location {
row: 7,
column: 57,
},
),
Attributed {
range: 181..260,
custom: (),
node: ExceptHandler(
ExcepthandlerExceptHandler {
type_: Some(
Located {
location: Location {
row: 6,
column: 8,
},
end_location: Some(
Location {
row: 6,
column: 15,
},
),
Attributed {
range: 189..196,
custom: (),
node: Name(
ExprName {
@ -693,45 +378,18 @@ expression: parse_ast
"e",
),
body: [
Located {
location: Location {
row: 7,
column: 4,
},
end_location: Some(
Location {
row: 7,
column: 57,
},
),
Attributed {
range: 207..260,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 7,
column: 4,
},
end_location: Some(
Location {
row: 7,
column: 57,
},
),
value: Attributed {
range: 207..260,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 7,
column: 4,
},
end_location: Some(
Location {
row: 7,
column: 9,
},
),
func: Attributed {
range: 207..212,
custom: (),
node: Name(
ExprName {
@ -741,32 +399,14 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 7,
column: 10,
},
end_location: Some(
Location {
row: 7,
column: 56,
},
),
Attributed {
range: 213..259,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 7,
column: 10,
},
end_location: Some(
Location {
row: 7,
column: 56,
},
),
Attributed {
range: 213..259,
custom: (),
node: Constant(
ExprConstant {
@ -777,45 +417,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 7,
column: 10,
},
end_location: Some(
Location {
row: 7,
column: 56,
},
),
Attributed {
range: 213..259,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 7,
column: 20,
},
end_location: Some(
Location {
row: 7,
column: 27,
},
),
value: Attributed {
range: 223..230,
custom: (),
node: Call(
ExprCall {
func: Located {
location: Location {
row: 7,
column: 20,
},
end_location: Some(
Location {
row: 7,
column: 24,
},
),
func: Attributed {
range: 223..227,
custom: (),
node: Name(
ExprName {
@ -825,17 +438,8 @@ expression: parse_ast
),
},
args: [
Located {
location: Location {
row: 7,
column: 25,
},
end_location: Some(
Location {
row: 7,
column: 26,
},
),
Attributed {
range: 228..229,
custom: (),
node: Name(
ExprName {
@ -854,17 +458,8 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 7,
column: 10,
},
end_location: Some(
Location {
row: 7,
column: 56,
},
),
Attributed {
range: 213..259,
custom: (),
node: Constant(
ExprConstant {
@ -875,45 +470,18 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 7,
column: 10,
},
end_location: Some(
Location {
row: 7,
column: 56,
},
),
Attributed {
range: 213..259,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 7,
column: 42,
},
end_location: Some(
Location {
row: 7,
column: 54,
},
),
value: Attributed {
range: 245..257,
custom: (),
node: Attribute(
ExprAttribute {
value: Located {
location: Location {
row: 7,
column: 42,
},
end_location: Some(
Location {
row: 7,
column: 43,
},
),
value: Attributed {
range: 245..246,
custom: (),
node: Name(
ExprName {

View file

@ -3,17 +3,8 @@ source: parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 2,
column: 0,
},
end_location: Some(
Location {
row: 2,
column: 48,
},
),
Attributed {
range: 1..49,
custom: (),
node: FunctionDef(
StmtFunctionDef {
@ -22,46 +13,19 @@ expression: parse_ast
posonlyargs: [],
args: [],
vararg: Some(
Located {
location: Location {
row: 2,
column: 19,
},
end_location: Some(
Location {
row: 2,
column: 28,
},
),
Attributed {
range: 20..29,
custom: (),
node: ArgData {
arg: "args",
annotation: Some(
Located {
location: Location {
row: 2,
column: 25,
},
end_location: Some(
Location {
row: 2,
column: 28,
},
),
Attributed {
range: 26..29,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 2,
column: 26,
},
end_location: Some(
Location {
row: 2,
column: 28,
},
),
value: Attributed {
range: 27..29,
custom: (),
node: Name(
ExprName {
@ -85,31 +49,13 @@ expression: parse_ast
defaults: [],
},
body: [
Located {
location: Location {
row: 2,
column: 45,
},
end_location: Some(
Location {
row: 2,
column: 48,
},
),
Attributed {
range: 46..49,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 2,
column: 45,
},
end_location: Some(
Location {
row: 2,
column: 48,
},
),
value: Attributed {
range: 46..49,
custom: (),
node: Constant(
ExprConstant {
@ -124,31 +70,13 @@ expression: parse_ast
],
decorator_list: [],
returns: Some(
Located {
location: Location {
row: 2,
column: 33,
},
end_location: Some(
Location {
row: 2,
column: 43,
},
),
Attributed {
range: 34..44,
custom: (),
node: Subscript(
ExprSubscript {
value: Located {
location: Location {
row: 2,
column: 33,
},
end_location: Some(
Location {
row: 2,
column: 38,
},
),
value: Attributed {
range: 34..39,
custom: (),
node: Name(
ExprName {
@ -157,31 +85,13 @@ expression: parse_ast
},
),
},
slice: Located {
location: Location {
row: 2,
column: 39,
},
end_location: Some(
Location {
row: 2,
column: 42,
},
),
slice: Attributed {
range: 40..43,
custom: (),
node: Starred(
ExprStarred {
value: Located {
location: Location {
row: 2,
column: 40,
},
end_location: Some(
Location {
row: 2,
column: 42,
},
),
value: Attributed {
range: 41..43,
custom: (),
node: Name(
ExprName {

File diff suppressed because it is too large Load diff

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 0..15,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
value: Attributed {
range: 0..15,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
Attributed {
range: 0..9,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 9,
},
),
value: Attributed {
range: 0..9,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 21,
},
),
Attributed {
range: 0..21,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 21,
},
),
value: Attributed {
range: 0..21,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 45,
},
),
Attributed {
range: 0..45,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 45,
},
),
value: Attributed {
range: 0..45,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 0..12,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
value: Attributed {
range: 0..12,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 738,
},
),
Attributed {
range: 0..738,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 738,
},
),
value: Attributed {
range: 0..738,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
Attributed {
range: 0..12,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 12,
},
),
value: Attributed {
range: 0..12,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
Attributed {
range: 0..13,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 13,
},
),
value: Attributed {
range: 0..13,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
Attributed {
range: 0..14,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 14,
},
),
value: Attributed {
range: 0..14,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,31 +3,13 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
Attributed {
range: 0..15,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 15,
},
),
value: Attributed {
range: 0..15,
custom: (),
node: Constant(
ExprConstant {

View file

@ -3,46 +3,19 @@ source: parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 0..8,
custom: (),
node: Expr(
StmtExpr {
value: Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
value: Attributed {
range: 0..8,
custom: (),
node: JoinedStr(
ExprJoinedStr {
values: [
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 0..8,
custom: (),
node: Constant(
ExprConstant {
@ -53,31 +26,13 @@ expression: parse_ast
},
),
},
Located {
location: Location {
row: 1,
column: 0,
},
end_location: Some(
Location {
row: 1,
column: 8,
},
),
Attributed {
range: 0..8,
custom: (),
node: FormattedValue(
ExprFormattedValue {
value: Located {
location: Location {
row: 1,
column: 5,
},
end_location: Some(
Location {
row: 1,
column: 6,
},
),
value: Attributed {
range: 5..6,
custom: (),
node: Name(
ExprName {

Some files were not shown because too many files have changed in this diff Show more