mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-01 08:07:50 +00:00
Move range
from Attributed
to Node
s (#22)
* Move `range` from `Attributed` to `Node`s * No Attributed + custom for Range PoC * Generate all located variants, generate enum implementations * Implement `Copy` on simple enums * Move `Suite` to `ranged` and `located` * Update tests --------- Co-authored-by: Jeong YunWon <jeong@youknowone.org>
This commit is contained in:
parent
a983f4383f
commit
192379cede
126 changed files with 29410 additions and 30670 deletions
|
@ -1,39 +1,15 @@
|
|||
use crate::builtin::Attributed;
|
||||
use rustpython_parser_core::source_code::{SourceLocation, SourceLocator, SourceRange};
|
||||
use rustpython_parser_core::{
|
||||
source_code::{SourceLocator, SourceRange},
|
||||
text_size::TextRange,
|
||||
};
|
||||
|
||||
impl crate::fold::Fold<()> for SourceLocator<'_> {
|
||||
impl crate::fold::Fold<TextRange> for SourceLocator<'_> {
|
||||
type TargetU = SourceRange;
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
#[cold]
|
||||
fn map_user(&mut self, _user: ()) -> Result<Self::TargetU, Self::Error> {
|
||||
unreachable!("implemented map_attributed");
|
||||
}
|
||||
|
||||
fn map_attributed<T>(
|
||||
&mut self,
|
||||
node: Attributed<T, ()>,
|
||||
) -> Result<Attributed<T, Self::TargetU>, Self::Error> {
|
||||
let start = self.locate(node.range.start());
|
||||
let end = self.locate(node.range.end());
|
||||
Ok(Attributed {
|
||||
range: node.range,
|
||||
custom: (start..end).into(),
|
||||
node: node.node,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Attributed<T, SourceRange> {
|
||||
/// Returns the absolute start position of the node from the beginning of the document.
|
||||
#[inline]
|
||||
pub const fn location(&self) -> SourceLocation {
|
||||
self.custom.start
|
||||
}
|
||||
|
||||
/// Returns the absolute position at which the node ends in the source document.
|
||||
#[inline]
|
||||
pub const fn end_location(&self) -> Option<SourceLocation> {
|
||||
self.custom.end
|
||||
fn map_user(&mut self, user: TextRange) -> Result<Self::TargetU, Self::Error> {
|
||||
let start = self.locate(user.start());
|
||||
let end = self.locate(user.end());
|
||||
Ok((start..end).into())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue