Remove Range type parameter from AST nodes (#15)
This commit is contained in:
4
.github/workflows/ci.yaml
vendored
4
.github/workflows/ci.yaml
vendored
@@ -40,7 +40,7 @@ jobs:
|
||||
- name: run tests with num-bigint
|
||||
run: cargo test --all --no-default-features --features num-bigint
|
||||
- name: run tests with malachite-bigint and all features
|
||||
run: cargo test --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde
|
||||
run: cargo test --all --features malachite-bigint,full-lexer,serde
|
||||
|
||||
lint:
|
||||
name: Check Rust code with rustfmt and clippy
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
- name: run clippy
|
||||
run: cargo clippy --all --no-default-features --features num-bigint
|
||||
- name: run clippy
|
||||
run: cargo clippy --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde -- -Dwarnings
|
||||
run: cargo clippy --all --features malachite-bigint,full-lexer,serde -- -Dwarnings
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
|
||||
@@ -9,7 +9,6 @@ license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["malachite-bigint"]
|
||||
all-nodes-with-ranges = []
|
||||
|
||||
[dependencies]
|
||||
rustpython-parser-core = { workspace = true }
|
||||
|
||||
@@ -286,13 +286,6 @@ class TypeInfoMixin:
|
||||
def has_user_data(self, typ):
|
||||
return self.type_info[typ].has_user_data
|
||||
|
||||
def apply_generics(self, typ, *generics):
|
||||
needs_generics = not self.type_info[typ].is_simple
|
||||
if needs_generics:
|
||||
return [f"<{g}>" for g in generics]
|
||||
else:
|
||||
return ["" for g in generics]
|
||||
|
||||
|
||||
class EmitVisitor(asdl.VisitorBase, TypeInfoMixin):
|
||||
"""Visit that emits lines"""
|
||||
@@ -393,17 +386,14 @@ class StructVisitor(EmitVisitor):
|
||||
self.emit("#[derive(Clone, Debug, PartialEq)]", depth)
|
||||
|
||||
def emit_range(self, has_attributes, depth):
|
||||
if has_attributes:
|
||||
self.emit("pub range: R,", depth + 1)
|
||||
else:
|
||||
self.emit("pub range: OptionalRange<R>,", depth + 1)
|
||||
self.emit("pub range: TextRange,", depth + 1)
|
||||
|
||||
def visitModule(self, mod):
|
||||
self.emit_attrs(0)
|
||||
self.emit(
|
||||
"""
|
||||
#[derive(is_macro::Is)]
|
||||
pub enum Ast<R=TextRange> {
|
||||
pub enum Ast {
|
||||
""",
|
||||
0,
|
||||
)
|
||||
@@ -411,7 +401,6 @@ class StructVisitor(EmitVisitor):
|
||||
info = self.customized_type_info(dfn.name)
|
||||
dfn = info.custom
|
||||
rust_name = info.full_type_name
|
||||
generics = "" if self.type_info[dfn.name].is_simple else "<R>"
|
||||
if dfn.name == "mod":
|
||||
# This is exceptional rule to other enums.
|
||||
# Unlike other enums, this is justified because `Mod` is only used as
|
||||
@@ -419,11 +408,11 @@ class StructVisitor(EmitVisitor):
|
||||
# Because it will be very rarely used in very particular applications,
|
||||
# "ast_" prefix to everywhere seems less useful.
|
||||
self.emit('#[is(name = "module")]', 1)
|
||||
self.emit(f"{rust_name}({rust_name}{generics}),", 1)
|
||||
self.emit(f"{rust_name}({rust_name}),", 1)
|
||||
self.emit(
|
||||
"""
|
||||
}
|
||||
impl<R> Node for Ast<R> {
|
||||
impl Node for Ast {
|
||||
const NAME: &'static str = "AST";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||
}
|
||||
@@ -433,11 +422,10 @@ class StructVisitor(EmitVisitor):
|
||||
for dfn in mod.dfns:
|
||||
info = self.customized_type_info(dfn.name)
|
||||
rust_name = info.full_type_name
|
||||
generics = "" if self.type_info[dfn.name].is_simple else "<R>"
|
||||
self.emit(
|
||||
f"""
|
||||
impl<R> From<{rust_name}{generics}> for Ast<R> {{
|
||||
fn from(node: {rust_name}{generics}) -> Self {{
|
||||
impl From<{rust_name}> for Ast {{
|
||||
fn from(node: {rust_name}) -> Self {{
|
||||
Ast::{rust_name}(node)
|
||||
}}
|
||||
}}
|
||||
@@ -462,10 +450,9 @@ class StructVisitor(EmitVisitor):
|
||||
else:
|
||||
self.sum_with_constructors(sum, type, depth)
|
||||
|
||||
(generics_applied,) = self.apply_generics(type.name, "R")
|
||||
self.emit(
|
||||
f"""
|
||||
impl{generics_applied} Node for {rust_type_name(type.name)}{generics_applied} {{
|
||||
impl Node for {rust_type_name(type.name)} {{
|
||||
const NAME: &'static str = "{type.name}";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||
}}
|
||||
@@ -512,7 +499,7 @@ class StructVisitor(EmitVisitor):
|
||||
{rust_name}::{cons.name}
|
||||
}}
|
||||
}}
|
||||
impl<R> From<{rust_name}{cons.name}> for Ast<R> {{
|
||||
impl From<{rust_name}{cons.name}> for Ast {{
|
||||
fn from(_: {rust_name}{cons.name}) -> Self {{
|
||||
{rust_name}::{cons.name}.into()
|
||||
}}
|
||||
@@ -537,7 +524,7 @@ class StructVisitor(EmitVisitor):
|
||||
|
||||
self.emit_attrs(depth)
|
||||
self.emit("#[derive(is_macro::Is)]", depth)
|
||||
self.emit(f"pub enum {rust_name}<R = TextRange> {{", depth)
|
||||
self.emit(f"pub enum {rust_name} {{", depth)
|
||||
needs_escape = any(rust_field_name(t.name) in RUST_KEYWORDS for t in sum.types)
|
||||
for t in sum.types:
|
||||
if needs_escape:
|
||||
@@ -545,7 +532,7 @@ class StructVisitor(EmitVisitor):
|
||||
f'#[is(name = "{rust_field_name(t.name)}_{rust_name.lower()}")]',
|
||||
depth + 1,
|
||||
)
|
||||
self.emit(f"{t.name}({rust_name}{t.name}<R>),", depth + 1)
|
||||
self.emit(f"{t.name}({rust_name}{t.name}),", depth + 1)
|
||||
self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
@@ -559,7 +546,7 @@ class StructVisitor(EmitVisitor):
|
||||
)
|
||||
self.emit_attrs(depth)
|
||||
payload_name = f"{rust_name}{t.name}"
|
||||
self.emit(f"pub struct {payload_name}<R = TextRange> {{", depth)
|
||||
self.emit(f"pub struct {payload_name} {{", depth)
|
||||
self.emit_range(sum_type_info.has_attributes, depth)
|
||||
for f in t.fields:
|
||||
self.visit(f, sum_type_info, "pub ", depth + 1, t.name)
|
||||
@@ -572,17 +559,17 @@ class StructVisitor(EmitVisitor):
|
||||
field_names = [f'"{f.name}"' for f in t.fields]
|
||||
self.emit(
|
||||
f"""
|
||||
impl<R> Node for {payload_name}<R> {{
|
||||
impl Node for {payload_name} {{
|
||||
const NAME: &'static str = "{t.name}";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[{', '.join(field_names)}];
|
||||
}}
|
||||
impl<R> From<{payload_name}<R>> for {rust_name}<R> {{
|
||||
fn from(payload: {payload_name}<R>) -> Self {{
|
||||
impl From<{payload_name}> for {rust_name} {{
|
||||
fn from(payload: {payload_name}) -> Self {{
|
||||
{rust_name}::{t.name}(payload)
|
||||
}}
|
||||
}}
|
||||
impl<R> From<{payload_name}<R>> for Ast<R> {{
|
||||
fn from(payload: {payload_name}<R>) -> Self {{
|
||||
impl From<{payload_name}> for Ast {{
|
||||
fn from(payload: {payload_name}) -> Self {{
|
||||
{rust_name}::from(payload).into()
|
||||
}}
|
||||
}}
|
||||
@@ -609,7 +596,7 @@ class StructVisitor(EmitVisitor):
|
||||
field_type = None
|
||||
typ = rust_type_name(field.type)
|
||||
if field_type and not field_type.is_simple:
|
||||
typ = f"{typ}<R>"
|
||||
typ = f"{typ}"
|
||||
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
|
||||
if (
|
||||
field_type
|
||||
@@ -642,7 +629,7 @@ class StructVisitor(EmitVisitor):
|
||||
type_info = self.type_info[type.name]
|
||||
product_name = type_info.full_type_name
|
||||
self.emit_attrs(depth)
|
||||
self.emit(f"pub struct {product_name}<R = TextRange> {{", depth)
|
||||
self.emit(f"pub struct {product_name} {{", depth)
|
||||
self.emit_range(product.attributes, depth + 1)
|
||||
for f in product.fields:
|
||||
self.visit(f, type_info, "pub ", depth + 1)
|
||||
@@ -652,7 +639,7 @@ class StructVisitor(EmitVisitor):
|
||||
field_names = [f'"{f.name}"' for f in product.fields]
|
||||
self.emit(
|
||||
f"""
|
||||
impl<R> Node for {product_name}<R> {{
|
||||
impl Node for {product_name} {{
|
||||
const NAME: &'static str = "{type.name}";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[
|
||||
{', '.join(field_names)}
|
||||
@@ -692,8 +679,6 @@ class RangedDefVisitor(EmitVisitor):
|
||||
self.emit_type_alias(variant_info)
|
||||
self.emit_ranged_impl(variant_info)
|
||||
|
||||
if not info.no_cfg(self.type_info):
|
||||
self.emit('#[cfg(feature = "all-nodes-with-ranges")]', 0)
|
||||
|
||||
self.emit(
|
||||
f"""
|
||||
@@ -716,21 +701,16 @@ class RangedDefVisitor(EmitVisitor):
|
||||
|
||||
def emit_type_alias(self, info):
|
||||
return # disable
|
||||
generics = "" if info.is_simple else "::<TextRange>"
|
||||
|
||||
self.emit(
|
||||
f"pub type {info.full_type_name} = crate::generic::{info.full_type_name}{generics};",
|
||||
f"pub type {info.full_type_name} = crate::generic::{info.full_type_name};",
|
||||
0,
|
||||
)
|
||||
self.emit("", 0)
|
||||
|
||||
def emit_ranged_impl(self, info):
|
||||
if not info.no_cfg(self.type_info):
|
||||
self.emit('#[cfg(feature = "all-nodes-with-ranges")]', 0)
|
||||
|
||||
self.file.write(
|
||||
f"""
|
||||
impl Ranged for crate::generic::{info.full_type_name}::<TextRange> {{
|
||||
impl Ranged for crate::generic::{info.full_type_name} {{
|
||||
fn range(&self) -> TextRange {{
|
||||
self.range
|
||||
}}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,25 @@
|
||||
// File automatically generated by ast/asdl_rs.py.
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::ModModule<TextRange> {
|
||||
impl Ranged for crate::generic::ModModule {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::ModInteractive<TextRange> {
|
||||
impl Ranged for crate::generic::ModInteractive {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::ModExpression<TextRange> {
|
||||
impl Ranged for crate::generic::ModExpression {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::ModFunctionType<TextRange> {
|
||||
impl Ranged for crate::generic::ModFunctionType {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::Mod {
|
||||
fn range(&self) -> TextRange {
|
||||
match self {
|
||||
@@ -36,137 +31,137 @@ impl Ranged for crate::Mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for crate::generic::StmtFunctionDef<TextRange> {
|
||||
impl Ranged for crate::generic::StmtFunctionDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAsyncFunctionDef<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAsyncFunctionDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtClassDef<TextRange> {
|
||||
impl Ranged for crate::generic::StmtClassDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtReturn<TextRange> {
|
||||
impl Ranged for crate::generic::StmtReturn {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtDelete<TextRange> {
|
||||
impl Ranged for crate::generic::StmtDelete {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAssign<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAugAssign<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAugAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAnnAssign<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAnnAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtFor<TextRange> {
|
||||
impl Ranged for crate::generic::StmtFor {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAsyncFor<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAsyncFor {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtWhile<TextRange> {
|
||||
impl Ranged for crate::generic::StmtWhile {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtIf<TextRange> {
|
||||
impl Ranged for crate::generic::StmtIf {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtWith<TextRange> {
|
||||
impl Ranged for crate::generic::StmtWith {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAsyncWith<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAsyncWith {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtMatch<TextRange> {
|
||||
impl Ranged for crate::generic::StmtMatch {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtRaise<TextRange> {
|
||||
impl Ranged for crate::generic::StmtRaise {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtTry<TextRange> {
|
||||
impl Ranged for crate::generic::StmtTry {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtTryStar<TextRange> {
|
||||
impl Ranged for crate::generic::StmtTryStar {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtAssert<TextRange> {
|
||||
impl Ranged for crate::generic::StmtAssert {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtImport<TextRange> {
|
||||
impl Ranged for crate::generic::StmtImport {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtImportFrom<TextRange> {
|
||||
impl Ranged for crate::generic::StmtImportFrom {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtGlobal<TextRange> {
|
||||
impl Ranged for crate::generic::StmtGlobal {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtNonlocal<TextRange> {
|
||||
impl Ranged for crate::generic::StmtNonlocal {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtExpr<TextRange> {
|
||||
impl Ranged for crate::generic::StmtExpr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtPass<TextRange> {
|
||||
impl Ranged for crate::generic::StmtPass {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtBreak<TextRange> {
|
||||
impl Ranged for crate::generic::StmtBreak {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::StmtContinue<TextRange> {
|
||||
impl Ranged for crate::generic::StmtContinue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
@@ -205,137 +200,137 @@ impl Ranged for crate::Stmt {
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for crate::generic::ExprBoolOp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprBoolOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprNamedExpr<TextRange> {
|
||||
impl Ranged for crate::generic::ExprNamedExpr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprBinOp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprBinOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprUnaryOp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprUnaryOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprLambda<TextRange> {
|
||||
impl Ranged for crate::generic::ExprLambda {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprIfExp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprIfExp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprDict<TextRange> {
|
||||
impl Ranged for crate::generic::ExprDict {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprSet<TextRange> {
|
||||
impl Ranged for crate::generic::ExprSet {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprListComp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprListComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprSetComp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprSetComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprDictComp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprDictComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprGeneratorExp<TextRange> {
|
||||
impl Ranged for crate::generic::ExprGeneratorExp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprAwait<TextRange> {
|
||||
impl Ranged for crate::generic::ExprAwait {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprYield<TextRange> {
|
||||
impl Ranged for crate::generic::ExprYield {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprYieldFrom<TextRange> {
|
||||
impl Ranged for crate::generic::ExprYieldFrom {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprCompare<TextRange> {
|
||||
impl Ranged for crate::generic::ExprCompare {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprCall<TextRange> {
|
||||
impl Ranged for crate::generic::ExprCall {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprFormattedValue<TextRange> {
|
||||
impl Ranged for crate::generic::ExprFormattedValue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprJoinedStr<TextRange> {
|
||||
impl Ranged for crate::generic::ExprJoinedStr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprConstant<TextRange> {
|
||||
impl Ranged for crate::generic::ExprConstant {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprAttribute<TextRange> {
|
||||
impl Ranged for crate::generic::ExprAttribute {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprSubscript<TextRange> {
|
||||
impl Ranged for crate::generic::ExprSubscript {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprStarred<TextRange> {
|
||||
impl Ranged for crate::generic::ExprStarred {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprName<TextRange> {
|
||||
impl Ranged for crate::generic::ExprName {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprList<TextRange> {
|
||||
impl Ranged for crate::generic::ExprList {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprTuple<TextRange> {
|
||||
impl Ranged for crate::generic::ExprTuple {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExprSlice<TextRange> {
|
||||
impl Ranged for crate::generic::ExprSlice {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
@@ -374,13 +369,12 @@ impl Ranged for crate::Expr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::Comprehension<TextRange> {
|
||||
impl Ranged for crate::generic::Comprehension {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::ExceptHandlerExceptHandler<TextRange> {
|
||||
impl Ranged for crate::generic::ExceptHandlerExceptHandler {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
@@ -393,75 +387,72 @@ impl Ranged for crate::ExceptHandler {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::PythonArguments<TextRange> {
|
||||
impl Ranged for crate::generic::PythonArguments {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::Arg<TextRange> {
|
||||
impl Ranged for crate::generic::Arg {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::Keyword<TextRange> {
|
||||
impl Ranged for crate::generic::Keyword {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::Alias<TextRange> {
|
||||
impl Ranged for crate::generic::Alias {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::WithItem<TextRange> {
|
||||
impl Ranged for crate::generic::WithItem {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::MatchCase<TextRange> {
|
||||
impl Ranged for crate::generic::MatchCase {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchValue<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchValue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchSingleton<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchSingleton {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchSequence<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchSequence {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchMapping<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchMapping {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchClass<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchClass {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchStar<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchStar {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchAs<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchAs {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::generic::PatternMatchOr<TextRange> {
|
||||
impl Ranged for crate::generic::PatternMatchOr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
@@ -481,13 +472,11 @@ impl Ranged for crate::Pattern {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::TypeIgnoreTypeIgnore<TextRange> {
|
||||
impl Ranged for crate::generic::TypeIgnoreTypeIgnore {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::TypeIgnore {
|
||||
fn range(&self) -> TextRange {
|
||||
match self {
|
||||
@@ -496,20 +485,17 @@ impl Ranged for crate::TypeIgnore {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::Decorator<TextRange> {
|
||||
impl Ranged for crate::generic::Decorator {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::Arguments<TextRange> {
|
||||
impl Ranged for crate::generic::Arguments {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::ArgWithDefault<TextRange> {
|
||||
impl Ranged for crate::generic::ArgWithDefault {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
||||
@@ -1,58 +1,8 @@
|
||||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
pub use crate::{builtin::*, text_size::TextSize, ConversionFlag, Node};
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::marker::PhantomData;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub type Suite<R = TextRange> = Vec<Stmt<R>>;
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
pub type OptionalRange<R> = R;
|
||||
|
||||
#[cfg(not(feature = "all-nodes-with-ranges"))]
|
||||
pub type OptionalRange<R> = EmptyRange<R>;
|
||||
|
||||
#[cfg(not(feature = "all-nodes-with-ranges"))]
|
||||
impl<R> From<R> for OptionalRange<R> {
|
||||
fn from(_: R) -> Self {
|
||||
Self {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Copy, Clone)]
|
||||
pub struct EmptyRange<R> {
|
||||
phantom: PhantomData<R>,
|
||||
}
|
||||
|
||||
impl<R> EmptyRange<R> {
|
||||
#[inline(always)]
|
||||
pub fn new(_start: TextSize, _end: TextSize) -> Self {
|
||||
Self {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Display for EmptyRange<R> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("()")
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Debug for EmptyRange<R> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Default for EmptyRange<R> {
|
||||
fn default() -> Self {
|
||||
EmptyRange {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub type Suite = Vec<Stmt>;
|
||||
|
||||
impl CmpOp {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
@@ -71,8 +21,8 @@ impl CmpOp {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Arguments<R> {
|
||||
pub fn empty(range: OptionalRange<R>) -> Self {
|
||||
impl Arguments {
|
||||
pub fn empty(range: TextRange) -> Self {
|
||||
Self {
|
||||
range,
|
||||
posonlyargs: Vec::new(),
|
||||
@@ -85,39 +35,17 @@ impl<R> Arguments<R> {
|
||||
}
|
||||
|
||||
#[allow(clippy::borrowed_box)] // local utility
|
||||
fn clone_boxed_expr<R: Clone>(expr: &Box<Expr<R>>) -> Box<Expr<R>> {
|
||||
let expr: &Expr<_> = expr.as_ref();
|
||||
fn clone_boxed_expr(expr: &Box<Expr>) -> Box<Expr> {
|
||||
let expr: &Expr = expr.as_ref();
|
||||
Box::new(expr.clone())
|
||||
}
|
||||
|
||||
impl<R> ArgWithDefault<R> {
|
||||
pub fn from_arg(def: Arg<R>, default: Option<Expr<R>>) -> Self
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
let range = {
|
||||
if cfg!(feature = "all-nodes-with-ranges") {
|
||||
todo!("range recovery is not implemented yet") // def.range.start()..default.range.end()
|
||||
} else {
|
||||
#[allow(clippy::useless_conversion)] // false positive by cfg
|
||||
OptionalRange::from(def.range.clone())
|
||||
}
|
||||
};
|
||||
Self {
|
||||
range,
|
||||
def,
|
||||
default: default.map(Box::new),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_arg(&self) -> &Arg<R> {
|
||||
impl ArgWithDefault {
|
||||
pub fn as_arg(&self) -> &Arg {
|
||||
&self.def
|
||||
}
|
||||
|
||||
pub fn to_arg(&self) -> (Arg<R>, Option<Box<Expr<R>>>)
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
pub fn to_arg(&self) -> (Arg, Option<Box<Expr>>) {
|
||||
let ArgWithDefault {
|
||||
range: _,
|
||||
def,
|
||||
@@ -125,7 +53,7 @@ impl<R> ArgWithDefault<R> {
|
||||
} = self;
|
||||
(def.clone(), default.as_ref().map(clone_boxed_expr))
|
||||
}
|
||||
pub fn into_arg(self) -> (Arg<R>, Option<Box<Expr<R>>>) {
|
||||
pub fn into_arg(self) -> (Arg, Option<Box<Expr>>) {
|
||||
let ArgWithDefault {
|
||||
range: _,
|
||||
def,
|
||||
@@ -135,8 +63,8 @@ impl<R> ArgWithDefault<R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Arguments<R> {
|
||||
pub fn defaults(&self) -> impl std::iter::Iterator<Item = &Expr<R>> {
|
||||
impl Arguments {
|
||||
pub fn defaults(&self) -> impl std::iter::Iterator<Item = &Expr> {
|
||||
self.posonlyargs
|
||||
.iter()
|
||||
.chain(self.args.iter())
|
||||
@@ -144,7 +72,7 @@ impl<R> Arguments<R> {
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn split_kwonlyargs(&self) -> (Vec<&Arg<R>>, Vec<(&Arg<R>, &Expr<R>)>) {
|
||||
pub fn split_kwonlyargs(&self) -> (Vec<&Arg>, Vec<(&Arg, &Expr)>) {
|
||||
let mut args = Vec::new();
|
||||
let mut with_defaults = Vec::new();
|
||||
for arg in self.kwonlyargs.iter() {
|
||||
@@ -156,172 +84,6 @@ impl<R> Arguments<R> {
|
||||
}
|
||||
(args, with_defaults)
|
||||
}
|
||||
|
||||
pub fn to_python_arguments(&self) -> PythonArguments<R>
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
let Arguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
vararg,
|
||||
kwonlyargs,
|
||||
kwarg,
|
||||
} = self;
|
||||
|
||||
let mut pos_only = Vec::with_capacity(posonlyargs.len());
|
||||
let mut pos_args = Vec::with_capacity(args.len());
|
||||
let mut defaults = Vec::new();
|
||||
for arg in posonlyargs {
|
||||
let (arg, default) = arg.to_arg();
|
||||
if let Some(default) = default {
|
||||
defaults.push(*default);
|
||||
}
|
||||
pos_only.push(arg);
|
||||
}
|
||||
for arg in args {
|
||||
let (arg, default) = arg.to_arg();
|
||||
if let Some(default) = default {
|
||||
defaults.push(*default);
|
||||
}
|
||||
pos_args.push(arg);
|
||||
}
|
||||
|
||||
let mut kw_only = Vec::with_capacity(kwonlyargs.len());
|
||||
let mut kw_defaults = Vec::new();
|
||||
for arg in kwonlyargs {
|
||||
let (arg, default) = arg.to_arg();
|
||||
if let Some(default) = default {
|
||||
kw_defaults.push(*default);
|
||||
}
|
||||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
PythonArguments {
|
||||
range: range.clone(),
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
defaults,
|
||||
vararg: vararg.clone(),
|
||||
kwonlyargs: kw_only,
|
||||
kw_defaults,
|
||||
kwarg: kwarg.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_python_arguments(self) -> PythonArguments<R> {
|
||||
let Arguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
vararg,
|
||||
kwonlyargs,
|
||||
kwarg,
|
||||
} = self;
|
||||
|
||||
let mut pos_only = Vec::with_capacity(posonlyargs.len());
|
||||
let mut pos_args = Vec::with_capacity(args.len());
|
||||
let mut defaults = Vec::new();
|
||||
for arg in posonlyargs {
|
||||
let (arg, default) = arg.into_arg();
|
||||
if let Some(default) = default {
|
||||
defaults.push(*default);
|
||||
}
|
||||
pos_only.push(arg);
|
||||
}
|
||||
for arg in args {
|
||||
let (arg, default) = arg.into_arg();
|
||||
if let Some(default) = default {
|
||||
defaults.push(*default);
|
||||
}
|
||||
pos_args.push(arg);
|
||||
}
|
||||
|
||||
let mut kw_only = Vec::with_capacity(kwonlyargs.len());
|
||||
let mut kw_defaults = Vec::new();
|
||||
for arg in kwonlyargs {
|
||||
let (arg, default) = arg.into_arg();
|
||||
if let Some(default) = default {
|
||||
kw_defaults.push(*default);
|
||||
}
|
||||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
PythonArguments {
|
||||
range,
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
defaults,
|
||||
vararg,
|
||||
kwonlyargs: kw_only,
|
||||
kw_defaults,
|
||||
kwarg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> PythonArguments<R> {
|
||||
pub fn into_arguments(self) -> Arguments<R>
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
let PythonArguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
defaults,
|
||||
vararg,
|
||||
kwonlyargs,
|
||||
kw_defaults,
|
||||
kwarg,
|
||||
} = self;
|
||||
|
||||
let mut pos_only = Vec::with_capacity(posonlyargs.len());
|
||||
let mut pos_args = Vec::with_capacity(args.len());
|
||||
let args_len = posonlyargs.len() + args.len();
|
||||
// not optimal
|
||||
let mut defaults: Vec<_> = std::iter::repeat_with(|| None)
|
||||
.take(args_len - defaults.len())
|
||||
.chain(defaults.into_iter().map(Some))
|
||||
.collect();
|
||||
debug_assert_eq!(args_len, defaults.len());
|
||||
|
||||
for (arg, default) in std::iter::zip(args, defaults.drain(posonlyargs.len()..)) {
|
||||
let arg = ArgWithDefault::from_arg(arg, default);
|
||||
pos_args.push(arg);
|
||||
}
|
||||
|
||||
for (arg, default) in std::iter::zip(posonlyargs, defaults.drain(..)) {
|
||||
let arg = ArgWithDefault::from_arg(arg, default);
|
||||
pos_only.push(arg);
|
||||
}
|
||||
|
||||
let mut kw_only = Vec::with_capacity(kwonlyargs.len());
|
||||
let kw_defaults: Vec<_> = std::iter::repeat_with(|| None)
|
||||
.take(kw_only.len().saturating_sub(kw_defaults.len()))
|
||||
.chain(kw_defaults.into_iter().map(Some))
|
||||
.collect();
|
||||
for (arg, default) in std::iter::zip(kwonlyargs, kw_defaults) {
|
||||
let arg = ArgWithDefault::from_arg(arg, default);
|
||||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
Arguments {
|
||||
range,
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
vararg,
|
||||
kwonlyargs: kw_only,
|
||||
kwarg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> From<Arguments<R>> for PythonArguments<R> {
|
||||
fn from(arguments: Arguments<R>) -> Self {
|
||||
arguments.into_python_arguments()
|
||||
}
|
||||
}
|
||||
|
||||
include!("gen/generic.rs");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{Constant, Expr};
|
||||
|
||||
impl<R> Expr<R> {
|
||||
impl Expr {
|
||||
/// Returns a short name for the node suitable for use in error messages.
|
||||
pub fn python_name(&self) -> &'static str {
|
||||
match self {
|
||||
|
||||
@@ -11,7 +11,6 @@ edition = "2021"
|
||||
[features]
|
||||
default = ["malachite-bigint"]
|
||||
serde = ["dep:serde", "rustpython-parser-core/serde"]
|
||||
all-nodes-with-ranges = ["rustpython-ast/all-nodes-with-ranges"]
|
||||
full-lexer = []
|
||||
malachite-bigint = ["dep:malachite-bigint", "rustpython-ast/malachite-bigint"]
|
||||
num-bigint = ["dep:num-bigint", "rustpython-ast/num-bigint"]
|
||||
|
||||
@@ -66,7 +66,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_assign_list() {
|
||||
let source = "[x, y] = (1, 2, 3)";
|
||||
let parse_ast = ast::Suite::parse(source, "<test>").unwrap();
|
||||
@@ -102,7 +101,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_assign_list_comp() {
|
||||
let source = "x = [y for y in (1, 2, 3)]";
|
||||
let parse_ast = ast::Suite::parse(source, "<test>").unwrap();
|
||||
@@ -110,7 +108,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_assign_set_comp() {
|
||||
let source = "x = {y for y in (1, 2, 3)}";
|
||||
let parse_ast = ast::Suite::parse(source, "<test>").unwrap();
|
||||
@@ -118,7 +115,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_assign_with() {
|
||||
let source = "with 1 as x: pass";
|
||||
let parse_ast = ast::Suite::parse(source, "<test>").unwrap();
|
||||
|
||||
@@ -141,7 +141,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{ast, parser::ParseErrorType, Parse};
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
macro_rules! function_and_lambda {
|
||||
($($name:ident: $code:expr,)*) => {
|
||||
$(
|
||||
@@ -154,13 +153,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
function_and_lambda! {
|
||||
test_function_no_args_with_ranges: "def f(): pass",
|
||||
test_function_pos_args_with_ranges: "def f(a, b, c): pass",
|
||||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
function_and_lambda! {
|
||||
test_function_no_args: "def f(): pass",
|
||||
test_function_pos_args: "def f(a, b, c): pass",
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
//! [`Mode`]: crate::mode
|
||||
|
||||
use crate::{
|
||||
ast::{self, OptionalRange, Ranged},
|
||||
ast::{self, Ranged},
|
||||
lexer::{self, LexResult, LexicalError, LexicalErrorType},
|
||||
python,
|
||||
text_size::TextSize,
|
||||
@@ -23,7 +23,7 @@ use crate::{
|
||||
use itertools::Itertools;
|
||||
use std::iter;
|
||||
|
||||
use crate::{lexer::Lexer, soft_keywords::SoftKeywordTransformer, text_size::TextRange};
|
||||
use crate::{lexer::Lexer, soft_keywords::SoftKeywordTransformer};
|
||||
pub(super) use lalrpop_util::ParseError as LalrpopError;
|
||||
|
||||
/// Parse Python code string to implementor's type.
|
||||
@@ -551,11 +551,6 @@ impl ParseErrorType {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(super) fn optional_range(start: TextSize, end: TextSize) -> OptionalRange<TextRange> {
|
||||
OptionalRange::<TextRange>::new(start, end)
|
||||
}
|
||||
|
||||
include!("gen/parse.rs");
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -612,7 +607,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_lambda() {
|
||||
let source = "lambda x, y: x * y"; // lambda(x, y): x * y";
|
||||
let parse_ast = ast::Suite::parse(source, "<test>").unwrap();
|
||||
@@ -627,7 +621,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_class() {
|
||||
let source = "\
|
||||
class Foo(A, B):
|
||||
@@ -640,7 +633,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_dict_comprehension() {
|
||||
let source = "{x1: x2 for y in z}";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -648,7 +640,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_list_comprehension() {
|
||||
let source = "[x for y in z]";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -656,7 +647,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_double_list_comprehension() {
|
||||
let source = "[x for y, y2 in z for a in b if a < 5 if a > 10]";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -664,7 +654,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_generator_comprehension() {
|
||||
let source = "(x for y in z)";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -672,7 +661,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_named_expression_generator_comprehension() {
|
||||
let source = "(x := y + 1 for y in z)";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -680,7 +668,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_parse_if_else_generator_comprehension() {
|
||||
let source = "(x if y else y for y in z)";
|
||||
let parse_ast = ast::Expr::parse(source, "<test>").unwrap();
|
||||
@@ -709,7 +696,6 @@ class Foo(A, B):
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_with_statement() {
|
||||
let source = "\
|
||||
with 0: pass
|
||||
@@ -779,7 +765,6 @@ array[3:5, *indexes_to_select]
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_generator_expression_argument() {
|
||||
let source = r#"' '.join(
|
||||
sql
|
||||
@@ -839,7 +824,6 @@ except* OSError as e:
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_match_as_identifier() {
|
||||
let parse_ast = ast::Suite::parse(
|
||||
r#"
|
||||
@@ -872,7 +856,6 @@ print(match(12))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_patma() {
|
||||
let source = r#"# Cases sampled from Lib/test/test_patma.py
|
||||
|
||||
@@ -1044,7 +1027,6 @@ match w := x,:
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_match() {
|
||||
let parse_ast = ast::Suite::parse(
|
||||
r#"
|
||||
@@ -1075,7 +1057,6 @@ match x:
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn test_variadic_generics() {
|
||||
let parse_ast = ast::Suite::parse(
|
||||
r#"
|
||||
@@ -1105,7 +1086,6 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ...
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
fn decorator_ranges() {
|
||||
let parse_ast = ast::Suite::parse(
|
||||
r#"
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
context::set_context,
|
||||
string::parse_strings,
|
||||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
text_size::TextSize
|
||||
};
|
||||
|
||||
grammar;
|
||||
@@ -19,9 +19,9 @@ grammar;
|
||||
// For each public entry point, a full parse table is generated.
|
||||
// By having only a single pub function, we reduce this to one.
|
||||
pub Top: ast::Mod = {
|
||||
<start:@L> StartModule <body:Program> <end:@R> => ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into(),
|
||||
<start:@L> StartInteractive <body:Program> <end:@R> => ast::ModInteractive { body, range: optional_range(start, end) }.into(),
|
||||
<start:@L> StartExpression <body:TestList> ("\n")* <end:@R> => ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into()
|
||||
<start:@L> StartModule <body:Program> <end:@R> => ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into(),
|
||||
<start:@L> StartInteractive <body:Program> <end:@R> => ast::ModInteractive { body, range: (start..end).into() }.into(),
|
||||
<start:@L> StartExpression <body:TestList> ("\n")* <end:@R> => ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into()
|
||||
};
|
||||
|
||||
Program: ast::Suite = {
|
||||
@@ -393,7 +393,7 @@ MatchCase: ast::MatchCase = {
|
||||
pattern,
|
||||
guard: guard.map(Box::new),
|
||||
body,
|
||||
range: optional_range(start, end)
|
||||
range: (start..end).into()
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -952,15 +952,15 @@ WithItems: Vec<ast::WithItem> = {
|
||||
#[inline]
|
||||
WithItemsNoAs: Vec<ast::WithItem> = {
|
||||
<location:@L> <all:OneOrMore<Test<"all">>> <end_location:@R> => {
|
||||
all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
|
||||
all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }).collect()
|
||||
},
|
||||
}
|
||||
|
||||
WithItem<Goal>: ast::WithItem = {
|
||||
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) },
|
||||
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() },
|
||||
<location:@L> <context_expr:Test<"all">> "as" <vars:Expression<"all">> <end_location:@R> => {
|
||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||
ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() }
|
||||
},
|
||||
};
|
||||
|
||||
@@ -982,7 +982,7 @@ Parameters: ast::Arguments = {
|
||||
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter, DoubleStarTypedParameter>)?> ")" <end_location:@R> =>? {
|
||||
a.as_ref().map(validate_arguments).transpose()?;
|
||||
|
||||
let range = optional_range(location, end_location);
|
||||
let range = (location..end_location).into();
|
||||
let args = a
|
||||
.map(|mut arguments| {
|
||||
arguments.range = range;
|
||||
@@ -1010,7 +1010,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::Arguments = {
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
},
|
||||
<location:@L> <param1:ParameterDefs<ArgType>> <kw:("," <KwargParameter<DoubleStarArgType>>)> ","? <end_location:@R> =>? {
|
||||
@@ -1028,7 +1028,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::Arguments = {
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
},
|
||||
<location:@L> <params:ParameterListStarArgs<ArgType, StarArgType, DoubleStarArgType>> ","? <end_location:@R> => {
|
||||
@@ -1039,7 +1039,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::Arguments = {
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
},
|
||||
<location:@L> <kwarg:KwargParameter<DoubleStarArgType>> ","? <end_location:@R> => {
|
||||
@@ -1049,7 +1049,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::Arguments = {
|
||||
kwonlyargs: vec![],
|
||||
vararg: None,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1069,10 +1069,7 @@ ParameterDef<ArgType>: ast::ArgWithDefault = {
|
||||
<i:ArgType> => i,
|
||||
<mut i:ArgType> "=" <e:Test<"all">> <end_location:@R> => {
|
||||
i.default = Some(Box::new(e));
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
{
|
||||
i.range = optional_range(i.range.start(), end_location);
|
||||
}
|
||||
i.range = (i.range.start()..end_location).into();
|
||||
i
|
||||
},
|
||||
};
|
||||
@@ -1080,7 +1077,7 @@ ParameterDef<ArgType>: ast::ArgWithDefault = {
|
||||
UntypedParameter: ast::ArgWithDefault = {
|
||||
<location:@L> <arg:Identifier> <end_location:@R> => {
|
||||
let def = ast::Arg { arg, annotation: None, type_comment: None, range: (location..end_location).into() };
|
||||
ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) }
|
||||
ast::ArgWithDefault { def, default: None, range: (location..end_location).into() }
|
||||
},
|
||||
};
|
||||
StarUntypedParameter: ast::Arg = {
|
||||
@@ -1091,7 +1088,7 @@ TypedParameter: ast::ArgWithDefault = {
|
||||
<location:@L> <arg:Identifier> <a:(":" <Test<"all">>)?> <end_location:@R> => {
|
||||
let annotation = a.map(Box::new);
|
||||
let def = ast::Arg { arg, annotation, type_comment: None, range: (location..end_location).into() };
|
||||
ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) }
|
||||
ast::ArgWithDefault { def, default: None, range: (location..end_location).into() }
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1157,7 +1154,7 @@ ClassDef: ast::Stmt = {
|
||||
// Decorators:
|
||||
Decorator: ast::Decorator = {
|
||||
<location:@L> "@" <p:NamedExpressionTest> <end_location:@R> "\n" => {
|
||||
ast::Decorator { range: optional_range(location, end_location), expression: p }
|
||||
ast::Decorator { range: (location..end_location).into(), expression: p }
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1206,7 +1203,7 @@ LambdaDef: ast::Expr = {
|
||||
<location:@L> "lambda" <p:ParameterList<UntypedParameter, StarUntypedParameter, StarUntypedParameter>?> ":" <body:Test<"all">> <end_location:@R> =>? {
|
||||
p.as_ref().map(validate_arguments).transpose()?;
|
||||
let p = p
|
||||
.unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location)));
|
||||
.unwrap_or_else(|| ast::Arguments::empty((location..end_location).into()));
|
||||
|
||||
Ok(ast::Expr::Lambda(
|
||||
ast::ExprLambda {
|
||||
@@ -1570,7 +1567,7 @@ SingleForComprehension: ast::Comprehension = {
|
||||
iter,
|
||||
ifs,
|
||||
is_async,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
64
parser/src/python.rs
generated
64
parser/src/python.rs
generated
@@ -1,5 +1,5 @@
|
||||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: 4caf54d50e2859da942dd4db1d0d538083a10c1a232b8619e44f266f1ae25384
|
||||
// sha3: 0fa2bdb02350fa071c24cfc111835a73b754cc5d1f240b2105cea9d59431bf4e
|
||||
use crate::{
|
||||
ast::{self as ast, Ranged, bigint::BigInt},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
context::set_context,
|
||||
string::parse_strings,
|
||||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
text_size::TextSize
|
||||
};
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
@@ -27,7 +27,7 @@ mod __parse__Top {
|
||||
context::set_context,
|
||||
string::parse_strings,
|
||||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
text_size::TextSize
|
||||
};
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
@@ -28748,7 +28748,7 @@ fn __action1<
|
||||
(_, end, _): (TextSize, TextSize, TextSize),
|
||||
) -> ast::Mod
|
||||
{
|
||||
ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into()
|
||||
ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -28760,7 +28760,7 @@ fn __action2<
|
||||
(_, end, _): (TextSize, TextSize, TextSize),
|
||||
) -> ast::Mod
|
||||
{
|
||||
ast::ModInteractive { body, range: optional_range(start, end) }.into()
|
||||
ast::ModInteractive { body, range: (start..end).into() }.into()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -28773,7 +28773,7 @@ fn __action3<
|
||||
(_, end, _): (TextSize, TextSize, TextSize),
|
||||
) -> ast::Mod
|
||||
{
|
||||
ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into()
|
||||
ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -29788,7 +29788,7 @@ fn __action82<
|
||||
pattern,
|
||||
guard: guard.map(Box::new),
|
||||
body,
|
||||
range: optional_range(start, end)
|
||||
range: (start..end).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31071,7 +31071,7 @@ fn __action156<
|
||||
) -> Vec<ast::WithItem>
|
||||
{
|
||||
{
|
||||
all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
|
||||
all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31115,7 +31115,7 @@ fn __action158<
|
||||
{
|
||||
a.as_ref().map(validate_arguments).transpose()?;
|
||||
|
||||
let range = optional_range(location, end_location);
|
||||
let range = (location..end_location).into();
|
||||
let args = a
|
||||
.map(|mut arguments| {
|
||||
arguments.range = range;
|
||||
@@ -31137,7 +31137,7 @@ fn __action159<
|
||||
{
|
||||
{
|
||||
let def = ast::Arg { arg, annotation: None, type_comment: None, range: (location..end_location).into() };
|
||||
ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) }
|
||||
ast::ArgWithDefault { def, default: None, range: (location..end_location).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31164,7 +31164,7 @@ fn __action161<
|
||||
{
|
||||
let annotation = a.map(Box::new);
|
||||
let def = ast::Arg { arg, annotation, type_comment: None, range: (location..end_location).into() };
|
||||
ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) }
|
||||
ast::ArgWithDefault { def, default: None, range: (location..end_location).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31240,7 +31240,7 @@ fn __action165<
|
||||
) -> ast::Decorator
|
||||
{
|
||||
{
|
||||
ast::Decorator { range: optional_range(location, end_location), expression: p }
|
||||
ast::Decorator { range: (location..end_location).into(), expression: p }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31328,7 +31328,7 @@ fn __action171<
|
||||
{
|
||||
p.as_ref().map(validate_arguments).transpose()?;
|
||||
let p = p
|
||||
.unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location)));
|
||||
.unwrap_or_else(|| ast::Arguments::empty((location..end_location).into()));
|
||||
|
||||
Ok(ast::Expr::Lambda(
|
||||
ast::ExprLambda {
|
||||
@@ -31775,7 +31775,7 @@ fn __action213<
|
||||
iter,
|
||||
ifs,
|
||||
is_async,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32232,7 +32232,7 @@ fn __action250<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -32262,7 +32262,7 @@ fn __action251<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -32284,7 +32284,7 @@ fn __action252<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32305,7 +32305,7 @@ fn __action253<
|
||||
kwonlyargs: vec![],
|
||||
vararg: None,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32449,7 +32449,7 @@ fn __action266<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -32479,7 +32479,7 @@ fn __action267<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -32501,7 +32501,7 @@ fn __action268<
|
||||
kwonlyargs,
|
||||
vararg,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32522,7 +32522,7 @@ fn __action269<
|
||||
kwonlyargs: vec![],
|
||||
vararg: None,
|
||||
kwarg,
|
||||
range: optional_range(location, end_location)
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32625,7 +32625,7 @@ fn __action279<
|
||||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> ast::WithItem
|
||||
{
|
||||
ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -32640,7 +32640,7 @@ fn __action280<
|
||||
{
|
||||
{
|
||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||
ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32681,7 +32681,7 @@ fn __action284<
|
||||
(_, end_location, _): (TextSize, TextSize, TextSize),
|
||||
) -> ast::WithItem
|
||||
{
|
||||
ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -32696,7 +32696,7 @@ fn __action285<
|
||||
{
|
||||
{
|
||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||
ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32712,7 +32712,7 @@ fn __action286<
|
||||
{
|
||||
{
|
||||
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
|
||||
ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) }
|
||||
ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34376,10 +34376,7 @@ fn __action443<
|
||||
{
|
||||
{
|
||||
i.default = Some(Box::new(e));
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
{
|
||||
i.range = optional_range(i.range.start(), end_location);
|
||||
}
|
||||
i.range = (i.range.start()..end_location).into();
|
||||
i
|
||||
}
|
||||
}
|
||||
@@ -34494,10 +34491,7 @@ fn __action454<
|
||||
{
|
||||
{
|
||||
i.default = Some(Box::new(e));
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
{
|
||||
i.range = optional_range(i.range.start(), end_location);
|
||||
}
|
||||
i.range = (i.range.start()..end_location).into();
|
||||
i
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user