Skip to main content

oxilean_parse/error_impl/
parseerrorkind_traits.rs

1//! # ParseErrorKind - Trait Implementations
2//!
3//! This module contains trait implementations for `ParseErrorKind`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::ParseErrorKind;
12use std::fmt;
13
14impl fmt::Display for ParseErrorKind {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            ParseErrorKind::UnexpectedToken { expected, got } => {
18                write!(f, "expected ")?;
19                if expected.is_empty() {
20                    write!(f, "something")?;
21                } else if expected.len() == 1 {
22                    write!(f, "{}", expected[0])?;
23                } else {
24                    write!(f, "one of: {}", expected.join(", "))?;
25                }
26                write!(f, ", but got {}", got)
27            }
28            ParseErrorKind::UnexpectedEof { expected } => {
29                write!(f, "unexpected end of file, expected ")?;
30                if expected.is_empty() {
31                    write!(f, "more input")
32                } else if expected.len() == 1 {
33                    write!(f, "{}", expected[0])
34                } else {
35                    write!(f, "one of: {}", expected.join(", "))
36                }
37            }
38            ParseErrorKind::InvalidSyntax(msg) => write!(f, "invalid syntax: {}", msg),
39            ParseErrorKind::DuplicateDeclaration(name) => {
40                write!(f, "duplicate declaration: {}", name)
41            }
42            ParseErrorKind::InvalidBinder(msg) => write!(f, "invalid binder: {}", msg),
43            ParseErrorKind::InvalidPattern(msg) => write!(f, "invalid pattern: {}", msg),
44            ParseErrorKind::InvalidUniverse(msg) => {
45                write!(f, "invalid universe: {}", msg)
46            }
47            ParseErrorKind::Other(msg) => write!(f, "{}", msg),
48        }
49    }
50}