Adapt SourceLocation

This commit is contained in:
Jeong YunWon 2023-05-09 18:30:35 +09:00
parent a14e43e03a
commit 09a6afdd04
117 changed files with 1606 additions and 1676 deletions

View file

@ -2,12 +2,21 @@ mod attributed;
mod constant;
#[cfg(feature = "fold")]
mod fold_helpers;
mod generic;
mod generic {
#![allow(clippy::derive_partial_eq_without_eq)]
include!("gen/generic.rs");
}
mod impls;
#[cfg(feature = "location")]
pub mod located;
pub mod located {
include!("gen/located.rs");
}
#[cfg(feature = "location")]
mod locator;
#[cfg(feature = "location")]
pub use crate::locator::locate;
#[cfg(feature = "location")]
pub use rustpython_compiler_core::SourceLocator;
#[cfg(feature = "unparse")]
mod unparse;
@ -15,7 +24,36 @@ mod unparse;
pub use attributed::Attributed;
pub use constant::{Constant, ConversionFlag};
pub use generic::*;
#[cfg(feature = "location")]
pub use locator::Locator;
pub type Suite<U = ()> = Vec<Stmt<U>>;
pub mod location {
pub use rustpython_compiler_core::source_code::{OneIndexed, SourceLocation};
#[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),
}
}
}
}