From 2dfd053bed1e339a4d0c6477b11f850b62e398e3 Mon Sep 17 00:00:00 2001 From: harupy Date: Thu, 5 Jan 2023 22:48:47 +0900 Subject: [PATCH] Implement Default for Location --- core/src/location.rs | 8 +++++++- parser/src/lexer.rs | 2 +- parser/src/string_parser.rs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/location.rs b/core/src/location.rs index 021dc2f..9d32b54 100644 --- a/core/src/location.rs +++ b/core/src/location.rs @@ -1,12 +1,18 @@ use serde::{Deserialize, Serialize}; /// 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(super) row: u32, pub(super) column: u32, } +impl Default for Location { + fn default() -> Self { + Self { row: 1, column: 0 } + } +} + impl Location { pub fn fmt_with( &self, diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 8251794..ec4cfbe 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -153,7 +153,7 @@ pub type LexResult = Result; #[inline] pub fn make_tokenizer(source: &str) -> impl Iterator + '_ { - make_tokenizer_located(source, Location::new(1, 0)) + make_tokenizer_located(source, Location::default()) } pub fn make_tokenizer_located( diff --git a/parser/src/string_parser.rs b/parser/src/string_parser.rs index 1d95cff..c18ba0f 100644 --- a/parser/src/string_parser.rs +++ b/parser/src/string_parser.rs @@ -541,8 +541,8 @@ mod tests { source, StringKind::FString, false, - Location::new(1, 0), - Location::new(1, source.len() + 3), // 3 for prefix and quotes + Location::default(), + Location::default().with_col_offset(source.len() + 3), // 3 for prefix and quotes ) .parse() }