mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-23 04:55:25 +00:00
Implement Default for Location
This commit is contained in:
parent
7f552e4594
commit
2dfd053bed
3 changed files with 10 additions and 4 deletions
|
@ -1,12 +1,18 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Sourcecode location.
|
/// Sourcecode location.
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
pub struct Location {
|
pub struct Location {
|
||||||
pub(super) row: u32,
|
pub(super) row: u32,
|
||||||
pub(super) column: u32,
|
pub(super) column: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Location {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { row: 1, column: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Location {
|
impl Location {
|
||||||
pub fn fmt_with(
|
pub fn fmt_with(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub type LexResult = Result<Spanned, LexicalError>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ {
|
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ {
|
||||||
make_tokenizer_located(source, Location::new(1, 0))
|
make_tokenizer_located(source, Location::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_tokenizer_located(
|
pub fn make_tokenizer_located(
|
||||||
|
|
|
@ -541,8 +541,8 @@ mod tests {
|
||||||
source,
|
source,
|
||||||
StringKind::FString,
|
StringKind::FString,
|
||||||
false,
|
false,
|
||||||
Location::new(1, 0),
|
Location::default(),
|
||||||
Location::new(1, source.len() + 3), // 3 for prefix and quotes
|
Location::default().with_col_offset(source.len() + 3), // 3 for prefix and quotes
|
||||||
)
|
)
|
||||||
.parse()
|
.parse()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue