Skip to content

Commit

Permalink
refactor(parser): refactor number parsing to support generic number t…
Browse files Browse the repository at this point in the history
…ypes
  • Loading branch information
zkat committed Dec 1, 2024
1 parent 0940bb1 commit fb7c92b
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 87 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ span = []

[dependencies]
miette = "7.2.0"
num = "0.4.2"
thiserror = "1.0.40"
winnow = { version = "0.6.20", features = ["alloc", "unstable-recover"] }

Expand Down
7 changes: 6 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct KdlDiagnostic {
pub kind: KdlErrorKind,
}

/// A type reprenting additional information specific to the type of error being returned.
/// A type representing additional information specific to the type of error being returned.
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
pub enum KdlErrorKind {
/// An error occurred while parsing an integer.
Expand All @@ -91,6 +91,11 @@ pub enum KdlErrorKind {
#[diagnostic(code(kdl::parse_float))]
ParseFloatError(ParseFloatError),

/// Tried to parse a negative number as an unsigned integer.
#[error("Tried to parse a negative number as an unsigned integer.")]
#[diagnostic(code(kdl::negative_unsigned))]
NegativeUnsignedError,

/// Generic parsing error. The given context string denotes the component
/// that failed to parse.
#[error("Expected {0}.")]
Expand Down
Loading

0 comments on commit fb7c92b

Please sign in to comment.