mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-01 08:07:50 +00:00
More flexible map_user and fold for new constructor nodes (#53)
* make fold.rs file * Split user_map steps * Fold for new constructor nodes
This commit is contained in:
parent
205ee80033
commit
b48834fe2d
6 changed files with 2516 additions and 833 deletions
|
@ -1,14 +1,22 @@
|
|||
use rustpython_parser_core::{
|
||||
source_code::{SourceLocator, SourceRange},
|
||||
source_code::{SourceLocation, SourceLocator, SourceRange},
|
||||
text_size::TextRange,
|
||||
};
|
||||
|
||||
impl crate::fold::Fold<TextRange> for SourceLocator<'_> {
|
||||
type TargetU = SourceRange;
|
||||
type Error = std::convert::Infallible;
|
||||
type UserContext = SourceLocation;
|
||||
|
||||
fn map_user(&mut self, user: TextRange) -> Result<Self::TargetU, Self::Error> {
|
||||
let start = self.locate(user.start());
|
||||
fn will_map_user(&mut self, user: &TextRange) -> Self::UserContext {
|
||||
self.locate(user.start())
|
||||
}
|
||||
|
||||
fn map_user(
|
||||
&mut self,
|
||||
user: TextRange,
|
||||
start: Self::UserContext,
|
||||
) -> Result<Self::TargetU, Self::Error> {
|
||||
let end = self.locate(user.end());
|
||||
Ok((start..end).into())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue