diff options
Diffstat (limited to 'vendor/pest/src/error.rs')
-rw-r--r-- | vendor/pest/src/error.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/vendor/pest/src/error.rs b/vendor/pest/src/error.rs index eef004233..df3f5448e 100644 --- a/vendor/pest/src/error.rs +++ b/vendor/pest/src/error.rs @@ -74,6 +74,19 @@ pub enum LineColLocation { Span((usize, usize), (usize, usize)), } +impl From<Position<'_>> for LineColLocation { + fn from(value: Position<'_>) -> Self { + Self::Pos(value.line_col()) + } +} + +impl From<Span<'_>> for LineColLocation { + fn from(value: Span<'_>) -> Self { + let (start, end) = value.split(); + Self::Span(start.line_col(), end.line_col()) + } +} + impl<R: RuleType> Error<R> { /// Creates `Error` from `ErrorVariant` and `Position`. /// @@ -418,7 +431,7 @@ impl<R: RuleType> Error<R> { .unwrap_or_default(); let pair = (self.line_col.clone(), &self.continued_line); - if let (LineColLocation::Span(_, end), &Some(ref continued_line)) = pair { + if let (LineColLocation::Span(_, end), Some(ref continued_line)) = pair { let has_line_gap = end.0 - self.start().0 > 1; if has_line_gap { format!( @@ -892,4 +905,26 @@ mod tests { .join("\n") ); } + + #[test] + fn pos_to_lcl_conversion() { + let input = "input"; + + let pos = Position::new(input, 2).unwrap(); + + assert_eq!(LineColLocation::Pos(pos.line_col()), pos.into()); + } + + #[test] + fn span_to_lcl_conversion() { + let input = "input"; + + let span = Span::new(input, 2, 4).unwrap(); + let (start, end) = span.split(); + + assert_eq!( + LineColLocation::Span(start.line_col(), end.line_col()), + span.into() + ); + } } |