mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-17 01:55:22 +00:00
integrate ast::Location into compilre-core::Location
This commit is contained in:
parent
bfac0355dc
commit
904fc477f1
8 changed files with 21 additions and 83 deletions
|
@ -3,7 +3,7 @@
|
|||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
|
||||
pub use crate::constant::*;
|
||||
pub use crate::location::Location;
|
||||
pub use crate::Location;
|
||||
|
||||
type Ident = String;
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@ mod constant;
|
|||
#[cfg(feature = "fold")]
|
||||
mod fold_helpers;
|
||||
mod impls;
|
||||
mod location;
|
||||
#[cfg(feature = "unparse")]
|
||||
mod unparse;
|
||||
|
||||
pub use ast_gen::*;
|
||||
pub use location::Location;
|
||||
pub use rustpython_compiler_core::Location;
|
||||
|
||||
pub type Suite<U = ()> = Vec<Stmt<U>>;
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
//! Datatypes to support source location information.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// A location somewhere in the sourcecode.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Location(rustpython_compiler_core::Location);
|
||||
|
||||
impl std::ops::Deref for Location {
|
||||
type Target = rustpython_compiler_core::Location;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for Location {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Location {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "line {} column {}", self.row(), self.column())
|
||||
}
|
||||
}
|
||||
|
||||
impl Location {
|
||||
pub fn visualize<'a>(
|
||||
&self,
|
||||
line: &'a str,
|
||||
desc: impl fmt::Display + 'a,
|
||||
) -> impl fmt::Display + 'a {
|
||||
struct Visualize<'a, D: fmt::Display> {
|
||||
loc: Location,
|
||||
line: &'a str,
|
||||
desc: D,
|
||||
}
|
||||
impl<D: fmt::Display> fmt::Display for Visualize<'_, D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}\n{}{arrow:>pad$}",
|
||||
self.desc,
|
||||
self.line,
|
||||
pad = self.loc.column(),
|
||||
arrow = "^",
|
||||
)
|
||||
}
|
||||
}
|
||||
Visualize {
|
||||
loc: *self,
|
||||
line,
|
||||
desc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Location {
|
||||
pub fn new(row: usize, column: usize) -> Self {
|
||||
Location(rustpython_compiler_core::Location::new(row, column))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue