Skip to content

Commit 904fc47

Browse files
committed
integrate ast::Location into compilre-core::Location
1 parent bfac035 commit 904fc47

8 files changed

Lines changed: 21 additions & 83 deletions

File tree

‎ast/asdl_rs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def write_ast_def(mod, typeinfo, f):
645645
#![allow(clippy::derive_partial_eq_without_eq)]
646646
647647
pub use crate::constant::*;
648-
pub use crate::location::Location;
648+
pub use crate::Location;
649649
650650
type Ident = String;
651651
\n

‎ast/src/ast_gen.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::derive_partial_eq_without_eq)]
44

55
pub use crate::constant::*;
6-
pub use crate::location::Location;
6+
pub use crate::Location;
77

88
type Ident = String;
99

‎ast/src/lib.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ mod constant;
33
#[cfg(feature = "fold")]
44
mod fold_helpers;
55
mod impls;
6-
mod location;
76
#[cfg(feature = "unparse")]
87
mod unparse;
98

109
pub use ast_gen::*;
11-
pub use location::Location;
10+
pub use rustpython_compiler_core::Location;
1211

1312
pub type Suite<U = ()> = Vec<Stmt<U>>;

‎ast/src/location.rs‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎core/src/location.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ pub struct Location {
77
pub(super) column: u32,
88
}
99

10+
impl Location {
11+
pub fn fmt_with(
12+
&self,
13+
f: &mut std::fmt::Formatter,
14+
e: &impl std::fmt::Display,
15+
) -> std::fmt::Result {
16+
write!(f, "{} at line {} column {}", e, self.row(), self.column())
17+
}
18+
}
19+
1020
impl Location {
1121
/// Creates a new Location object at the given row and column.
1222
///

‎parser/src/error.rs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Define internal parse error types
22
//! The goal is to provide a matching and a safe error API, maksing errors from LALR
3-
use lalrpop_util::ParseError as LalrpopError;
4-
5-
use crate::ast::Location;
6-
use crate::token::Tok;
73
8-
use std::error::Error;
9-
use std::fmt;
4+
use crate::{ast::Location, token::Tok};
5+
use lalrpop_util::ParseError as LalrpopError;
6+
use std::{error::Error, fmt};
107

118
/// Represents an error during lexical scanning.
129
#[derive(Debug, PartialEq)]
@@ -186,7 +183,7 @@ impl ParseError {
186183

187184
impl fmt::Display for ParseError {
188185
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189-
write!(f, "{} at {}", self.error, self.location)
186+
self.location.fmt_with(f, &self.error)
190187
}
191188
}
192189

‎parser/src/function.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use ahash::RandomState;
2-
use std::collections::HashSet;
3-
41
use crate::ast;
52
use crate::error::{LexicalError, LexicalErrorType};
3+
use ahash::RandomState;
4+
use std::collections::HashSet;
65

76
pub struct ArgumentList {
87
pub args: Vec<ast::Expr>,

‎parser/src/parser.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
//! parse a whole program, a single statement, or a single
66
//! expression.
77
8-
use std::iter;
9-
10-
use crate::ast;
11-
use crate::error::ParseError;
12-
use crate::lexer;
138
pub use crate::mode::Mode;
14-
use crate::python;
9+
use crate::{ast, error::ParseError, lexer, python};
10+
use std::iter;
1511

1612
/*
1713
* Parse python code.

0 commit comments

Comments
 (0)