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:
Jeong, YunWon 2023-05-18 00:16:04 +09:00 committed by GitHub
parent 205ee80033
commit b48834fe2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 2516 additions and 833 deletions

View file

@ -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())
}