Skip to content

Commit

Permalink
Update DebugText with non-parenthesized range
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Feb 12, 2024
1 parent 4946a18 commit 02c55a0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/ruff_python_codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ class Foo:
assert_round_trip!(r#"f"{ chr(65) = !s}""#);
assert_round_trip!(r#"f"{ chr(65) = !r}""#);
assert_round_trip!(r#"f"{ chr(65) = :#x}""#);
assert_round_trip!(r#"f"{ ( chr(65) ) = }""#);
assert_round_trip!(r#"f"{a=!r:0.05f}""#);
}

Expand Down
1 change: 1 addition & 0 deletions crates/ruff_python_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ f"""{
y
z
}"""
f"{ ( foo ) = }"
"#
.trim(),
)
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1656,8 +1656,8 @@ FStringReplacementField: ast::FStringElement = {
)
};
ast::DebugText {
leading: source_code[TextRange::new(start_offset, value.start())].to_string(),
trailing: source_code[TextRange::new(value.end(), end_offset)].to_string(),
leading: source_code[TextRange::new(start_offset, value.expr.start())].to_string(),
trailing: source_code[TextRange::new(value.expr.end(), end_offset)].to_string(),
}
});
Ok(
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_python_parser/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.20.0"
// sha3: d38cc0f2252a58db42d3bd63a102b537865992b3cf51d402cdb4828f48989c9d
// sha3: 8c85e4bbac54760ed8be03b56a428d76e14d18e6dbde62b424d0b2b5e8e65dbe
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use ruff_python_ast::{self as ast, Int, IpyEscapeKind};
use crate::{
Expand Down Expand Up @@ -36457,8 +36457,8 @@ fn __action221<
)
};
ast::DebugText {
leading: source_code[TextRange::new(start_offset, value.start())].to_string(),
trailing: source_code[TextRange::new(value.end(), end_offset)].to_string(),
leading: source_code[TextRange::new(start_offset, value.expr.start())].to_string(),
trailing: source_code[TextRange::new(value.expr.end(), end_offset)].to_string(),
}
});
Ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,4 +942,45 @@ expression: parse_ast
),
},
),
Expr(
StmtExpr {
range: 374..392,
value: FString(
ExprFString {
range: 374..392,
value: FStringValue {
inner: Single(
FString(
FString {
range: 374..392,
elements: [
Expression(
FStringExpressionElement {
range: 376..391,
expression: Name(
ExprName {
range: 381..384,
id: "foo",
ctx: Load,
},
),
debug_text: Some(
DebugText {
leading: " ( ",
trailing: " ) = ",
},
),
conversion: None,
format_spec: None,
},
),
],
},
),
),
},
},
),
},
),
]

0 comments on commit 02c55a0

Please sign in to comment.